Skip to content

Commit

Permalink
chore(AvatarPair): Convert AvatarPair to CSS modules (#5002)
Browse files Browse the repository at this point in the history
* Convert to CSS module

* Create twenty-spoons-give.md

* test(vrt): update snapshots

* test(vrt): update snapshots

---------

Co-authored-by: jonrohan <[email protected]>
  • Loading branch information
jonrohan and jonrohan authored Sep 23, 2024
1 parent 597d285 commit 9bd5c89
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-spoons-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

chore(AvatarPair): Convert AvatarPair to CSS modules
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions packages/react/src/AvatarPair/AvatarPair.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.AvatarPair {
position: relative;
display: inline-flex;

[data-component='Avatar']:last-child,
[data-component='SkeletonAvatar']:last-child {
position: absolute;
right: -15%;
bottom: -9%;
box-shadow: var(--avatar-shadow);
}

[data-component='SkeletonAvatar']:last-child {
box-shadow: inset var(--avatar-shadow);
}
}

.AvatarChild {
background-color: var(--bgColor-default);
}
37 changes: 11 additions & 26 deletions packages/react/src/AvatarPair/AvatarPair.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import React from 'react'
import styled from 'styled-components'
import React, {type HTMLProps} from 'react'
import type {AvatarProps} from '../Avatar'
import Avatar from '../Avatar'
import {get} from '../constants'
import Box, {type BoxProps} from '../Box'
import {SkeletonAvatar} from '../experimental/Skeleton/SkeletonAvatar'
import classes from './AvatarPair.module.css'
import {clsx} from 'clsx'

const StyledAvatarPair = styled(Box)`
position: relative;
display: inline-flex;
export type AvatarPairProps = HTMLProps<HTMLDivElement>

[data-component='Avatar']:last-child,
[data-component='SkeletonAvatar']:last-child {
position: absolute;
right: -15%;
bottom: -9%;
box-shadow: ${get('shadows.avatar.childShadow')};
}
[data-component='SkeletonAvatar']:last-child {
box-shadow: inset ${get('shadows.avatar.childShadow')};
}
`

export type AvatarPairProps = BoxProps

const AvatarPair = ({children, ...rest}: AvatarPairProps) => {
const AvatarPair = ({children, className, ...rest}: AvatarPairProps) => {
const avatars = React.Children.map(children, (child, i) => {
if (!React.isValidElement(child)) {
return child
Expand All @@ -39,13 +21,16 @@ const AvatarPair = ({children, ...rest}: AvatarPairProps) => {
return <SkeletonAvatar {...child.props} size={20} />
}

return <Avatar bg="canvas.default" {...child.props} size={20} />
return <Avatar className={clsx(child.props.className, classes.AvatarChild)} {...child.props} size={20} />
})

return <StyledAvatarPair {...rest}>{avatars}</StyledAvatarPair>
return (
<div className={clsx(className, classes.AvatarPair)} {...rest}>
{avatars}
</div>
)
}

// styled() changes this
AvatarPair.displayName = 'AvatarPair'

export default AvatarPair

0 comments on commit 9bd5c89

Please sign in to comment.