Skip to content

Commit

Permalink
feat: Add PercentageBar component (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
drazik authored Nov 6, 2019
1 parent 82bd844 commit 26dc94f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
'../react/Spinner/index.jsx',
'../react/Counter/index.jsx',
'../react/PercentageLine/index.jsx',
'../react/PercentageBar/index.jsx',
'../react/Stack/index.jsx',
'../react/IconStack/index.jsx'
]
Expand Down
18 changes: 18 additions & 0 deletions react/PercentageBar/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```
import PercentageBar from 'cozy-ui/transpiled/react/PercentageBar';
initialState = { percentage: 0.5 * 100 };
<>
<button onClick={() => setState({ percentage: Math.random() * 100})}>Random percentage</button>
{(state.percentage).toFixed(2)}%
<PercentageBar
color="var(--primaryColor)"
value={state.percentage}
style={{ marginBottom: '2rem' }}
/>
<PercentageBar
color="var(--emerald)"
value={state.percentage}
/>
</>
```
20 changes: 20 additions & 0 deletions react/PercentageBar/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import PercentageLine from '../PercentageLine'
import styles from './styles.styl'
import cx from 'classnames'

const PercentageBar = props => {
const { value, color, className, ...rest } = props

return (
<div className={cx(styles.PercentageBar, className)} {...rest}>
<PercentageLine
value={value}
color={color}
className={styles.PercentageBar__line}
/>
</div>
)
}

export default PercentageBar
11 changes: 11 additions & 0 deletions react/PercentageBar/styles.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
radius = 4px

.PercentageBar
background-color var(--paleGrey)
border 1px solid var(--silver)
height 1.5rem
border-radius radius

.PercentageBar__line
height 100%
border-radius radius
15 changes: 15 additions & 0 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,21 @@ exports[`Menu should render examples: Menu 3`] = `
</div>"
`;
exports[`PercentageBar should render examples: PercentageBar 1`] = `
"<div><button>Random percentage</button>50.00% <div class=\\"styles__PercentageBar___12TWu\\" style=\\"margin-bottom: 2rem;\\">
<div class=\\"styles__PercentageBar__line___1DAnN PercentageLine__PercentageLine___3koWP\\" style=\\"transform: scaleX(0.5);\\"></div>
</div>
<div class=\\"styles__PercentageBar___12TWu\\">
<div class=\\"styles__PercentageBar__line___1DAnN PercentageLine__PercentageLine___3koWP\\" style=\\"transform: scaleX(0.5);\\"></div>
</div>
</div>"
`;
exports[`PercentageLine should render examples: PercentageLine 1`] = `
"<div><button>Random percentage</button>50.00% <div class=\\"PercentageLine__PercentageLine___3koWP\\" style=\\"transform: scaleX(0.5);\\"></div>
</div>"
`;
exports[`QuotaAlert should render examples: QuotaAlert 1`] = `
"<div>
<div><button>Toggle modal</button></div>
Expand Down
2 changes: 2 additions & 0 deletions react/examples.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ testComponent('Label')
testComponent('ListItemText')
testComponent('Media')
testComponent('Menu')
testComponent('PercentageBar')
testComponent('PercentageLine')
testComponent('QuotaAlert')
testComponent('Radio')
testComponent('SelectBox')
Expand Down

0 comments on commit 26dc94f

Please sign in to comment.