From 6927d7906d041440b652f91187ec3c134ededdfe Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sat, 9 Nov 2024 20:43:06 +0800 Subject: [PATCH] update badge/button/separator/skeleton component to svelte 5 --- .../src/lib/components/ui/badge/badge.svelte | 48 +++++++-- frontend/src/lib/components/ui/badge/index.ts | 22 +---- .../lib/components/ui/button/button.svelte | 97 +++++++++++++++---- .../src/lib/components/ui/button/index.ts | 58 +++-------- .../components/ui/separator/separator.svelte | 29 +++--- .../components/ui/skeleton/skeleton.svelte | 18 ++-- 6 files changed, 155 insertions(+), 117 deletions(-) diff --git a/frontend/src/lib/components/ui/badge/badge.svelte b/frontend/src/lib/components/ui/badge/badge.svelte index 58ec3b0..9c7457a 100644 --- a/frontend/src/lib/components/ui/badge/badge.svelte +++ b/frontend/src/lib/components/ui/badge/badge.svelte @@ -1,18 +1,50 @@ + + - + {@render children?.()} diff --git a/frontend/src/lib/components/ui/badge/index.ts b/frontend/src/lib/components/ui/badge/index.ts index 2824b56..64e0aa9 100644 --- a/frontend/src/lib/components/ui/badge/index.ts +++ b/frontend/src/lib/components/ui/badge/index.ts @@ -1,22 +1,2 @@ -import { tv, type VariantProps } from "tailwind-variants"; export { default as Badge } from "./badge.svelte"; - -export const badgeVariants = tv({ - base: "inline-flex items-center border rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none select-none focus:ring-2 focus:ring-ring focus:ring-offset-2", - variants: { - variant: { - default: - "bg-primary hover:bg-primary/80 border-transparent text-primary-foreground", - secondary: - "bg-secondary hover:bg-secondary/80 border-transparent text-secondary-foreground", - destructive: - "bg-destructive hover:bg-destructive/80 border-transparent text-destructive-foreground", - outline: "text-foreground" - } - }, - defaultVariants: { - variant: "default" - } -}); - -export type Variant = VariantProps["variant"]; +export { badgeVariants, type BadgeVariant } from "./badge.svelte"; diff --git a/frontend/src/lib/components/ui/button/button.svelte b/frontend/src/lib/components/ui/button/button.svelte index d7267f8..a344974 100644 --- a/frontend/src/lib/components/ui/button/button.svelte +++ b/frontend/src/lib/components/ui/button/button.svelte @@ -1,24 +1,81 @@ - + + - - - +{#if href} + + {@render children?.()} + +{:else} + +{/if} diff --git a/frontend/src/lib/components/ui/button/index.ts b/frontend/src/lib/components/ui/button/index.ts index da58cec..fb585d7 100644 --- a/frontend/src/lib/components/ui/button/index.ts +++ b/frontend/src/lib/components/ui/button/index.ts @@ -1,53 +1,17 @@ -import Root from './button.svelte' -import { tv, type VariantProps } from 'tailwind-variants' -import type { Button as ButtonPrimitive } from 'bits-ui' - -const buttonVariants = tv({ - base: 'inline-flex items-center justify-center rounded-md text-sm font-medium whitespace-nowrap ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 flex gap-2', - variants: { - variant: { - default: - 'bg-primary-foreground text-primary hover:bg-primary-foreground/70', - brand: 'bg-brand text-brand-foreground hover:bg-brand/80', - destructive: - 'bg-destructive text-destructive-foreground hover:bg-destructive/90', - outline: - 'border border-input bg-background hover:bg-accent hover:text-accent-foreground', - secondary: - 'bg-secondary text-secondary-foreground hover:bg-secondary/80', - ghost: 'hover:bg-accent hover:text-accent-foreground', - link: 'text-primary underline-offset-4 hover:underline', - }, - size: { - default: 'h-10 px-4 py-2', - sm: 'h-9 rounded-md px-3', - lg: 'h-11 rounded-md px-8', - icon: 'h-10 w-10', - }, - }, - defaultVariants: { - variant: 'default', - size: 'default', - }, -}) - -type Variant = VariantProps['variant'] -type Size = VariantProps['size'] - -type Props = ButtonPrimitive.Props & { - variant?: Variant - size?: Size -} - -type Events = ButtonPrimitive.Events +import Root, { + type ButtonProps, + type ButtonSize, + type ButtonVariant, + buttonVariants, +} from "./button.svelte"; export { Root, - type Props, - type Events, + type ButtonProps as Props, // Root as Button, - type Props as ButtonProps, - type Events as ButtonEvents, buttonVariants, -} + type ButtonProps, + type ButtonSize, + type ButtonVariant, +}; diff --git a/frontend/src/lib/components/ui/separator/separator.svelte b/frontend/src/lib/components/ui/separator/separator.svelte index 4d27138..839494d 100644 --- a/frontend/src/lib/components/ui/separator/separator.svelte +++ b/frontend/src/lib/components/ui/separator/separator.svelte @@ -1,23 +1,22 @@ + {...restProps} +/> diff --git a/frontend/src/lib/components/ui/skeleton/skeleton.svelte b/frontend/src/lib/components/ui/skeleton/skeleton.svelte index 09fb7cd..4089b49 100644 --- a/frontend/src/lib/components/ui/skeleton/skeleton.svelte +++ b/frontend/src/lib/components/ui/skeleton/skeleton.svelte @@ -1,11 +1,17 @@ -
+