Card.svelte 1.1 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. import * as Card from "./ui/card/index.js";
  6. import { cn } from "./lib/utils.js";
  7. interface Props extends BaseComponentProps<ShadcnProps<"Card">> {
  8. children?: Snippet;
  9. }
  10. let { props, children }: Props = $props();
  11. const maxWidthClass = $derived(
  12. props.maxWidth === "sm"
  13. ? "max-w-xs sm:min-w-[280px]"
  14. : props.maxWidth === "md"
  15. ? "max-w-sm sm:min-w-[320px]"
  16. : props.maxWidth === "lg"
  17. ? "max-w-md sm:min-w-[360px]"
  18. : "w-full",
  19. );
  20. </script>
  21. <Card.Root class={cn(maxWidthClass, props.centered ? "mx-auto" : "") }>
  22. {#if props.title || props.description}
  23. <Card.Header>
  24. {#if props.title}
  25. <Card.Title>{props.title}</Card.Title>
  26. {/if}
  27. {#if props.description}
  28. <Card.Description>{props.description}</Card.Description>
  29. {/if}
  30. </Card.Header>
  31. {/if}
  32. <Card.Content class="flex flex-col gap-3">
  33. {@render children?.()}
  34. </Card.Content>
  35. </Card.Root>