Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Migrate CircleBadge to TypeScript #1035

Merged
merged 2 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 29 additions & 19 deletions src/CircleBadge.js → src/CircleBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {COMMON, get} from './constants'
import isNumeric from './utils/isNumeric'
import theme from './theme'
import sx from './sx'
import {COMMON, get, SystemCommonProps} from './constants'
import StyledOcticon from './StyledOcticon'
import sx, {SxProp} from './sx'
import theme from './theme'
import isNumeric from './utils/isNumeric'
import {ComponentProps} from './utils/types'

const variantSizes = {
small: 56,
medium: 96,
large: 128
}

const sizeStyles = ({size, variant}) => {
type StyledCircleBadgeProps = {
inline?: boolean
variant?: keyof typeof variantSizes
size?: number
} & SystemCommonProps &
SxProp

const sizeStyles = ({size, variant = 'medium'}: StyledCircleBadgeProps) => {
const calc = isNumeric(size) ? size : variantSizes[variant]
return {
width: calc,
height: calc
}
}

const CircleBadge = styled.div`
const CircleBadge = styled.div<StyledCircleBadgeProps>`
display: ${props => (props.inline ? 'inline-flex' : 'flex')};
align-items: center;
justify-content: center;
background-color: ${get('colors.white')};
border-radius: 50%;
box-shadow: ${get('shadows.medium')};
${COMMON} ${sizeStyles};
${COMMON};
${sizeStyles};
${sx};
`

CircleBadge.Icon = props => (
<StyledOcticon {...props} sx={Object.assign(props.sx, {height: 'auto', maxWidth: '60%', maxHeight: '55%'})} />
)
const CircleBadgeIcon = styled(StyledOcticon)`
height: auto;
max-width: 60%;
max-height: 55%;
`

CircleBadge.defaultProps = {
inline: false,
theme,
variant: 'medium'
theme
}

CircleBadge.propTypes = {
Expand All @@ -51,15 +60,16 @@ CircleBadge.propTypes = {
...sx.propTypes
}

CircleBadge.Icon.defaultProps = {
theme,
sx: {}
CircleBadgeIcon.defaultProps = {
theme
}

CircleBadge.Icon.propTypes = {
CircleBadgeIcon.propTypes = {
...StyledOcticon.propTypes
}

CircleBadge.Icon.displayName = 'CircleBadge.Icon'
CircleBadgeIcon.displayName = 'CircleBadge.Icon'

export default CircleBadge
export type CircleBadgeProps = ComponentProps<typeof CircleBadge>
export type CircleBadgeIconProps = ComponentProps<typeof CircleBadgeIcon>
export default Object.assign(CircleBadge, {Icon: CircleBadgeIcon})
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ describe('CircleBadge', () => {
})

describe('CircleBadge.Icon', () => {
behavesAsComponent(CircleBadge.Icon, [COMMON], () => (
<CircleBadge.Icon icon={CheckIcon}>
<div />
</CircleBadge.Icon>
))
behavesAsComponent(CircleBadge.Icon, [COMMON], () => <CircleBadge.Icon icon={CheckIcon} />)
})

it('should have no axe violations', async () => {
Expand Down