stack.tsx 809 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use client";
  2. import { type ComponentRenderProps } from "@json-render/react";
  3. export function Stack({ element, children }: ComponentRenderProps) {
  4. const { direction, gap, align } = element.props as {
  5. direction?: string | null;
  6. gap?: string | null;
  7. align?: string | null;
  8. };
  9. const gaps: Record<string, string> = {
  10. none: "0",
  11. sm: "8px",
  12. md: "16px",
  13. lg: "24px",
  14. };
  15. const alignments: Record<string, string> = {
  16. start: "flex-start",
  17. center: "center",
  18. end: "flex-end",
  19. stretch: "stretch",
  20. };
  21. return (
  22. <div
  23. style={{
  24. display: "flex",
  25. flexDirection: direction === "horizontal" ? "row" : "column",
  26. gap: gaps[gap || "md"],
  27. alignItems: alignments[align || "stretch"],
  28. }}
  29. >
  30. {children}
  31. </div>
  32. );
  33. }