2026-06-17 22:30:56 -06:00
|
|
|
<script lang="ts">
|
|
|
|
|
import type { Snippet } from 'svelte';
|
|
|
|
|
import Icon from '$lib/icons/Icon.svelte';
|
|
|
|
|
|
|
|
|
|
type Variant = 'primary' | 'secondary' | 'danger';
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
/** Visual style → `.btn-{variant}` (default `secondary`). */
|
|
|
|
|
variant?: Variant;
|
|
|
|
|
/** Optional leading icon-registry name. */
|
|
|
|
|
icon?: string;
|
|
|
|
|
/** Compact size → adds `.btn-sm`. */
|
|
|
|
|
small?: boolean;
|
|
|
|
|
type?: 'button' | 'submit' | 'reset';
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
title?: string;
|
|
|
|
|
onclick?: (e: MouseEvent) => void;
|
|
|
|
|
/** Extra classes appended after the base `.btn` classes. */
|
|
|
|
|
class?: string;
|
2026-06-21 20:03:32 -06:00
|
|
|
/** e2e test hook forwarded to the underlying `<button>`. */
|
|
|
|
|
'data-testid'?: string;
|
2026-06-17 22:30:56 -06:00
|
|
|
children?: Snippet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
variant = 'secondary',
|
|
|
|
|
icon,
|
|
|
|
|
small = false,
|
|
|
|
|
type = 'button',
|
|
|
|
|
disabled = false,
|
|
|
|
|
title,
|
|
|
|
|
onclick,
|
|
|
|
|
class: cls = '',
|
2026-06-21 20:03:32 -06:00
|
|
|
'data-testid': testid,
|
2026-06-17 22:30:56 -06:00
|
|
|
children
|
|
|
|
|
}: Props = $props();
|
|
|
|
|
|
|
|
|
|
const className = $derived(
|
|
|
|
|
['btn', `btn-${variant}`, small ? 'btn-sm' : '', cls].filter(Boolean).join(' ')
|
|
|
|
|
);
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-06-21 20:03:32 -06:00
|
|
|
<button class={className} {type} {disabled} {title} data-testid={testid} {onclick}>
|
2026-06-17 22:30:56 -06:00
|
|
|
{#if icon}<Icon name={icon} />{/if}
|
|
|
|
|
{@render children?.()}
|
|
|
|
|
</button>
|