widgetLayout.stories.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {CodeSnippet} from 'sentry/components/codeSnippet';
  4. import JSXNode from 'sentry/components/stories/jsxNode';
  5. import SizingWindow from 'sentry/components/stories/sizingWindow';
  6. import storyBook from 'sentry/stories/storyBook';
  7. import {LineChartWidgetVisualization} from '../lineChartWidget/lineChartWidgetVisualization';
  8. import sampleDurationTimeSeries from '../lineChartWidget/sampleDurationTimeSeries.json';
  9. import {WidgetButton} from './widgetButton';
  10. import {WidgetDescription} from './widgetDescription';
  11. import {WidgetLayout} from './widgetLayout';
  12. import {WidgetTitle} from './widgetTitle';
  13. export default storyBook(WidgetLayout, story => {
  14. story('Getting Started', () => {
  15. return (
  16. <Fragment>
  17. <p>
  18. In most cases, we recommend using standard widgets like{' '}
  19. <JSXNode name="LineChartWidget" />. If this isn't possible (because of custom
  20. layout needs), we offer a set of helper components. Components like{' '}
  21. <JSXNode name="WidgetLayout" /> can be used to create a standard-looking widget
  22. from near-scratch.
  23. </p>
  24. </Fragment>
  25. );
  26. });
  27. story('WidgetLayout', () => {
  28. return (
  29. <Fragment>
  30. <p>
  31. <JSXNode name="WidgetLayout" /> is a layout-only component. It contains no
  32. logic, all it does it place the passed components in correct locations in a
  33. bordered widget frame. The contents of the <code>Title</code> prop are shown in
  34. the top left, and are always visible. The title is truncated to fit. The
  35. contents of the <code>Actions</code> prop are shown in the top right, and only
  36. shown on hover. Actions are not truncated. The contents of{' '}
  37. <code>Visualization</code> are always visible, shown below the title and
  38. actions. The layout expands both horizontally and vertically to fit the parent.
  39. </p>
  40. <p>
  41. In order to make a nice-looking custom widget layout we recommend using the
  42. pre-built components that we provide alongside the layout.
  43. </p>
  44. <CodeSnippet language="jsx">
  45. {`import {LineChartWidgetVisualization} from '../lineChartWidget/lineChartWidgetVisualization';
  46. import sampleDurationTimeSeries from '../lineChartWidget/sampleDurationTimeSeries.json';
  47. import {WidgetButton} from './widgetButton';
  48. import {WidgetDescription} from './widgetDescription';
  49. import {WidgetLayout} from './widgetLayout';
  50. import {WidgetTitle} from './widgetTitle';
  51. <WidgetLayout
  52. Title={<WidgetTitle title="epm()" />}
  53. Actions={
  54. <Fragment>
  55. <WidgetButton>Say More</WidgetButton>
  56. <WidgetButton>Say Less</WidgetButton>
  57. <WidgetDescription
  58. title="epm()"
  59. description="Events received, tracked per minute"
  60. />
  61. </Fragment>
  62. }
  63. Visualization={
  64. <LineChartWidgetVisualization timeseries={[sampleDurationTimeSeries]} />
  65. }
  66. Footer={<p>This data is incomplete!</p>}
  67. />
  68. `}
  69. </CodeSnippet>
  70. <SmallSizingWindow>
  71. <WidgetLayout
  72. Title={<WidgetTitle title="epm()" />}
  73. Actions={
  74. <Fragment>
  75. <WidgetButton>Say More</WidgetButton>
  76. <WidgetButton>Say Less</WidgetButton>
  77. <WidgetDescription
  78. title="epm()"
  79. description="Events received, tracked per minute"
  80. />
  81. </Fragment>
  82. }
  83. Visualization={
  84. <LineChartWidgetVisualization timeseries={[sampleDurationTimeSeries]} />
  85. }
  86. Footer={<p>This data is incomplete!</p>}
  87. />
  88. </SmallSizingWindow>
  89. </Fragment>
  90. );
  91. });
  92. });
  93. const SmallSizingWindow = styled(SizingWindow)`
  94. width: 400px;
  95. height: 300px;
  96. `;