draggableTabBar.stories.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import {Button} from 'sentry/components/button';
  5. import JSXNode from 'sentry/components/stories/jsxNode';
  6. import SizingWindow from 'sentry/components/stories/sizingWindow';
  7. import storyBook from 'sentry/stories/storyBook';
  8. import {
  9. DraggableTabBar,
  10. type Tab,
  11. } from 'sentry/views/issueList/groupSearchViewTabs/draggableTabBar';
  12. const TabPanelContainer = styled('div')`
  13. width: 90%;
  14. height: 250px;
  15. background-color: white;
  16. `;
  17. const TABS: Tab[] = [
  18. {
  19. key: 'one',
  20. label: 'Inbox',
  21. content: <TabPanelContainer>This is the Inbox view</TabPanelContainer>,
  22. queryCount: 1001,
  23. hasUnsavedChanges: true,
  24. },
  25. {
  26. key: 'two',
  27. label: 'For Review',
  28. content: <TabPanelContainer>This is the For Review view</TabPanelContainer>,
  29. queryCount: 50,
  30. hasUnsavedChanges: false,
  31. },
  32. {
  33. key: 'three',
  34. label: 'Regressed',
  35. content: <TabPanelContainer>This is the Regressed view</TabPanelContainer>,
  36. queryCount: 100,
  37. hasUnsavedChanges: false,
  38. },
  39. ];
  40. export default storyBook(DraggableTabBar, story => {
  41. story('Default', () => {
  42. const [showTempTab, setShowTempTab] = useState(false);
  43. const [tabs, setTabs] = useState(TABS);
  44. const tempTab = {
  45. key: 'temporary-tab',
  46. label: 'Unsaved',
  47. content: <TabPanelContainer>This is the Temporary view</TabPanelContainer>,
  48. };
  49. const defaultNewTab = {
  50. key: `view-${tabs.length + 1}`,
  51. label: `New View`,
  52. content: <TabPanelContainer>This is the a New View</TabPanelContainer>,
  53. };
  54. return (
  55. <Fragment>
  56. <Alert type="warning">This component is still a work in progress.</Alert>
  57. <p>
  58. You should be using all of <JSXNode name="Tabs" />, <JSXNode name="TabList" />,{' '}
  59. <JSXNode name="TabList.Item" />, <JSXNode name="DroppableTabPanels" /> and
  60. <JSXNode name="DroppableTabPanels.Item" /> components.
  61. </p>
  62. <p>
  63. This will give you all kinds of accessibility and state tracking out of the box.
  64. But you will have to render all tab content, including hooks, upfront.
  65. </p>
  66. <SizingWindow style={{flexDirection: 'column', alignItems: 'flex-start'}}>
  67. <StyledButton onClick={() => setShowTempTab(!showTempTab)}>
  68. Toggle Temporary View
  69. </StyledButton>
  70. <TabBarContainer>
  71. <DraggableTabBar
  72. tabs={tabs}
  73. setTabs={setTabs}
  74. showTempTab={showTempTab}
  75. tempTabContent={
  76. <TabPanelContainer>This is a Temporary view</TabPanelContainer>
  77. }
  78. defaultNewTab={defaultNewTab}
  79. tempTab={tempTab}
  80. onDiscardTempView={() => {
  81. setShowTempTab(false);
  82. }}
  83. />
  84. </TabBarContainer>
  85. </SizingWindow>
  86. </Fragment>
  87. );
  88. });
  89. });
  90. const StyledButton = styled(Button)`
  91. justify-content: start;
  92. margin-bottom: 5px;
  93. `;
  94. const TabBarContainer = styled('div')`
  95. display: flex;
  96. justify-content: start;
  97. width: 90%;
  98. height: 300px;
  99. `;