Skip to content

Commit

Permalink
Merge pull request #1032 from primer/cb/ts-avatar-stack
Browse files Browse the repository at this point in the history
Migrate AvatarStack to TypeScript
  • Loading branch information
colebemis authored Feb 9, 2021
2 parents 6071295 + 16aeca6 commit d757a81
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-cars-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Migrate `AvatarStack` to TypeScript
24 changes: 18 additions & 6 deletions src/AvatarStack.js → src/AvatarStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import React from 'react'
import classnames from 'classnames'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import sx from './sx'
import {get, COMMON} from './constants'
import sx, {SxProp} from './sx'
import {get, COMMON, SystemCommonProps} from './constants'
import theme from './theme'
import {Absolute} from './Position'
import {ComponentProps} from './utils/types'

const AvatarStackWrapper = styled.span`
type StyledAvatarStackWrapperProps = {
count?: number
} & SystemCommonProps &
SxProp

const AvatarStackWrapper = styled.span<StyledAvatarStackWrapperProps>`
display: flex;
position: relative;
height: 20px;
Expand Down Expand Up @@ -124,17 +130,22 @@ const AvatarStackWrapper = styled.span`
${COMMON}
${sx};
`
const transformChildren = children => {
const transformChildren = (children: React.ReactNode) => {
return React.Children.map(children, (child, index) => {
if (!React.isValidElement(child)) return child
return React.cloneElement(child, {
className: classnames(child.props.className, 'pc-AvatarItem'),
sx: {zIndex: 10 - index, ...child.props.sx}
})
})
}

const AvatarStack = ({children = [], alignRight, ...rest}) => {
const count = children.length
export type AvatarStackProps = {
alignRight?: boolean
} & ComponentProps<typeof AvatarStackWrapper>

const AvatarStack = ({children, alignRight, ...rest}: AvatarStackProps) => {
const count = React.Children.count(children)
const wrapperClassNames = classnames({
'pc-AvatarStack--two': count === 2,
'pc-AvatarStack--three-plus': count > 2,
Expand All @@ -158,4 +169,5 @@ AvatarStack.propTypes = {
alignRight: PropTypes.bool,
...sx.propTypes
}

export default AvatarStack
File renamed without changes.

1 comment on commit d757a81

@vercel
Copy link

@vercel vercel bot commented on d757a81 Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.