2024-10-24 17:11:01 +00:00
|
|
|
<script lang="ts">
|
2025-02-04 01:21:46 +00:00
|
|
|
import type {Snippet} from "svelte"
|
2024-10-24 17:11:01 +00:00
|
|
|
|
2026-06-24 20:56:53 +00:00
|
|
|
// Button is BEHAVIOR only: it renders a <button>, swallows the default
|
|
|
|
|
// event/propagation, and forwards everything else. Styling is supplied by the
|
|
|
|
|
// caller as classes (`class="button button-primary"`), so the same `button*` styles in
|
|
|
|
|
// common.css can be applied to <a> (via Link), <span>, etc. without a prop API.
|
2025-02-04 01:21:46 +00:00
|
|
|
const {
|
|
|
|
|
children,
|
|
|
|
|
onclick,
|
|
|
|
|
type = "button",
|
|
|
|
|
...restProps
|
|
|
|
|
}: {
|
|
|
|
|
children: Snippet
|
2025-02-05 21:02:51 +00:00
|
|
|
onclick?: (event: Event) => any
|
2025-02-04 01:21:46 +00:00
|
|
|
type?: "button" | "submit"
|
|
|
|
|
class?: string
|
|
|
|
|
style?: string
|
|
|
|
|
disabled?: boolean
|
|
|
|
|
"data-tip"?: string
|
2026-06-24 20:10:06 +00:00
|
|
|
"aria-label"?: string
|
2026-04-08 17:10:20 +00:00
|
|
|
"aria-pressed"?: boolean
|
2025-02-04 01:21:46 +00:00
|
|
|
} = $props()
|
2025-02-04 00:37:14 +00:00
|
|
|
|
2025-02-04 01:21:46 +00:00
|
|
|
const onClick = (e: Event) => {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
|
2025-02-05 21:02:51 +00:00
|
|
|
onclick?.(e)
|
2025-02-04 01:21:46 +00:00
|
|
|
}
|
2024-10-24 17:11:01 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-10-24 19:50:49 +00:00
|
|
|
{#if type === "submit"}
|
2026-06-24 20:56:53 +00:00
|
|
|
<button {...restProps} {type}>
|
2025-02-04 01:21:46 +00:00
|
|
|
{@render children?.()}
|
2024-10-24 17:11:01 +00:00
|
|
|
</button>
|
|
|
|
|
{:else}
|
2026-06-24 20:56:53 +00:00
|
|
|
<button {...restProps} onclick={onClick} type="button">
|
2025-02-04 01:21:46 +00:00
|
|
|
{@render children?.()}
|
2024-10-24 17:11:01 +00:00
|
|
|
</button>
|
|
|
|
|
{/if}
|