mirror of
https://github.com/Blah-IM/Weblah.git
synced 2025-05-01 00:31:08 +00:00
fix: Button component typing and add background style
Add proper TypeScript discriminated union type to ensure correct HTML attributes based on whether the component renders as a button or anchor. Also add bg-sb-primary class to the component's base styles.
This commit is contained in:
parent
35315ca5f3
commit
a1f0e4d4bd
1 changed files with 13 additions and 12 deletions
|
@ -1,28 +1,29 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tw } from '$lib/tw';
|
import { tw } from '$lib/tw';
|
||||||
|
import type { HTMLAttributes } from 'svelte/elements';
|
||||||
|
|
||||||
interface Props {
|
type Props = {
|
||||||
variant?: 'primary' | 'secondary';
|
variant?: 'primary' | 'secondary';
|
||||||
class?: string | null;
|
class?: string;
|
||||||
href?: string | null;
|
|
||||||
children?: import('svelte').Snippet;
|
children?: import('svelte').Snippet;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
} & (
|
||||||
|
| ({
|
||||||
|
href: string;
|
||||||
|
} & HTMLAttributes<HTMLAnchorElement>)
|
||||||
|
| ({
|
||||||
|
href?: undefined;
|
||||||
|
} & HTMLAttributes<HTMLButtonElement>)
|
||||||
|
);
|
||||||
|
|
||||||
let {
|
let { variant = 'secondary', class: className = '', href, children, ...rest }: Props = $props();
|
||||||
variant = 'secondary',
|
|
||||||
class: className = '',
|
|
||||||
href = null,
|
|
||||||
children,
|
|
||||||
...rest
|
|
||||||
}: Props = $props();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={href ? 'a' : 'button'}
|
this={href ? 'a' : 'button'}
|
||||||
{href}
|
{href}
|
||||||
class={tw(
|
class={tw(
|
||||||
'text-sf-secondary ring-ss-secondary inline-flex cursor-default items-center justify-center rounded-md px-2.5 py-1 shadow-xs ring-1',
|
'text-sf-secondary bg-sb-primary ring-ss-secondary inline-flex cursor-default items-center justify-center rounded-md px-2.5 py-1 shadow-xs ring-1',
|
||||||
'hover:ring-ss-primary font-normal transition-shadow duration-200 active:shadow-inner',
|
'hover:ring-ss-primary font-normal transition-shadow duration-200 active:shadow-inner',
|
||||||
variant === 'primary' && [
|
variant === 'primary' && [
|
||||||
'relative text-slate-50 ring-0 duration-200',
|
'relative text-slate-50 ring-0 duration-200',
|
||||||
|
|
Loading…
Add table
Reference in a new issue