> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Button

A quiet button with an optional icon on either side, exported from
`@fabiocv/ui/button`.

```tsx
import { Button } from '@fabiocv/ui/button';
import { ArrowLeft, ArrowRight, ArrowUpRight } from '@fabiocv/ui/icons';

<Button leadingIcon={<ArrowLeft />}>Back</Button>;
<Button trailingIcon={<ArrowRight />}>View work</Button>;
<Button>View work</Button>;
<Button leadingIcon={<ArrowLeft />} aria-label="Back" />;
<Button size="small">Latest projects</Button>;
<Button size="compact" href={url}>
  softle.app
</Button>;
<Button href="/work/">Work</Button>;
<Button
  href={resume}
  target="_blank"
  rel="noreferrer"
  trailingIcon={<ArrowUpRight />}
  trailingIconOnHover
>
  Résumé
</Button>;
```

- `size` is `default`, `small` or `compact`. A small button sets its label in
  `Text.Menu`, `14px` on a `20px` line, like a menu's items, and keeps the
  same box. A `Button` given to a `Menu` as its trigger takes the small size.
  A compact button keeps its label in a box `24px` tall, the height of the
  label's line, for a button in a line of text, such as an address.

- One line of body text in Regular and Foreground secondary, in a box `32px`
  tall, with `8px` corners and no ground of its own until it is hovered.
- Text sits `8px` from the edges. Icons come from `@fabiocv/ui/icons`:
  `24px`, drawn in their middle `16px`, in `currentColor`. Their `4px` of air
  counts toward the padding and gap beside them, so that `16px` area also sits
  `8px` from the edge and from the label. An icon-only button is a `32px`
  square.
- Hover paints Surface subtle behind it. The highlight comes in from where the
  pointer was a frame ago and leaves to where it will be a frame on, up to
  `8px`, so a slow pointer barely moves it. It fades in on the quick `TRACK`
  spring and out on `APPEAR`, and grows from a scale of `0.9` and back on
  `APPEAR`. Touch shows no highlight. With reduced motion it only fades. A press
  changes nothing while it is held.
- Focus shows `focusRing`: a `2px` outline in `currentColor`, inside the button's edge.
  The outline stays in place and a clip reveals it from its inner edge out, on
  a spring with a response of `0.4s` and a damping ratio of `1`. With reduced
  motion it appears at once.
- `trailingIconOnHover` reveals the trailing icon only while the button is
  hovered or holds keyboard focus. It is a mark, such as the arrow to another
  site, inked in its middle `8px`, so it sits `8px` from the label and about
  `9px` from the right edge, matching the label's first letter on the left.
  Hidden, it takes no room. Revealed, the button and its highlight grow by
  `17px` on the `SETTLE` spring, and the icon
  fades in on `APPEAR`, as a `Tag`'s does. With reduced motion it grows at once
  and the icon only fades. Without hover, as on touch, it always shows.
- `type` defaults to `button`. `disabled` stops the press. It turns the label and
  icons Foreground disabled, as in a toggle, with the default cursor, no highlight
  and no icon revealed on hover.
- With `href`, it renders an `<a>` that looks and moves the same. To one of the
  app's own pages it goes through [its router](https://ui.fabio.cv/router/index.md).
- There is one kind of button, with no filled or primary version.
  [Hierarchy](https://ui.fabio.cv/brand/index.md) comes from weight and ink.
- It takes a `ref` and pointer handlers alongside its hover highlight, so it
  can be another component's trigger, such as a menu's. While the popup it
  opened is open, it keeps the hover background, and the pointer crossing it
  changes nothing.

## Types of `@fabiocv/ui/button`

```ts
export type ButtonProps = {
    /** A 24px icon before the label. Give an icon-only button an `aria-label`. */
    leadingIcon?: ReactNode;
    /** A 24px icon after the label. */
    trailingIcon?: ReactNode;
    /**
     * Reveals the trailing icon only while the button is hovered or holds
     * keyboard focus. The button grows to make room for it.
     */
    trailingIconOnHover?: boolean;
    /**
     * `small` sets the label at 14px, as in a menu. A menu's trigger takes it.
     * `compact` keeps the label in a box as tall as its line.
     */
    size?: 'default' | 'small' | 'compact';
} & ((ComponentPropsWithRef<'button'> & {
    href?: undefined;
}) | (ComponentPropsWithRef<'a'> & {
    /** Renders a link that looks and moves like the button. */
    href: string;
}));

/**
 * Takes a ref and pointer handlers alongside its own hover highlight, so it
 * can be another component's trigger, such as a menu's.
 */
export declare function Button({ leadingIcon, trailingIcon, trailingIconOnHover, size, children, className, ref, onPointerEnter, onPointerLeave, ...props }: ButtonProps): import("react").JSX.Element;
```

## Examples

### Label

```tsx
<Button>View work</Button>
```

### Sizes

```tsx
<Button size="default">Default</Button>
<Button size="small">Small</Button>
<Button size="compact">Compact</Button>
```

### Icons

```tsx
<Button leadingIcon={<ArrowLeft />}>Back</Button>
<Button trailingIcon={<ArrowRight />}>View work</Button>
```

### Trailing icon on hover

```tsx
<Button
  href="https://resume.fabio.cv/"
  target="_blank"
  trailingIcon={<ArrowUpRight />}
  trailingIconOnHover={true}
>
  Résumé
</Button>
```

### Icon only

```tsx
<Button leadingIcon={<ArrowLeft />} aria-label="Back" />
```

See it at https://ui.fabio.cv/button/.
