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.6KB

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