foldSection.stories.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import {Fragment} from 'react';
  2. import {Button} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import {CodeSnippet} from 'sentry/components/codeSnippet';
  5. import {IconAdd, IconCopy, IconSubtract} from 'sentry/icons';
  6. import storyBook from 'sentry/stories/storyBook';
  7. import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
  8. import {FoldSection} from 'sentry/views/issueDetails/streamline/foldSection';
  9. export default storyBook('FoldSection', story => {
  10. story('Usage', () => (
  11. <Fragment>
  12. <CodeSnippet language="jsx">
  13. {`import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
  14. import {FoldSection} from 'sentry/views/issueDetails/streamline/foldSection';
  15. <FoldSection title="My Section" sectionKey={SectionKey.MY_SECTION}>
  16. <MySectionComponent />
  17. </FoldSection>`}
  18. </CodeSnippet>
  19. <p>
  20. The <code>SectionKey</code> required in props is used to create a local storage
  21. state key to remember the user's previous state for the fold section.
  22. </p>
  23. </Fragment>
  24. ));
  25. story('Default example', () => {
  26. return (
  27. <Fragment>
  28. <FoldSection title="Default Section" sectionKey={SectionKey.HIGHLIGHTS}>
  29. <Lorem />
  30. </FoldSection>
  31. <CodeSnippet language="jsx">
  32. {`<FoldSection title="Default Section" sectionKey={SectionKey.MY_SECTION}>
  33. <p>Lorem ipsum...</p>
  34. </FoldSection>`}
  35. </CodeSnippet>
  36. </Fragment>
  37. );
  38. });
  39. story('Preventing user from collapsing the section', () => {
  40. return (
  41. <Fragment>
  42. <FoldSection
  43. title="Prevent Collapse Section"
  44. sectionKey={SectionKey.HIGHLIGHTS}
  45. preventCollapse
  46. >
  47. <Lorem />
  48. </FoldSection>
  49. <CodeSnippet language="jsx">
  50. {`<FoldSection title="Prevent Collapse Section" sectionKey={SectionKey.MY_SECTION} preventCollapse>
  51. <p>Lorem ipsum...</p>
  52. </FoldSection>`}
  53. </CodeSnippet>
  54. </Fragment>
  55. );
  56. });
  57. story('Custom headers/titles for the section', () => {
  58. return (
  59. <Fragment>
  60. <FoldSection
  61. title={<span style={{color: 'rebeccapurple'}}>Custom Title</span>}
  62. sectionKey={SectionKey.HIGHLIGHTS}
  63. >
  64. <Lorem />
  65. </FoldSection>
  66. <FoldSection
  67. title="Header with Actions"
  68. actions={
  69. <ButtonBar gap={1}>
  70. <Button size="xs" icon={<IconAdd />}>
  71. Add
  72. </Button>
  73. <Button size="xs" icon={<IconSubtract />}>
  74. Remove
  75. </Button>
  76. <Button size="xs" icon={<IconCopy />}>
  77. Copy
  78. </Button>
  79. </ButtonBar>
  80. }
  81. sectionKey={SectionKey.HIGHLIGHTS}
  82. >
  83. <Lorem />
  84. </FoldSection>
  85. <CodeSnippet language="jsx">
  86. {`<FoldSection title={<CustomTitle />} actions={<ButtonBar />} sectionKey={SectionKey.MY_SECTION}>
  87. <p>Lorem ipsum...</p>
  88. </FoldSection>`}
  89. </CodeSnippet>
  90. </Fragment>
  91. );
  92. });
  93. story('Collapsing the section by default', () => {
  94. return (
  95. <Fragment>
  96. <p>
  97. Important Note: User's local storage preferences overwrite this prop, if they
  98. have manually opened this section before, it will stay open and ignore this
  99. prop.
  100. </p>
  101. <FoldSection
  102. title="Initially Collapsed Section"
  103. sectionKey={SectionKey.HIGHLIGHTS}
  104. initialCollapse
  105. >
  106. <Lorem />
  107. </FoldSection>
  108. <CodeSnippet language="jsx">
  109. {`<FoldSection title="Initially Collapsed Section" sectionKey={SectionKey.MY_SECTION} initialCollapse>
  110. <p>Lorem ipsum...</p>
  111. </FoldSection>`}
  112. </CodeSnippet>
  113. </Fragment>
  114. );
  115. });
  116. });
  117. function Lorem() {
  118. return (
  119. <Fragment>
  120. <p>
  121. Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti expedita unde
  122. exercitationem tempora non recusandae sapiente aspernatur, culpa perferendis
  123. illum? Facere cupiditate soluta eligendi aliquam labore ratione corrupti inventore
  124. delectus.
  125. </p>
  126. <p>
  127. Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae suscipit nihil
  128. eaque earum minus, optio officia, nam nemo error harum, cupiditate cum odio
  129. debitis rerum quod maiores ipsa quia nobis? Lorem, ipsum dolor sit amet
  130. consectetur adipisicing elit. Dignissimos, similique reiciendis aliquid eius
  131. corrupti eum magni in dolores deleniti sequi maxime assumenda numquam blanditiis
  132. magnam fuga quo tempore ipsum ducimus! Lorem ipsum dolor sit amet consectetur
  133. adipisicing elit. Repellendus tempore optio architecto, dignissimos assumenda
  134. quasi reiciendis in earum hic quae quidem deserunt dolorum aut, sint impedit
  135. distinctio totam. Ullam, veniam?
  136. </p>
  137. </Fragment>
  138. );
  139. }