progressRing.stories.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React from 'react';
  2. import {withInfo} from '@storybook/addon-info';
  3. import {number, text, boolean, color} from '@storybook/addon-knobs';
  4. import styled from '@emotion/styled';
  5. import {css} from '@emotion/core';
  6. import ProgressRing from 'app/components/progressRing';
  7. class Ticker extends React.Component {
  8. state = {
  9. tickNumber: 0,
  10. };
  11. componentDidMount() {
  12. this.interval = setInterval(this.tick, 1000);
  13. }
  14. componentWillUnmount() {
  15. clearInterval(this.interval);
  16. }
  17. tick = () =>
  18. this.setState(s => ({
  19. tickNumber: (s.tickNumber + 5) % 100,
  20. }));
  21. render() {
  22. return this.props.children({tickNumber: this.state.tickNumber});
  23. }
  24. }
  25. export default {
  26. title: 'UI/ProgressRing',
  27. };
  28. export const Default = withInfo('Circle style progress bar ')(() => {
  29. const value = number('Value', 29);
  30. const size = number('Size', 40);
  31. const minValue = number('Min Value', 0);
  32. const maxValue = number('Max Value', 100);
  33. const barWidth = number('Bar Width', 3);
  34. const textValue = text('Text Value', '');
  35. const animateText = boolean('Animate Text', false);
  36. const backgroundColor = color('Background color');
  37. const progressColor = color('Progress color');
  38. return (
  39. <Grid>
  40. <ProgressRing
  41. value={value}
  42. minValue={minValue}
  43. maxValue={maxValue}
  44. size={size}
  45. barWidth={barWidth}
  46. text={textValue}
  47. animateText={animateText}
  48. backgroundColor={backgroundColor}
  49. progressColor={progressColor}
  50. />
  51. <Ticker>
  52. {({tickNumber}) => (
  53. <ProgressRing
  54. animateText
  55. value={tickNumber}
  56. text={tickNumber}
  57. size={38}
  58. barWidth={4}
  59. progressColor="#f58159"
  60. />
  61. )}
  62. </Ticker>
  63. <ProgressRing
  64. value={65}
  65. size={60}
  66. barWidth={6}
  67. text="BAD"
  68. textCss={() => css`
  69. font-size: 14px;
  70. font-weight: bold;
  71. color: #ec5f5f;
  72. `}
  73. progressColor="#ff4d44"
  74. backgroundColor="#fbe6e6"
  75. />
  76. </Grid>
  77. );
  78. });
  79. Default.story = {
  80. name: 'default',
  81. };
  82. const Grid = styled('div')`
  83. margin-top: 8px;
  84. display: grid;
  85. grid-template-columns: repeat(auto-fit, 50px);
  86. align-items: center;
  87. justify-content: center;
  88. grid-gap: 8px;
  89. `;