-
Notifications
You must be signed in to change notification settings - Fork 616
Migrate ProgressBar to TypeScript #987
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
Changes from all commits
288465c
f9a7e78
9c3a849
81bfc0c
d41d361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/components": patch | ||
--- | ||
|
||
Migrate `ProgressBar` to TypeScript |
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} | ||
` | ||
|
@@ -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']}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary if we're setting the default value in defaultProps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't be necessary. But defaultProps + styled-components + TypeScript don't play well together in this case. TypeScript was complaining about |
||
${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} /> | ||
|
Uh oh!
There was an error while loading. Please reload this page.