progressRing.stories.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {Component} from 'react';
  2. import {css} from '@emotion/core';
  3. import styled from '@emotion/styled';
  4. import ProgressRing from 'sentry/components/progressRing';
  5. class Ticker extends Component {
  6. state = {
  7. tickNumber: 0,
  8. };
  9. componentDidMount() {
  10. this.interval = setInterval(this.tick, 1000);
  11. }
  12. componentWillUnmount() {
  13. clearInterval(this.interval);
  14. }
  15. tick = () =>
  16. this.setState(s => ({
  17. tickNumber: (s.tickNumber + 5) % 100,
  18. }));
  19. render() {
  20. return this.props.children({tickNumber: this.state.tickNumber});
  21. }
  22. }
  23. export default {
  24. title: 'Components/Data Visualization/Charts/Progress Ring',
  25. args: {
  26. value: 29,
  27. size: 40,
  28. minValue: 0,
  29. maxValue: 100,
  30. barWidth: 3,
  31. text: '',
  32. animateText: false,
  33. },
  34. argTypes: {
  35. backgroundColor: {control: 'color'},
  36. progressColor: {control: 'color'},
  37. },
  38. };
  39. export const Default = ({...args}) => {
  40. return (
  41. <Grid>
  42. <ProgressRing {...args} />
  43. <Ticker>
  44. {({tickNumber}) => (
  45. <ProgressRing
  46. animateText
  47. value={tickNumber}
  48. text={tickNumber}
  49. size={38}
  50. barWidth={4}
  51. progressColor="#f58159"
  52. />
  53. )}
  54. </Ticker>
  55. <ProgressRing
  56. value={65}
  57. size={60}
  58. barWidth={6}
  59. text="BAD"
  60. textCss={() => css`
  61. font-size: 14px;
  62. font-weight: bold;
  63. color: #ec5f5f;
  64. `}
  65. progressColor="#ff4d44"
  66. backgroundColor="#fbe6e6"
  67. />
  68. </Grid>
  69. );
  70. };
  71. Default.storyName = 'Progress Ring';
  72. const Grid = styled('div')`
  73. margin-top: 8px;
  74. display: grid;
  75. grid-template-columns: repeat(auto-fit, 50px);
  76. align-items: center;
  77. justify-content: center;
  78. gap: 8px;
  79. `;