flotilla/src/lib/components/Button.svelte

38 lines
775 B
Svelte
Raw Normal View History

2024-10-24 17:11:01 +00:00
<script lang="ts">
import type {Snippet} from "svelte"
2024-10-24 17:11:01 +00:00
const {
children,
onclick,
type = "button",
...restProps
}: {
children: Snippet
onclick?: (...args: unknown[]) => any
type?: "button" | "submit"
class?: string
style?: string
disabled?: boolean
"data-tip"?: string
} = $props()
2025-02-04 00:37:14 +00:00
const className = $derived(`text-left ${restProps.class}`)
const onClick = (e: Event) => {
e.preventDefault()
e.stopPropagation()
onclick?.()
}
2024-10-24 17:11:01 +00:00
</script>
{#if type === "submit"}
2025-02-04 00:37:14 +00:00
<button {...restProps} {type} class={className}>
{@render children?.()}
2024-10-24 17:11:01 +00:00
</button>
{:else}
<button {...restProps} onclick={onClick} type={type as "button" | "submit"} class={className}>
{@render children?.()}
2024-10-24 17:11:01 +00:00
</button>
{/if}