[web] Domi UI: the web UI on @domi/ui v1.0.0 (fonts, roles, Button, TextField with seals, Checkbox, Select, Segmented)
This commit is contained in:
@@ -3,11 +3,17 @@
|
||||
- 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";
|
||||
|
||||
// Handoff §2.1: disabled is aria-disabled (it stays focusable and its reason is read through
|
||||
// aria-describedby); pending keeps the label, adds a spinner and ignores clicks.
|
||||
// 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,
|
||||
@@ -22,7 +28,7 @@
|
||||
children,
|
||||
...rest
|
||||
}: {
|
||||
variant?: "primary" | "quiet" | "outline" | "danger" | "link";
|
||||
variant?: "primary" | "quiet" | "outline" | "danger";
|
||||
icon?: IconName;
|
||||
disabled?: boolean;
|
||||
pending?: boolean;
|
||||
@@ -31,32 +37,28 @@
|
||||
small?: boolean;
|
||||
full?: boolean;
|
||||
type?: "button" | "submit";
|
||||
onclick?: (e: MouseEvent) => void;
|
||||
onclick?: (e: MouseEvent) => unknown;
|
||||
children?: Snippet;
|
||||
[key: string]: unknown;
|
||||
} = $props();
|
||||
|
||||
function click(e: MouseEvent) {
|
||||
if (disabled || pending) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
onclick?.(e);
|
||||
}
|
||||
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>
|
||||
|
||||
<button
|
||||
{type}
|
||||
class="domi-btn {variant === 'quiet' ? '' : variant}"
|
||||
class:small
|
||||
class:full
|
||||
aria-disabled={disabled || pending ? "true" : undefined}
|
||||
aria-busy={pending ? "true" : undefined}
|
||||
aria-describedby={describedby}
|
||||
aria-label={label}
|
||||
onclick={click}
|
||||
<DomiButton
|
||||
{...rest}
|
||||
variant={domiVariant}
|
||||
{size}
|
||||
{type}
|
||||
block={full}
|
||||
{disabled}
|
||||
status={pending ? "loading" : undefined}
|
||||
aria-describedby={describedby}
|
||||
aria-labelledby={label ? nameId : undefined}
|
||||
{onclick}
|
||||
>
|
||||
{#if pending}<span class="spin" aria-hidden="true"></span>{:else if icon}<Icon name={icon} />{/if}
|
||||
{@render children?.()}
|
||||
</button>
|
||||
{#if icon}<Icon name={icon} />{/if}{@render children?.()}{#if label}<span id={nameId} hidden>{label}</span>{/if}
|
||||
</DomiButton>
|
||||
|
||||
Reference in New Issue
Block a user