Button.svelte 738 B

12345678910111213141516171819202122
  1. <script lang="ts">
  2. import type { BaseComponentProps } from "@json-render/svelte";
  3. import type { ShadcnProps } from "./catalog.js";
  4. import { Button } from "./ui/button/index.js";
  5. interface Props extends BaseComponentProps<ShadcnProps<"Button">> {}
  6. let { props, emit }: Props = $props();
  7. const rawVariant = $derived((props.variant ?? "primary") as string);
  8. const variant = $derived(
  9. rawVariant === "danger" || rawVariant === "destructive"
  10. ? "destructive"
  11. : rawVariant === "secondary" || rawVariant === "outline" || rawVariant === "ghost"
  12. ? "secondary"
  13. : "default",
  14. );
  15. </script>
  16. <Button {variant} disabled={props.disabled ?? false} onclick={() => emit("press")}>
  17. {props.label}
  18. </Button>