You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

align-distribute.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {
  2. AlignBottomIcon,
  3. AlignCenterHorizontallyIcon,
  4. AlignCenterVerticallyIcon,
  5. AlignLeftIcon,
  6. AlignRightIcon,
  7. AlignTopIcon,
  8. SpaceEvenlyHorizontallyIcon,
  9. SpaceEvenlyVerticallyIcon,
  10. StretchHorizontallyIcon,
  11. StretchVerticallyIcon,
  12. } from '@radix-ui/react-icons'
  13. import { IconButton } from 'components/shared'
  14. import state from 'state'
  15. import styled from 'styles'
  16. import { AlignType, DistributeType, StretchType } from 'types'
  17. function alignTop() {
  18. state.send('ALIGNED', { type: AlignType.Top })
  19. }
  20. function alignCenterVertical() {
  21. state.send('ALIGNED', { type: AlignType.CenterVertical })
  22. }
  23. function alignBottom() {
  24. state.send('ALIGNED', { type: AlignType.Bottom })
  25. }
  26. function stretchVertically() {
  27. state.send('STRETCHED', { type: StretchType.Vertical })
  28. }
  29. function distributeVertically() {
  30. state.send('DISTRIBUTED', { type: DistributeType.Vertical })
  31. }
  32. function alignLeft() {
  33. state.send('ALIGNED', { type: AlignType.Left })
  34. }
  35. function alignCenterHorizontal() {
  36. state.send('ALIGNED', { type: AlignType.CenterHorizontal })
  37. }
  38. function alignRight() {
  39. state.send('ALIGNED', { type: AlignType.Right })
  40. }
  41. function stretchHorizontally() {
  42. state.send('STRETCHED', { type: StretchType.Horizontal })
  43. }
  44. function distributeHorizontally() {
  45. state.send('DISTRIBUTED', { type: DistributeType.Horizontal })
  46. }
  47. export default function AlignDistribute({
  48. hasTwoOrMore,
  49. hasThreeOrMore,
  50. }: {
  51. hasTwoOrMore: boolean
  52. hasThreeOrMore: boolean
  53. }): JSX.Element {
  54. return (
  55. <Container>
  56. <IconButton
  57. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  58. size="small"
  59. disabled={!hasTwoOrMore}
  60. onClick={alignLeft}
  61. >
  62. <AlignLeftIcon />
  63. </IconButton>
  64. <IconButton
  65. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  66. size="small"
  67. disabled={!hasTwoOrMore}
  68. onClick={alignCenterHorizontal}
  69. >
  70. <AlignCenterHorizontallyIcon />
  71. </IconButton>
  72. <IconButton
  73. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  74. size="small"
  75. disabled={!hasTwoOrMore}
  76. onClick={alignRight}
  77. >
  78. <AlignRightIcon />
  79. </IconButton>
  80. <IconButton
  81. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  82. size="small"
  83. disabled={!hasTwoOrMore}
  84. onClick={stretchHorizontally}
  85. >
  86. <StretchHorizontallyIcon />
  87. </IconButton>
  88. <IconButton
  89. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  90. size="small"
  91. disabled={!hasThreeOrMore}
  92. onClick={distributeHorizontally}
  93. >
  94. <SpaceEvenlyHorizontallyIcon />
  95. </IconButton>
  96. <IconButton
  97. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  98. size="small"
  99. disabled={!hasTwoOrMore}
  100. onClick={alignTop}
  101. >
  102. <AlignTopIcon />
  103. </IconButton>
  104. <IconButton
  105. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  106. size="small"
  107. disabled={!hasTwoOrMore}
  108. onClick={alignCenterVertical}
  109. >
  110. <AlignCenterVerticallyIcon />
  111. </IconButton>
  112. <IconButton
  113. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  114. size="small"
  115. disabled={!hasTwoOrMore}
  116. onClick={alignBottom}
  117. >
  118. <AlignBottomIcon />
  119. </IconButton>
  120. <IconButton
  121. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  122. size="small"
  123. disabled={!hasTwoOrMore}
  124. onClick={stretchVertically}
  125. >
  126. <StretchVerticallyIcon />
  127. </IconButton>
  128. <IconButton
  129. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  130. size="small"
  131. disabled={!hasThreeOrMore}
  132. onClick={distributeVertically}
  133. >
  134. <SpaceEvenlyVerticallyIcon />
  135. </IconButton>
  136. </Container>
  137. )
  138. }
  139. const Container = styled('div', {
  140. display: 'grid',
  141. padding: 4,
  142. gridTemplateColumns: 'repeat(5, auto)',
  143. [`& ${IconButton} > svg`]: {
  144. stroke: 'transparent',
  145. },
  146. })