Skip to content

Commit

Permalink
Merge pull request #1092 from cozy/percentage-line
Browse files Browse the repository at this point in the history
feat: Add PercentageLine
  • Loading branch information
ptbrowne authored Jul 5, 2019
2 parents 2e7238b + b79162b commit 40f1659
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = {
'../react/Chip/index.jsx',
'../react/Icon/index.jsx',
'../react/Spinner/index.jsx',
'../react/Counter/index.jsx'
'../react/Counter/index.jsx',
'../react/PercentageLine/index.jsx'
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions react/PercentageLine/PercentageLine.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PercentageLine
transition transform 0.3s ease
transform-origin 0 0
height 5px
8 changes: 8 additions & 0 deletions react/PercentageLine/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```
initialState = { percentage: Math.random() * 100 };
<>
<button onClick={() => setState({ percentage: Math.random() * 100})}>Random percentage</button>
<PercentageLine color='var(--primaryColor)' value={state.percentage}/>
</>
```
28 changes: 28 additions & 0 deletions react/PercentageLine/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import cx from 'classnames'
import styles from './PercentageLine.styl'
import PropTypes from 'prop-types'

const PercentageLine = ({ value, color, className, style }) => (
<div
className={cx(className, styles.PercentageLine)}
style={{
transform: `scaleX(${value / 100})`,
backgroundColor: color,
...style
}}
/>
)

PercentageLine.propTypes = {
/** @type Value in percent */
value: PropTypes.number.isRequired,
/** @type CSS color or CSS variable */
color: PropTypes.string.isRequired,
/** @type Additional className */
className: PropTypes.string,
/** @type Custom style */
style: PropTypes.object
}

export default PercentageLine
1 change: 1 addition & 0 deletions react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ export { default as Viewer } from './Viewer/ViewerExposer'
export { default as FileInput } from './FileInput'
export { default as Card } from './Card'
export { default as InlineCard } from './InlineCard'
export { default as PercentageLine } from './PercentageLine'

0 comments on commit 40f1659

Please sign in to comment.