foldSection.stories.tsx 4.7 KB

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