Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

align-distribute.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. }) {
  54. return (
  55. <Container>
  56. <IconButton disabled={!hasTwoOrMore} onClick={alignLeft}>
  57. <AlignLeftIcon />
  58. </IconButton>
  59. <IconButton disabled={!hasTwoOrMore} onClick={alignCenterHorizontal}>
  60. <AlignCenterHorizontallyIcon />
  61. </IconButton>
  62. <IconButton disabled={!hasTwoOrMore} onClick={alignRight}>
  63. <AlignRightIcon />
  64. </IconButton>
  65. <IconButton disabled={!hasTwoOrMore} onClick={stretchHorizontally}>
  66. <StretchHorizontallyIcon />
  67. </IconButton>
  68. <IconButton disabled={!hasThreeOrMore} onClick={distributeHorizontally}>
  69. <SpaceEvenlyHorizontallyIcon />
  70. </IconButton>
  71. <IconButton disabled={!hasTwoOrMore} onClick={alignTop}>
  72. <AlignTopIcon />
  73. </IconButton>
  74. <IconButton disabled={!hasTwoOrMore} onClick={alignCenterVertical}>
  75. <AlignCenterVerticallyIcon />
  76. </IconButton>
  77. <IconButton disabled={!hasTwoOrMore} onClick={alignBottom}>
  78. <AlignBottomIcon />
  79. </IconButton>
  80. <IconButton disabled={!hasTwoOrMore} onClick={stretchVertically}>
  81. <StretchVerticallyIcon />
  82. </IconButton>
  83. <IconButton disabled={!hasThreeOrMore} onClick={distributeVertically}>
  84. <SpaceEvenlyVerticallyIcon />
  85. </IconButton>
  86. </Container>
  87. )
  88. }
  89. const Container = styled("div", {
  90. display: "grid",
  91. padding: 4,
  92. gridTemplateColumns: "repeat(5, auto)",
  93. [`& ${IconButton}`]: {
  94. color: "$text",
  95. },
  96. [`& ${IconButton} > svg`]: {
  97. fill: "red",
  98. stroke: "transparent",
  99. },
  100. })