Skip to content

Commit

Permalink
Merge pull request #987 from primer/cb/ts-progress-bar
Browse files Browse the repository at this point in the history
Migrate ProgressBar to TypeScript
  • Loading branch information
colebemis authored Feb 4, 2021
2 parents f78c828 + d41d361 commit b408de4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-carrots-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Migrate `ProgressBar` to TypeScript
31 changes: 21 additions & 10 deletions src/ProgressBar.js → src/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react'
// @ts-ignore @styled-system/prop-types does not provide type definitions
import systemPropTypes from '@styled-system/prop-types'
import PropTypes from 'prop-types'
import React from 'react'
import styled from 'styled-components'
import {layout} from 'styled-system'
import systemPropTypes from '@styled-system/prop-types'
import {width, WidthProps} from 'styled-system'
import {COMMON, get, SystemCommonProps} from './constants'
import sx, {SxProp} from './sx'
import theme from './theme'
import {COMMON, get} from './constants'
import sx from './sx'
import {ComponentProps} from './utils/types'

const Bar = styled.span`
const Bar = styled.span<{progress?: string | number} & SystemCommonProps>`
width: ${props => (props.progress ? `${props.progress}%` : 0)};
${COMMON}
`
Expand All @@ -18,18 +20,27 @@ const sizeMap = {
default: '8px'
}

const ProgressContainer = styled.span`
type StyledProgressContainerProps = {
inline?: boolean
barSize?: keyof typeof sizeMap
} & WidthProps &
SystemCommonProps &
SxProp

const ProgressContainer = styled.span<StyledProgressContainerProps>`
display: ${props => (props.inline ? 'inline-flex' : 'flex')};
overflow: hidden;
background-color: ${get('colors.gray.2')};
border-radius: ${get('radii.1')};
height: ${props => sizeMap[props.barSize]};
height: ${props => sizeMap[props.barSize || 'default']};
${COMMON}
${layout.width}
${width}
${sx};
`

const ProgressBar = ({progress, bg, theme, ...rest}) => {
export type ProgressBarProps = ComponentProps<typeof ProgressContainer> & ComponentProps<typeof Bar>

function ProgressBar({progress, bg, theme, ...rest}: ProgressBarProps) {
return (
<ProgressContainer theme={theme} {...rest}>
<Bar progress={progress} bg={bg} theme={theme} />
Expand Down
File renamed without changes.

1 comment on commit b408de4

@vercel
Copy link

@vercel vercel bot commented on b408de4 Feb 4, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.