Files
Oxicloud/frontend/src/lib/components/Button.svelte
T

47 lines
1.1 KiB
Svelte
Raw Normal View History

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;
/** 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 = '',
'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>
<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>