# Components

Usage rules for the core components: button, input, select, table, badge, card, modal, toast, tabs, and nav.

HTML page: https://developer.mpalo.com/components
Markdown page: https://developer.mpalo.com/components.md

## Navigate sections

- [How to use a component](components#usage)
- [Button](components#button)
- [Input](components#input)
- [Select](components#select)
- [Table](components#table)
- [Badge](components#badge)
- [Card](components#card)
- [Modal](components#modal)
- [Toast](components#toast)
- [Tabs](components#tabs)
- [Navigation](components#nav)
- [Enforcement](components#enforcement)

## How to use a component

Scope: every shared component on every Mpalo surface.

**Rule.** Use the shared component and its tokens. Do not restyle it in the page. A page chooses the surface step its component sits on; the component derives its fill, hover, and selected states from that step.

A component takes `on` or `level`, the surface step of its container. The component fill is `on + 1`, hover is `on + 2`, and selected is `on + 2`. A card on a page is step 2; a button on that card is step 3; hover is step 4. The component never hard-codes a level.

**Do:** copy the shared markup and let the tokens do the work. **Do not:** add a page-level background, border, radius, shadow, font size, or hover state to a shared component.

## Button

One action, one consequence, one label.

- **When to use**: When the person is committing an action: create, save, revoke, submit, confirm. Use a quiet text action inside a row when the action should not compete with the primary action.

- **Anatomy**: Label, optional leading icon, optional pending indicator. The label is always visible. The button keeps its padding and its place in the layout when a pending state starts.

- **Variants**: `.btn` neutral, `.btn-primary` the main action, `.btn-success` confirm or enable, `.btn-warning` the action inside a caution banner, `.btn-danger` destructive, `.btn-quiet` secondary text action, `.btn-quiet-danger` destructive text action.

- **States**: Rest is the surface step above the container. Hover is one step above rest. Focus is a 2px outline at 2px offset. Disabled is the resting fill with muted text and a not-allowed cursor. Pending keeps the label, disables pointer events, and shows a compact progress ring.

- **Tokens**: `--surface-N` for the fill, `--accent` and `--on-accent` for primary, the semantic fill and on-color pair for success, warning, and danger, `--radius` for the corner, `--focus` for the ring, and the linear duration tokens for hover.

- **Accessibility**: The label is the accessible name. An icon-only button needs an `aria-label`. A pending button keeps its name and reports the pending state; do not replace the label with a spinner alone. A destructive button names the real operation, not "delete" when the operation is revocation.

- **Do not**: Do not center a wrapped label. Both lines start at the same left edge. Do not shrink the type or truncate the label to keep it on one line. Do not use a hollow red outline for a destructive action. Do not use a transparent button on the same surface as its container.

Variants and sizes  Neutral Primary Success Warning Danger Disabled Small Large

| Do | Do not |
| --- | --- |
| Use one primary action per view. | Make two buttons primary and let the person guess. |
| Write the operation: "Revoke API key". | Write "Delete" when the operation is revocation. |
| Call `window.mpaloPending.run(button, fn)` for an async action. | Leave the button looking idle while the request runs. |

## Input

A field is a question. The label says what the answer is for.

- **When to use**: When the person must supply a value that the system cannot infer. Use a select when the valid values are known and finite. Use a textarea when the answer is longer than one line.

- **Anatomy**: Visible label, the field, optional hint, optional error sentence. The error sits next to the field it belongs to. Required state is stated in text, not only with an asterisk.

- **States**: Rest is card +1. Hover is one step up. Focus is a 2px outline with a 0 offset. Error is a red outline plus a sentence that says how to correct it. Disabled is the resting fill with muted text; it is not the only explanation for why an action is unavailable.

- **Tokens**: `--surface-N` for the fill, `--text-1` for the value, `--text-muted` for the placeholder, `--red` for the error outline, `--focus` for the focus ring, and `--radius` for the corner.

- **Accessibility**: Every field has a visible label or an accessible name that matches the visible label. The hint and error are programmatically associated with the field. The error is announced. Placeholder text never replaces a label.

- **Do not**: Do not use a placeholder as the only label. Do not use color alone for an error. Do not use a disabled field to explain a permission the interface could state. Do not add a translucent fill or a border.

Default, focus, error, disabled

## Select

A select is a list of valid answers, not a menu of actions.

- **When to use**: When the person chooses one value from a known, finite set. Use a radio group when the options need explanation or when there are fewer than four. Use a menu when the control performs an action rather than choosing a value.

- **Anatomy**: Visible label, a real `select` element, real `option` elements, and a chevron that shows the open state.

- **States**: Rest and hover follow the field. Open rotates the chevron 180 degrees. The selected option is the value in the closed trigger. Disabled uses the field's disabled state.

- **Tokens**: The field tokens, `--surface-N` and `--text-1`. The popup is a solid surface two steps above the page with `--shadow-overlay`. It never inherits the operating system menu styling on a product surface.

- **Accessibility**: The real `select` stays in the DOM with its `id`, `name`, `value`, and events. The visual panel is an enhancement, not a replacement. The control has a visible label and a name that matches it. Keyboard operation follows the native select model.

- **Do not**: Do not build a custom dropdown from divs. Do not use a select for navigation or for a destructive action. Do not ship a bare native popup on the Mind Platform; the shared enhancer is mandatory there.

A real select with real options   All memories Episodic only

## Table

A table is a set of records with the same fields. It is not a layout tool.

- **When to use**: When several records share the same fields and the person needs to compare them. Use a definition list for one record. Use cards when each record has a different shape.

- **Anatomy**: Caption, header row with column names, body rows. A sortable header is a button. A row action sits in a cell with its own accessible name.

- **States**: Rows are solid bars at container +1, 1px apart. Hover is +1. The selected row is +2. The header is muted text with no fill. A sorted column states its direction in text and with `aria-sort`.

- **Tokens**: `--surface-N` for rows and hover, `--text-1` for values, `--text-muted` for headers, `--gap-within` and `--gap-between` for spacing, and the mono face for identifiers.

- **Accessibility**: A table has a caption and column headers. A sortable header exposes its sort state. A scroll container is keyboard reachable. The table never depends on color to distinguish a row.

- **Do not**: Do not fake responsive tables with `transform: scale()` and a wider width; that creates phantom horizontal scrolling. Do not put a tooltip in a cell where an SVG in the same cell can paint over it. Do not use a table for page layout.

Solid rows, 1px apart, muted header

| Name | Key | Status | Calls |
| --- | --- | --- | --- |
| Production | `mp_live_4f...a2` | Active | 18,204 |
| Staging | `mp_test_91...c7` | Active | 2,310 |
| Old laptop | `mp_live_0b...19` | Revoked | 0 |

## Badge

A badge states a condition. It is not a button and not a decoration.

- **When to use**: For a short status attached to a record: Active, Revoked, Pending, Private, Low. Use a chip when the value is a token the person can remove. Use plain text when no visual status is needed.

- **Anatomy**: One short word in a solid tone fill with its on-color text. The label sits slightly above center. No icon is required; if one is used it does not replace the word.

- **States**: Static. The tone carries meaning only with the word. A status change replaces the badge, not its color alone.

- **Tokens**: The semantic fill and on-color pair: `--green` and `--on-green`, `--yellow` and `--on-yellow`, `--orange` and `--on-orange`, `--red` and `--on-red`, `--purple` and `--on-purple`, `--blue` and `--on-blue`, plus `--radius`.

- **Accessibility**: The word is the status. Color is a second signal, never the only one. The badge is not focusable and has no click behavior.

- **Do not**: Do not use a pill. Do not use a left-border accent or a tint. Do not use a badge as a button. Do not rely on green alone to mean active.

Status badges  Accent Active Low Pending Revoked Private Info

## Card

A card groups one subject. It is not a container for a page.

- **When to use**: When one record, one setting, or one action group needs its own solid surface. Use a section when the content is part of the page's main argument. Use a card for a discrete object the person can scan or act on.

- **Anatomy**: Optional title, body, optional action row. The card has no border and no shadow. Its fill is its container's step +1.

- **States**: Rest is container +1. Hover, when the whole card is a link, is +1. Selected is +2. A card does not transform, glow, scale, or shimmer.

- **Tokens**: `--surface-N` for the fill, `--radius` for the corner, `--gap-within` and `--gap-between` for internal and external spacing. No shadow token.

- **Accessibility**: If the whole card is a link, the link has a name that describes the destination. Do not nest a second interactive control inside a card link. Focus is visible on the card or on its action.

- **Do not**: Do not add a border, a shadow, or a tint. Do not nest a card inside a card to create hierarchy; use a step of space instead. Do not put a marketing footer inside a card.

A card at step 2, with a neutral button on step 3

### Production key

Requests authenticated with this key use the hosted reference path.

Rotate key

## Modal

A modal interrupts the page. Use it only when the decision cannot wait.

- **When to use**: For a decision that must be completed before the page continues: a consequential confirmation, a focused form, or a search dialog. Use a toast for a result that does not need a decision. Use an inline panel when the content can sit in the page.

- **Anatomy**: Scrim, panel at the surface beneath +2, a title, the content, and the actions. The close control is always present. The panel carries `--shadow-overlay` and `--radius`.

- **States**: Open, closing, and focus-trapped. Escape closes the topmost overlay. A scrim click closes it when the content is dismissible. Focus returns to the control that opened it.

- **Tokens**: `--surface-N` for the panel, `--shadow-overlay` for the only shadow, `--radius` for the corner, and the scrim token for the one full-page translucent layer.

- **Accessibility**: The dialog has `role="dialog"`, `aria-modal="true"`, and a name from its title. Focus enters the panel and is trapped there until it closes. Background content is inert. Escape closes it. The close control has an accessible name.

- **Do not**: Do not use a modal for a routine success message. Do not open a modal from a modal. Do not remove the close control. Do not use a border or a second shadow.

## Toast

A toast reports a result that does not require a decision.

- **When to use**: After a completed action whose outcome the person should know: saved, copied, sent, failed. Use an inline status when the message belongs to a field or a section. Use a modal when the person must decide.

- **Anatomy**: Tone square, a short title, and at most one sentence. The panel sits at the surface beneath +2 with `--shadow-overlay`. The tone square is a solid 8px shape, not a tint.

- **States**: Enter, visible, and exit. The toast does not take focus. It remains long enough to read. A destructive consequence is never delivered only by a toast.

- **Tokens**: The semantic fill for the tone square, `--surface-N` for the panel, `--shadow-overlay`, and `--radius`.

- **Accessibility**: The toast is an `aria-live` status or alert region. It does not steal focus. The text states what happened, not "Success". A toast that disappears automatically still leaves the state visible on the page.

- **Do not**: Do not use a toast for an error the person must correct. Do not stack more than one. Do not use a tint, a border, or a left-border accent.

A toast with a solid tone square    Key created

Copy it now. You will not see it again.

## Tabs

Tabs switch between views of the same subject. They do not sequence a task.

- **When to use**: When two or more views belong to one subject and the person needs to move between them without leaving the page. Use links for navigation between pages. Use a stepped form for a sequence that must be completed in order.

- **Anatomy**: A tab list, a tab for each view, and one panel. The active tab has a 2px accent bar below its label. The label is text, not a filled tab.

- **States**: Inactive is muted text. Hover is full text. Active is full text with the accent bar. Focus is the 2px focus ring. Disabled is muted and not focusable.

- **Tokens**: `--text-1` and `--text-muted` for labels, `--accent` for the bar, `--focus` for the ring, and the linear duration for the state change.

- **Accessibility**: Use the tab pattern: `role="tablist"`, `role="tab"`, `role="tabpanel"`, `aria-selected`, and arrow-key movement between tabs. The panel is associated with its tab. A tab does not navigate to another URL unless it is a link.

- **Do not**: Do not use tabs for a multi-step form. Do not fill the active tab with a background. Do not use tabs when the content is long enough that the person will lose the tab list while reading.

Separated text with an accent bar  Overview Usage Billing

## Navigation

Navigation tells the person where they are and what they can reach next.

- **When to use**: A top bar for the shell and the primary destinations. A sidebar for a documentation set with many pages. A right rail for the sections of the current page. Use breadcrumbs only when the hierarchy is deeper than two levels.

- **Anatomy**: Brand, primary links, and at most two utility actions in the top bar. Group headings in the sidebar are interface text, not display text. The current page carries `aria-current="page"`. The right rail lists the named sections of the current page.

- **States**: Rest is the page step. Hover is +1. Current is +2. The current state is a solid fill or an underline on the label, never a border or a glow. External links carry an external-link glyph and an accessible name.

- **Tokens**: `--surface-N` for the shell and the selected item, `--text-1` and `--text-muted` for labels, `--focus` for the ring, and `--gap-within` for icon and label spacing.

- **Accessibility**: The page starts with a skip link to `#main-content`. Each navigation region has a name. The mobile menu is a modal-like overlay with focus management. The current page is exposed with `aria-current`. Nav labels remain visible; an icon never replaces the label.

- **Do not**: Do not add a marketing footer to the developer shell. Do not put a page's table of contents in the left sidebar. Do not use an icon-only navigation item without an accessible name. Do not make the current item look like a primary button.

**Why.** Navigation is the map of the system. When two regions claim the same job, the reader stops trusting either one.

## Enforcement

The component rules are checked in review and by the design checks.

- Confirm the component is the shared class and not a local copy.
- Confirm the surface step and the hover step are correct.
- Tab to the control and confirm focus is visible.
- Check the accessible name, state, and error association.
- Run `npm run check:design-rules` and `npm run check:design-runtime`.
- For a new component, add its rule here and its styles to `components.css`. Do not add a specimen-only class.

**Owner:** the Design owner for the shared component; the surface owner for its use. **Review:** before a component or a new usage pattern ships.

## Related pages

- [Elements](elements.md)
- [Accessibility](accessibility.md)
- [Design system](design.md)

## Authoritative integration reference

- [API quickstart](https://api.mpalo.com/get-started)
- [API reference](https://api.mpalo.com/landing)
