This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
progress-bar.js
150 lines (127 loc) · 3.6 KB
/
progress-bar.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import PropTypes from 'prop-types';
import { ProgressColors } from '../enums';
import { GeneralPropTypes, FlexboxPropTypes, createClassName, generalClassNames, removeProps, objectKeys, objectValues } from '../utils';
/**
* Progress component.
* http://foundation.zurb.com/sites/docs/progress-bar.html
*
* @param {Object} props
* @returns {Object}
*/
export const Progress = (props) => {
const { meter: meterProps = {} } = props;
const className = createClassName(
props.noDefaultClassName ? null : 'progress',
props.className,
props.color,
generalClassNames(props)
);
if (props.value) {
meterProps.style = meterProps.style || {};
meterProps.style.width = `${props.value}%`;
}
const passProps = removeProps(props, objectKeys(Progress.propTypes));
return (
<div {...passProps}
className={className}
role="progressbar"
aria-valuemin={props.min}
aria-valuemax={props.max}
aria-valuenow={props.value}
aria-valuetext={props.valueText}>
{meterProps.text ? <ProgressMeterWithText {...meterProps} /> : <ProgressMeter {...meterProps} />}
</div>
);
};
Progress.propTypes = {
...GeneralPropTypes,
...FlexboxPropTypes,
min: PropTypes.number,
max: PropTypes.number,
value: PropTypes.number,
color: PropTypes.oneOf(objectValues(ProgressColors))
};
/**
* Progress meter sub-component.
*
* @param {Object} props
* @returns {Object}
*/
export const ProgressMeter = (props) => {
const className = createClassName(
props.noDefaultClassName ? null : 'progress-meter',
props.className,
generalClassNames(props)
);
const passProps = removeProps(props, objectKeys(ProgressMeter.propTypes));
return <div {...passProps} className={className}/>;
};
ProgressMeter.propTypes = {
...GeneralPropTypes
};
/**
* Progress meter with text sub-component.
*
* @param {Object} props
* @returns {Object}
*/
export const ProgressMeterWithText = (props) => {
const className = createClassName(
props.noDefaultClassName ? null : 'progress-meter',
props.className,
generalClassNames(props)
);
const passProps = removeProps(props, objectKeys(ProgressMeterWithText.propTypes));
return (
<span {...passProps} className={className}>
<ProgressMeterText>{props.text}</ProgressMeterText>
</span>
);
};
ProgressMeterWithText.propTypes = {
...GeneralPropTypes,
...FlexboxPropTypes,
text: PropTypes.string.isRequired
};
/**
* Progress meter text sub-component.
*
* @param {Object} props
* @returns {Object}
*/
export const ProgressMeterText = (props) => {
const className = createClassName(
props.noDefaultClassName ? null : 'progress-meter-text',
props.className,
generalClassNames(props)
);
const passProps = removeProps(props, objectKeys(ProgressMeterText.propTypes));
return <p {...passProps} className={className}/>;
};
ProgressMeterText.propTypes = {
...GeneralPropTypes
};
/**
* Native progress component.
* http://foundation.zurb.com/sites/docs/progress-bar.html#native-progress
*
* @returns {Object}
*/
export const NativeProgress = (props) => {
const className = createClassName(
props.className,
props.color,
generalClassNames(props)
);
const passProps = removeProps(props, objectKeys(NativeProgress.propTypes));
return <progress {...passProps} max={props.max} value={props.value} className={className}/>;
};
NativeProgress.propTypes = {
...GeneralPropTypes,
...FlexboxPropTypes,
max: PropTypes.number,
value: PropTypes.number,
color: PropTypes.oneOf(objectValues(ProgressColors))
};
// TODO: Consider adding support for native meter.