65 lines
2.2 KiB
Svelte
65 lines
2.2 KiB
Svelte
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
|
|
<script lang="ts">
|
|
import type { Snippet } from "svelte";
|
|
import { Button as DomiButton } from "@domi/ui";
|
|
import Icon from "./Icon.svelte";
|
|
import type { IconName } from "./icons";
|
|
|
|
// Ianitor's buttons are @domi/ui's Button (struck plate, leaf, states, 48 px on touch). This maps Ianitor's props
|
|
// onto it, so the sizes on a desktop stay as they were: an ordinary button 44 px (lg), the primary 50 px (xl),
|
|
// a small one 34 px (md). quiet and outline were both bordered buttons here; they are the plate now.
|
|
// pending the button shows its work (status loading); a second press does nothing
|
|
// disabled not pressable; say elsewhere why (describedby points at that text)
|
|
// label the accessible name when it says more than the words ("+ Host" is "Add a host")
|
|
// icon one of Ianitor's icons, before the words
|
|
let {
|
|
variant = "quiet",
|
|
icon,
|
|
disabled = false,
|
|
pending = false,
|
|
describedby,
|
|
label,
|
|
small = false,
|
|
full = false,
|
|
type = "button",
|
|
onclick,
|
|
children,
|
|
...rest
|
|
}: {
|
|
variant?: "primary" | "quiet" | "outline" | "danger";
|
|
icon?: IconName;
|
|
disabled?: boolean;
|
|
pending?: boolean;
|
|
describedby?: string;
|
|
label?: string;
|
|
small?: boolean;
|
|
full?: boolean;
|
|
type?: "button" | "submit";
|
|
onclick?: (e: MouseEvent) => unknown;
|
|
children?: Snippet;
|
|
[key: string]: unknown;
|
|
} = $props();
|
|
|
|
const uid = $props.id();
|
|
const nameId = `ia-btn-name-${uid}`;
|
|
const domiVariant = $derived(variant === "primary" ? "primary" : variant === "danger" ? "danger" : "plate");
|
|
const size = $derived(small ? "md" : variant === "primary" ? "xl" : "lg");
|
|
</script>
|
|
|
|
<DomiButton
|
|
{...rest}
|
|
variant={domiVariant}
|
|
{size}
|
|
{type}
|
|
block={full}
|
|
{disabled}
|
|
status={pending ? "loading" : undefined}
|
|
aria-describedby={describedby}
|
|
aria-labelledby={label ? nameId : undefined}
|
|
{onclick}
|
|
>
|
|
{#if icon}<Icon name={icon} />{/if}{@render children?.()}{#if label}<span id={nameId} hidden>{label}</span>{/if}
|
|
</DomiButton>
|