Stack.svelte 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <script lang="ts">
  2. import type { Snippet } from "svelte";
  3. import type { BaseComponentProps } from "@json-render/svelte";
  4. import type { ShadcnProps } from "./catalog.js";
  5. interface Props extends BaseComponentProps<ShadcnProps<"Stack">> {
  6. children?: Snippet;
  7. }
  8. let { props, children }: Props = $props();
  9. const gapMap: Record<string, string> = {
  10. none: "gap-0",
  11. sm: "gap-2",
  12. md: "gap-3",
  13. lg: "gap-4",
  14. };
  15. const alignMap: Record<string, string> = {
  16. start: "items-start",
  17. center: "items-center",
  18. end: "items-end",
  19. stretch: "items-stretch",
  20. };
  21. const justifyMap: Record<string, string> = {
  22. start: "",
  23. center: "justify-center",
  24. end: "justify-end",
  25. between: "justify-between",
  26. around: "justify-around",
  27. };
  28. </script>
  29. <div
  30. class={`flex ${props.direction === "horizontal" ? "flex-row flex-wrap" : "flex-col"} ${gapMap[props.gap ?? "md"] ?? "gap-3"} ${alignMap[props.align ?? "start"] ?? "items-start"} ${justifyMap[props.justify ?? "start"] ?? ""}`}
  31. >
  32. {@render children?.()}
  33. </div>