# Button

Supply UI 1.1.0. Actions and forms.

`variant`: `default` (soft grey), `primary`, `outline`, `ghost` (quieter: a lighter grey behind words, nothing behind an icon or inside another control), `danger`, `link`. `size`: `sm`, `md`, `lg`. `icon` (a circle) needs an `aria-label`

A button for an action. `variant="primary"` for the one main action of a view; `loading` while it is under way.

## Options

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `block` | `boolean` |  | Full width. |
| `children` | `ReactNode` |  | What goes inside. |
| `className` | `string` |  | More classes on the outer element, for layout around it (margins, grid placement), not to restyle it. |
| `icon` | `boolean` |  | Square button holding one icon. Give it an `aria-label`. |
| `loading` | `boolean` |  | Shows a spinner and cannot be pressed: while a save or a send is under way. |
| `size` | `"sm" \| "md" \| "lg"` |  | Its size, one step from the theme's Size: `sm`, `md` (default) or `lg`. |
| `variant` | `"link" \| "default" \| "primary" \| "outline" \| "ghost" \| "danger"` |  | `primary` for the one main action of a view; `default` (a soft fill) for the rest; `outline` and `ghost` are quieter still. |

It also takes the 292 attributes of the element or UI SDK part it renders (`className`, `aria-label`, events…).

## Without React

Classes: `ui-btn ui-btn--primary ui-btn--sm`

## CSS parts

With the CSS in parts (`/ui/css/`), it needs: `components/button.css`, `components/button-group-toggle.css`, `components/carousel-arrows.css`, besides the ones every page loads.

## In the examples

- Take your data with you: Tick a whole branch or a single leaf (https://www.supply.family/ui/#scene-export)
- Loading, politely: Grey shapes hold the place until the classes arrive (https://www.supply.family/ui/#scene-loading)
- Join in three steps: A plan, a name, a tick. Next stays off until each step is done. (https://www.supply.family/ui/#scene-checkout)
- Prove it is you: Six boxes, and the last digit checks the code (https://www.supply.family/ui/#scene-code)
- Sign it once sure: Every step lands on the timeline. Signing asks twice. (https://www.supply.family/ui/#scene-contract)
- Set up, one step at a time: Open a step, mark it done, watch the bar (https://www.supply.family/ui/#scene-setup)
- Add without leaving: A dialog takes the details; the list grows behind it (https://www.supply.family/ui/#scene-new-client)
- Out of ten: A low score opens a question, a high one says thanks (https://www.supply.family/ui/#scene-score)
- Fresh by seven: Reserve loaves the night before. The total keeps up. (https://www.supply.family/ui/#scene-bakery)
- Who still owes: Nudge a client and the row remembers (https://www.supply.family/ui/#scene-owing)
- An invoice that adds up: Change a quantity or a price; the lines and VAT follow (https://www.supply.family/ui/#scene-invoice-lines)
- Split the bill: Slide the tip, set the people, send the links (https://www.supply.family/ui/#scene-split-bill)
- Nothing to chase: An empty list says why it is empty (https://www.supply.family/ui/#scene-paid)
- The top of a website: Links in a row, panels of links under them (https://www.supply.family/ui/#scene-site-header)
- Where am I: Open folders; the trail above takes you back up (https://www.supply.family/ui/#scene-files)
- Jump anywhere with ⌘K: Pages and actions in one search (https://www.supply.family/ui/#scene-jump)
- Fit the badge: Drag and zoom the photo into the round frame (https://www.supply.family/ui/#scene-badge)
- Bill the minutes: Start, stop, and every stretch lands in the list (https://www.supply.family/ui/#scene-timer)
- Two weeks away: Tap the first day, then the last (https://www.supply.family/ui/#scene-time-off)
- A free morning for Biscuit: Days with room are marked. The times follow the day. (https://www.supply.family/ui/#scene-vet)
- Keep the streak: Minutes a day, and the run so far (https://www.supply.family/ui/#scene-streak)
- Vote, then see: Results stay hidden until you have picked (https://www.supply.family/ui/#scene-poll)
- Oat milk is on the list: Add a thing, tick it off at the shop (https://www.supply.family/ui/#scene-groceries)
- Share with a link: A popover with the switch and the link to copy (https://www.supply.family/ui/#scene-share)

## Actions and forms: notes

**States.** Every control has rest, hover, pressed, focus (a ring, from the keyboard only), disabled and, where it applies, chosen (`data-checked`, `aria-pressed`) and invalid (`aria-invalid`, with the message under the field). Each change of look fades with `--ui-dur-fast`.

**Do**
- Give every field a visible label (`Field label=…`); a placeholder is an example, never the label.
- Keep one primary button per view; deleting is `danger` and asks first with `AlertDialog`.
- Say what went wrong under the field, in words a person can act on ("Enter a full email address").
- Use `NumberInput`, `DatePicker`, `Select` and the rest rather than a bare `<input>`: they bring the keyboard, the screen-reader names and the phone layout.

**Don't**
- Don't disable a button to say a form is incomplete without saying why next to it.
- Don't put two primary buttons side by side, or a primary button inside a menu.
- Don't use a `Switch` for something that only happens when a form is sent: that is a `Checkbox`.
