/
index.tsx
42 lines (37 loc) · 1.13 KB
/
index.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
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* Internal dependencies
*/
import type { ProgressBarProps } from './types';
import type { WordPressComponentProps } from '../ui/context';
// Width of the indicator for the indeterminate progress bar
export const INDETERMINATE_TRACK_WIDTH = 50;
export function ProgressBar(
props: WordPressComponentProps< ProgressBarProps, 'div', false >
) {
const { className, value, indicatorColor, trackColor } = props;
const isIndeterminate = ! Number.isFinite( value );
const wrapperClasses = classnames( 'components-progress-bar', className, {
'is-indeterminate': isIndeterminate,
} );
const trackStyle = {
backgroundColor: trackColor ? trackColor : undefined,
};
const indicatorStyle = {
width: `${ isIndeterminate ? INDETERMINATE_TRACK_WIDTH : value }%`,
backgroundColor: indicatorColor ? indicatorColor : undefined,
};
return (
<div className={ wrapperClasses } style={ trackStyle }>
<div
className="components-progress-bar__indicator"
style={ indicatorStyle }
/>
<progress max={ 100 } value={ value } />
</div>
);
}
export default ProgressBar;