Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

progress-bar

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
368
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
9 months ago
SIZE
39 KB
Show your progress. A simple way to add progress bars to your layouts. You only need two HTML elements to make them and they're easy to customize.
Use progress-bar in your project ?
Copied
npm i @bit/digiaonline.react-foundation.progress-bar
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
components/progress-bar.js
150 Lines(95 sloc)
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
151
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.