use-expand-collapse.stories.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import PropTypes from 'prop-types'
  2. import useExpandCollapse from '../js/shared/hooks/use-expand-collapse'
  3. function TestUI({ children, expandableProps, toggleProps }) {
  4. return (
  5. <>
  6. <div {...expandableProps}>{children}</div>
  7. <button {...toggleProps}>Expand/collapse</button>
  8. </>
  9. )
  10. }
  11. function VerticalTestUI(props) {
  12. return <TestUI {...props}>{verticalContents}</TestUI>
  13. }
  14. function HorizontalTestUI(props) {
  15. return <TestUI {...props}>{horizontalContents}</TestUI>
  16. }
  17. VerticalTestUI.propTypes = {
  18. expandableProps: PropTypes.object,
  19. toggleProps: PropTypes.object,
  20. }
  21. HorizontalTestUI.propTypes = VerticalTestUI.propTypes
  22. TestUI.propTypes = {
  23. ...VerticalTestUI.propTypes,
  24. children: PropTypes.node,
  25. }
  26. export const Vertical = args => {
  27. const { expandableProps, toggleProps } = useExpandCollapse(args)
  28. return (
  29. <VerticalTestUI
  30. expandableProps={expandableProps}
  31. toggleProps={toggleProps}
  32. />
  33. )
  34. }
  35. export const VerticalInitiallyExpanded = args => {
  36. const { expandableProps, toggleProps } = useExpandCollapse(args)
  37. return (
  38. <VerticalTestUI
  39. expandableProps={expandableProps}
  40. toggleProps={toggleProps}
  41. />
  42. )
  43. }
  44. VerticalInitiallyExpanded.args = {
  45. initiallyExpanded: true,
  46. }
  47. export const VerticalWithMinSize = args => {
  48. const { expandableProps, toggleProps } = useExpandCollapse(args)
  49. return (
  50. <VerticalTestUI
  51. expandableProps={expandableProps}
  52. toggleProps={toggleProps}
  53. />
  54. )
  55. }
  56. VerticalWithMinSize.args = {
  57. collapsedSize: 200,
  58. }
  59. export const Horizontal = args => {
  60. const { expandableProps, toggleProps } = useExpandCollapse(args)
  61. return (
  62. <HorizontalTestUI
  63. expandableProps={expandableProps}
  64. toggleProps={toggleProps}
  65. />
  66. )
  67. }
  68. Horizontal.args = {
  69. dimension: 'width',
  70. }
  71. export const HorizontalInitiallyExpanded = args => {
  72. const { expandableProps, toggleProps } = useExpandCollapse(args)
  73. return (
  74. <HorizontalTestUI
  75. expandableProps={expandableProps}
  76. toggleProps={toggleProps}
  77. />
  78. )
  79. }
  80. HorizontalInitiallyExpanded.args = {
  81. initiallyExpanded: true,
  82. }
  83. export const HorizontalWithMinSize = args => {
  84. const { expandableProps, toggleProps } = useExpandCollapse(args)
  85. return (
  86. <HorizontalTestUI
  87. expandableProps={expandableProps}
  88. toggleProps={toggleProps}
  89. />
  90. )
  91. }
  92. HorizontalWithMinSize.args = {
  93. dimension: 'width',
  94. collapsedSize: 200,
  95. }
  96. const defaultContentStyles = {
  97. display: 'flex',
  98. justifyContent: 'center',
  99. alignItems: 'center',
  100. fontSize: '2em',
  101. backgroundImage: 'linear-gradient(to bottom, red, blue)',
  102. width: '500px',
  103. height: '500px',
  104. color: '#FFF',
  105. }
  106. const verticalContents = <div style={defaultContentStyles}>Vertical</div>
  107. const horizontalContents = (
  108. <div
  109. style={{
  110. ...defaultContentStyles,
  111. backgroundImage: 'linear-gradient(to right, red, blue)',
  112. }}
  113. >
  114. Horizontal
  115. </div>
  116. )
  117. export default {
  118. title: 'Shared / Hooks / useExpandCollapse',
  119. }