~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0
125 lines · 2.7 KB Raw History
<script lang="ts">
	import type { Snippet } from 'svelte';
	import Icon, { type IconName } from './Icon.svelte';

	// A button: `primary` for the one that goes on, `quiet` for the rest,
	// `row` for one that is a whole line of a list, `link` for a way out that
	// reads as text. `wide` takes the whole line. With `children`, `label`
	// is its accessible name; without, its text.
	let {
		label,
		kind = 'quiet',
		type = 'button',
		form,
		icon,
		wide = false,
		busy = false,
		disabled = false,
		onclick,
		children
	}: {
		label: string;
		kind?: 'primary' | 'quiet' | 'row' | 'link';
		type?: 'button' | 'submit';
		form?: string;
		icon?: IconName;
		wide?: boolean;
		busy?: boolean;
		disabled?: boolean;
		onclick?: () => void;
		children?: Snippet;
	} = $props();
</script>

<button
	class="button"
	class:primary={kind === 'primary'}
	class:row={kind === 'row'}
	class:link={kind === 'link'}
	class:wide
	{type}
	{form}
	{disabled}
	{onclick}
	aria-busy={busy ? 'true' : undefined}
	aria-label={children ? label : undefined}
	data-primary={kind === 'primary' ? '' : undefined}
	>{#if icon}<Icon name={icon} />{/if}{#if children}{@render children()}{:else}<span>{label}</span>{/if}</button
>

<style>
	.button {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: var(--space-2);
		min-height: var(--control-height);
		padding: 0 var(--space-4);
		border: var(--border) solid var(--line);
		border-radius: var(--radius-md);
		background: var(--bg);
		color: var(--fg);
		font-family: var(--font-mono);
		font-size: var(--text-sm);
		font-weight: var(--weight-medium);
		letter-spacing: var(--tracking-mono);
		line-height: var(--leading-tight);
		cursor: pointer;
	}

	.button:hover:not(:disabled) {
		background: var(--hover);
	}

	.primary {
		border-color: var(--primary);
		background: var(--primary);
		color: var(--on-primary);
	}

	.primary:hover:not(:disabled) {
		border-color: var(--primary-hover);
		background: var(--primary-hover);
	}

	.row {
		width: 100%;
		justify-content: space-between;
		gap: var(--space-3);
		padding: var(--space-2-5) var(--space-3);
		text-align: start;
		font-family: var(--font-sans);
		font-size: var(--text-base);
		font-weight: var(--weight-normal);
		letter-spacing: normal;
	}

	.wide {
		width: 100%;
	}

	.link {
		min-height: auto;
		padding: var(--space-1) 0;
		border-color: transparent;
		background: none;
		color: var(--mute);
		font-family: var(--font-sans);
		text-decoration: underline;
		text-underline-offset: var(--space-1);
	}

	.link:hover:not(:disabled) {
		background: none;
		color: var(--fg);
	}

	.button:disabled {
		cursor: not-allowed;
		opacity: var(--disabled);
	}

	.button[aria-busy='true'] {
		cursor: progress;
	}
</style>