forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgressBar.tsx
53 lines (42 loc) · 1.22 KB
/
ProgressBar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react'
import styled from 'styled-components'
import {width, WidthProps} from 'styled-system'
import {get} from './constants'
import sx, {SxProp} from './sx'
type ProgressProp = {progress?: string | number}
const Bar = styled.span<ProgressProp & SxProp>`
width: ${props => (props.progress ? `${props.progress}%` : 0)};
${sx};
`
const sizeMap = {
small: '5px',
large: '10px',
default: '8px'
}
type StyledProgressContainerProps = {
inline?: boolean
barSize?: keyof typeof sizeMap
} & WidthProps &
SxProp
const ProgressContainer = styled.span<StyledProgressContainerProps>`
display: ${props => (props.inline ? 'inline-flex' : 'flex')};
overflow: hidden;
background-color: ${get('colors.border.default')};
border-radius: ${get('radii.1')};
height: ${props => sizeMap[props.barSize || 'default']};
${width}
${sx};
`
export type ProgressBarProps = {bg: string} & StyledProgressContainerProps & ProgressProp
function ProgressBar({progress, bg, ...rest}: ProgressBarProps) {
return (
<ProgressContainer {...rest}>
<Bar progress={progress} sx={{bg}} />
</ProgressContainer>
)
}
ProgressBar.defaultProps = {
bg: 'success.emphasis',
barSize: 'default'
}
export default ProgressBar