tabs.stories.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import styled from '@emotion/styled';
  2. import {Item, TabList, TabPanels, Tabs} from 'sentry/components/tabs';
  3. import space from 'sentry/styles/space';
  4. export default {
  5. title: 'Views/Tabs',
  6. component: Tabs,
  7. };
  8. const TABS = [
  9. {key: 'details', label: 'Details', content: 'So by colonel hearted ferrars.'},
  10. {
  11. key: 'activity',
  12. label: 'Activity',
  13. content: 'Draw from upon here gone add one.',
  14. },
  15. {
  16. key: 'user-feedback',
  17. label: 'User Feedback',
  18. content: 'He in sportsman household otherwise it perceived instantly.',
  19. },
  20. {
  21. key: 'attachments',
  22. label: 'Attachments',
  23. content: 'Do play they miss give so up.',
  24. },
  25. {
  26. key: 'tags',
  27. label: 'Tags',
  28. content: 'Words to up style of since world.',
  29. },
  30. {
  31. key: 'disabled',
  32. label: 'Disabled',
  33. content: 'Unreachable content.',
  34. disabled: true,
  35. },
  36. ];
  37. export const Default = args => {
  38. return (
  39. <Tabs {...args}>
  40. <TabList>
  41. {TABS.map(tab => (
  42. <Item key={tab.key} disabled={tab.disabled}>
  43. {tab.label}
  44. </Item>
  45. ))}
  46. </TabList>
  47. <StyledTabPanels orientation={args.orientation}>
  48. {TABS.map(tab => (
  49. <Item key={tab.key}>{tab.content}</Item>
  50. ))}
  51. </StyledTabPanels>
  52. </Tabs>
  53. );
  54. };
  55. Default.storyName = 'Default';
  56. Default.args = {
  57. orientation: 'horizontal',
  58. disabled: false,
  59. value: undefined,
  60. defaultValue: undefined,
  61. };
  62. Default.argTypes = {
  63. orientation: {
  64. options: ['horizontal', 'vertical'],
  65. control: {type: 'radio'},
  66. },
  67. value: {
  68. options: TABS.map(tab => tab.key),
  69. control: {type: 'select'},
  70. },
  71. defaultValue: {
  72. options: TABS.map(tab => tab.key),
  73. control: {type: 'select'},
  74. },
  75. className: {control: {type: 'disabed'}},
  76. };
  77. const TABS_LINKS = [
  78. {
  79. key: 'details',
  80. label: 'Details',
  81. content:
  82. 'These tabs act like links. You can command/ctrl/shift-click to open in a new browser tab/window.',
  83. to: '/?path=/story/views-tabs--tab-links&args=selectedValue:details',
  84. },
  85. {
  86. key: 'activity',
  87. label: 'Activity',
  88. content:
  89. 'These tabs act like links. You can command/ctrl/shift-click to open in a new browser tab/window.',
  90. to: '/?path=/story/views-tabs--tab-links&args=selectedValue:activity',
  91. },
  92. ];
  93. export const TabLinks = ({selectedValue, ...args}) => {
  94. return (
  95. <Tabs {...args} value={selectedValue}>
  96. <TabList>
  97. {TABS_LINKS.map(tab => (
  98. <Item key={tab.key} to={tab.to}>
  99. {tab.label}
  100. </Item>
  101. ))}
  102. </TabList>
  103. <StyledTabPanels orientation={args.orientation}>
  104. {TABS_LINKS.map(tab => (
  105. <Item key={tab.key}>{tab.content}</Item>
  106. ))}
  107. </StyledTabPanels>
  108. </Tabs>
  109. );
  110. };
  111. TabLinks.storyName = 'Tab Links';
  112. TabLinks.args = Default.args;
  113. TabLinks.argTypes = {
  114. value: {control: false},
  115. defaultValue: {control: false},
  116. selectedValue: {control: false},
  117. };
  118. // To add styles to tab panels, wrap styled() around `TabPanels`, not `Item`
  119. const StyledTabPanels = styled(TabPanels)`
  120. ${p =>
  121. p.orientation === 'horizontal'
  122. ? `padding: ${space(2)} 0;`
  123. : `padding: 0 ${space(2)};`};
  124. color: ${p => p.theme.subText};
  125. `;