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

# Tag

Text in a `Button`'s box, exported from `@fabiocv/ui/tag`. It renders a
`span` and never links. Use a `Button` with `href` for a link.

```tsx
import { Check, Copy, GitHub } from '@fabiocv/ui/icons';
import { Tag } from '@fabiocv/ui/tag';

<Tag>name@example.com</Tag>;
<Tag leadingIcon={<GitHub />}>GitHub</Tag>;
<Tag
  trailingIcon={<Copy />}
  trailingDoneIcon={<Check />}
  trailingIconOnHover
  trailingLabel="Copy email"
  onTrailingClick={copy}
>
  name@example.com
</Tag>;
```

- The box, type, ink, icons and hover highlight are the `Button`'s: one line
  of body text in Regular and Foreground secondary, `32px` tall with `8px`
  corners, text `8px` from the edges, and `24px` icons drawn in their middle
  `16px`.
- `trailingIconOnHover` reveals the trailing icon only while the tag is
  hovered or holds keyboard focus, so it closes once the pointer leaves, even
  after a click. Hidden, it takes no room. Revealed, the tag and its
  highlight grow on the `SETTLE` spring, and the icon fades in on `APPEAR`. It
  sits on a Surface sunken square `2px` in from the tag's top, end and bottom,
  with `6px` corners, the tag's less those `2px`, and `6px` from the label.
  Its icon is drawn at `20px` rather than `24px`, in the same `1.5px` stroke.
  With reduced motion the tag grows at once and the icon only fades. Without
  hover, as on touch, it always shows.
- `onTrailingClick` makes the trailing icon a button, named by
  `trailingLabel`. Its focus ring follows its box's corners: `4px`, or the
  sunken square's `6px`. On a sunken square, hovering it steps the square one
  darker, to Separator, on `APPEAR`. Without `onTrailingClick`, the icon is
  hidden from assistive technology.
- What the button does is not announced. Add a live region where it has to be.
- `trailingDoneIcon` crossfades in for the trailing icon when its button is
  pressed, on the quick `TRACK` spring, and back out after `1.5s`. If the
  pointer leaves first, a revealed icon keeps the done icon as it fades out and
  clears once it has gone, so the next hover shows the trailing icon again.

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

```ts
export type TagProps = Omit<ComponentPropsWithoutRef<'span'>, 'children'> & {
    children?: ReactNode;
    /** A 24px icon before the label. */
    leadingIcon?: ReactNode;
    /** A 24px icon after the label. */
    trailingIcon?: ReactNode;
    /**
     * Reveals the trailing icon, on a sunken square, only while the tag is
     * hovered or holds keyboard focus. The tag grows to make room for it.
     */
    trailingIconOnHover?: boolean;
    /** Makes the trailing icon a button, such as one that copies the label. */
    onTrailingClick?: () => void;
    /** The trailing button's name. Required with `onTrailingClick`. */
    trailingLabel?: string;
    /**
     * Crossfades in for the trailing icon after its button is pressed, such as a
     * check after copying, and back out after `DONE`. If the pointer leaves the
     * tag first, it clears once the revealed icon has faded out, or at once when
     * the icon always shows.
     */
    trailingDoneIcon?: ReactNode;
};

/** Text in the button's box, with its hover highlight. It never links. */
export declare function Tag({ leadingIcon, trailingIcon, trailingIconOnHover, onTrailingClick, trailingLabel, trailingDoneIcon, children, className, onPointerEnter, onPointerLeave, ...props }: TagProps): import("react").JSX.Element;
```

## Examples

### Label

```tsx
<Tag>name@example.com</Tag>
```

### Icons

```tsx
<Tag leadingIcon={<GitHub />}>GitHub</Tag>
<Tag trailingIcon={<Copy />}>name@example.com</Tag>
```

### Copy on hover

```tsx
<Tag
  trailingIcon={<Copy />}
  trailingDoneIcon={<Check />}
  trailingIconOnHover={true}
  trailingLabel="Copy email"
  onTrailingClick={copyEmail}
>
  name@example.com
</Tag>
```

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