This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import classNames from "classnames"; | ||
|
||
const propTypes = { | ||
value: PropTypes.number, | ||
children: PropTypes.node, | ||
text: PropTypes.string, | ||
blocking: PropTypes.bool, | ||
hidden: PropTypes.bool, | ||
className: PropTypes.string | ||
}; | ||
|
||
const defaultProps = { | ||
value: 0, | ||
blocking: false, | ||
hidden: false | ||
}; | ||
|
||
const Progress = ({ | ||
className, | ||
value, | ||
text, | ||
blocking, | ||
hidden, | ||
children, | ||
...attributes | ||
}) => { | ||
const classes = classNames( | ||
"progress-bar", | ||
blocking ? "progress-bar--blocking" : null, | ||
className | ||
); | ||
|
||
return ( | ||
<div {...attributes} className={classes}> | ||
<div className={classNames("progress-bar__meter", hidden ? "hidden" : null)}> | ||
<div className="progress-bar__value" style={{ width: `${value}%` }} /> | ||
{text && <div className="progress-bar__text">{text}</div>} | ||
</div> | ||
{!!children && <>{children}</>} | ||
</div> | ||
); | ||
}; | ||
|
||
Progress.propTypes = propTypes; | ||
Progress.defaultProps = defaultProps; | ||
|
||
export default Progress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
packages/kpn-style-react/stories/ProgressBar.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { | ||
Card, | ||
CardBody, | ||
CardHeader, | ||
CardTitle, | ||
Col, | ||
ProgressBar, | ||
Row | ||
} from "@kpn-style/react"; | ||
import { boolean, number, text, withKnobs } from "@storybook/addon-knobs"; | ||
|
||
import React from "react"; | ||
import { storiesOf } from "@storybook/react"; | ||
import { updateKnob } from "./utils"; | ||
|
||
const stories = storiesOf("Components.ProgressBar", module).addDecorator( | ||
withKnobs | ||
); | ||
|
||
stories.add("Simple", () => { | ||
const options = { | ||
range: true, | ||
min: 0, | ||
max: 100, | ||
step: 1 | ||
}; | ||
const value = number("value", 0, options); | ||
const _text = text("text", "Please wait"); | ||
return <ProgressBar value={value} text={_text} />; | ||
}); | ||
|
||
stories.add("Animated", () => { | ||
const options = { | ||
range: true, | ||
min: 0, | ||
max: 100, | ||
step: 1 | ||
}; | ||
const _text = text("text"); | ||
const value = number("value", 0, options); | ||
const delayInMilliseconds = 100; //1 second | ||
setTimeout(function() { | ||
if (value <= 95) { | ||
updateKnob("value", value + 5); | ||
} else { | ||
updateKnob("value", 0); | ||
} | ||
}, delayInMilliseconds); | ||
return <ProgressBar value={value} text={_text} />; | ||
}); | ||
|
||
stories.add("Blocking content", () => { | ||
const options = { | ||
range: true, | ||
min: 0, | ||
max: 100, | ||
step: 1 | ||
}; | ||
const value = number("value", 0, options); | ||
const _text = text("text", "Please wait"); | ||
const blocking = boolean("blocking", true); | ||
const hidden = boolean("hidden", false); | ||
return ( | ||
<Row> | ||
<Col xs={4}> | ||
<ProgressBar | ||
value={value} | ||
text={_text} | ||
blocking={blocking} | ||
hidden={hidden} | ||
> | ||
<Card> | ||
<CardBody>Hello</CardBody> | ||
</Card> | ||
</ProgressBar> | ||
</Col> | ||
</Row> | ||
); | ||
}); | ||
|
||
stories.add("Animated Blocking content", () => { | ||
const options = { | ||
range: true, | ||
min: 0, | ||
max: 100, | ||
step: 1 | ||
}; | ||
const value = number("value", 0, options); | ||
const _text = text("text", "Please wait"); | ||
const blocking = boolean("blocking", true); | ||
const delayInMilliseconds = 100; //1 second | ||
const timer = () => { | ||
const ti = setTimeout(function() { | ||
updateKnob("value", value + 10); | ||
if (value > 89) { | ||
updateKnob("blocking", false); | ||
stop() | ||
} | ||
|
||
}, delayInMilliseconds); | ||
|
||
function stop() { | ||
clearTimeout(ti) | ||
|
||
} | ||
}; | ||
if (value < 100) { | ||
timer(); | ||
} | ||
return ( | ||
<Row> | ||
<Col xs={4}> | ||
<ProgressBar | ||
value={value} | ||
text={_text} | ||
blocking={blocking} | ||
hidden={!blocking} | ||
> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Welcome</CardTitle> | ||
</CardHeader> | ||
<CardBody>Hello to this fantastic place</CardBody> | ||
</Card> | ||
<small>Terms and conditions may apply</small> | ||
</ProgressBar> | ||
</Col> | ||
</Row> | ||
); | ||
}); |