Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Migrate AvatarStack to TypeScript #1032

Merged
merged 2 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.