colorBar.stories.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import styled from '@emotion/styled';
  2. import Tooltip from 'sentry/components/tooltip';
  3. import theme from 'sentry/utils/theme';
  4. import ColorBar from 'sentry/views/performance/vitalDetail/colorBar.tsx';
  5. export default {
  6. title: 'Components/Data Visualization/Charts/Color Bar',
  7. component: ColorBar,
  8. };
  9. export const Default = ({...args}) => (
  10. <Container>
  11. <ColorBar {...args} />
  12. </Container>
  13. );
  14. Default.args = {
  15. colorStops: [
  16. {
  17. color: theme.green300,
  18. percent: 0.6,
  19. },
  20. {
  21. color: theme.yellow300,
  22. percent: 0.3,
  23. },
  24. {
  25. color: theme.red300,
  26. percent: 0.1,
  27. },
  28. ],
  29. };
  30. Default.storyName = 'Color Bar';
  31. Default.parameters = {
  32. docs: {
  33. description: {
  34. story:
  35. 'Split a group of percentages or ratios into separate colors. Will stretch to cover the entire bar if missing percents',
  36. },
  37. },
  38. };
  39. export const WithTooltips = ({...args}) => (
  40. <Container>
  41. <ColorBar {...args} />
  42. </Container>
  43. );
  44. WithTooltips.args = {
  45. colorStops: [
  46. {
  47. color: theme.green300,
  48. percent: 0.6,
  49. renderBarStatus: (barStatus, key) => (
  50. <Tooltip title="A - 60%" skipWrapper key={key}>
  51. {barStatus}
  52. </Tooltip>
  53. ),
  54. },
  55. {
  56. color: theme.yellow300,
  57. percent: 0.4,
  58. renderBarStatus: (barStatus, key) => (
  59. <Tooltip title="B - 40%" skipWrapper key={key}>
  60. {barStatus}
  61. </Tooltip>
  62. ),
  63. },
  64. ],
  65. };
  66. WithTooltips.parameters = {
  67. docs: {
  68. description: {
  69. story:
  70. 'Specify a custom render function for the bars. For example you can add Tooltips via composition.',
  71. },
  72. },
  73. };
  74. const Container = styled('div')`
  75. display: inline-block;
  76. width: 300px;
  77. `;