native buttons and links
Loafkit styles native buttons. you donāt need a Button component for an ordinary action, and there isnāt a public Button export. use a button for an action and an anchor for a destination.
Browse components<script>
let saved = $state(false);
let saving = $state(false);
</script>
<button type="button" class:loaf-primary={!saved} class:loaf-success={saved} disabled={saving} onclick={async () => {
saving = true; saved = false;
await new Promise(resolve => setTimeout(resolve,400));
saved = true; saving = false;
}}>{saving ? 'savingā¦' : saved ? 'save again' : 'save collection'}</button>
<a class="loaf-button" href="/docs/foundations/choose-a-component/">Browse components</a>
{#if saved}<p role="status">collection saved in this demo.</p>{/if}inside a form, a button submits by default. give local actions type="button" and use type="submit" only for the formās submit action. add loaf-button to an anchor when it needs the shared button presentation.
emphasis and state
native buttons support loaf-primary, loaf-success, loaf-danger, loaf-warning, loaf-active and loaf-elevated. the status classes use semantic palette tokens; the primary class uses the accent. not every color class has an equivalent anchor selector, so donāt assume adding one to a link creates the same treatment.
use native disabled to disable a button. loaf-disabled is visual styling, not a replacement for disabled semantics or event handling. loaf-active is also a visual class; use the right state attribute such as aria-pressed when the action represents a persistent toggle.
color and focus
supported buttons and components set their text color to contrast their background.
- explicit
--loaf-text-on-accent,--loaf-text-on-success,--loaf-text-on-errorand--loaf-text-on-warningoverride that choice. - the fallback uses the Flavorās text color
shared styles provide focus-visible outlines. keep them visible when composing controls. Toggle, Selector and Switcher provide their own behavior when a plain button alone isnāt enough.