# Compact button

A small icon button for actions that sit beside other content: close, copy, more, edit.

```tsx
import { CompactButton } from '@halo-ds/react';
```

## When to use it
Use a compact button where a full button would be too heavy, like the close icon on a dialog, actions in a table row or tools in a toolbar. It holds a single icon, with no label.

Compact buttons come in three styles, two sizes and six states, with square or round corners. They can also stay switched on (Selected), like Bold in a text editor.

## Do
- Use icons people already know: close, copy, edit, delete, more.
- Keep one style in a group, for example all Ghost in a toolbar.
- Show a tooltip with the action name on hover.
- Use Selected only for buttons that switch something on and off.

## Don't
- Use a compact button for the main action on a page; use a Button.
- Mix styles and corner shapes side by side.
- Rely on an unfamiliar icon alone with no tooltip.
- Use Medium on touch screens.

## Compact button or Button?
Both can show a single icon. Choose by how much attention the action needs.
- **Compact button**: Secondary actions next to content: close, copy, edit, more. Toolbars and table rows, where space is tight. Toggles that stay on (Selected).
- **Button (icon only)**: Main actions that need to be easy to see and tap. Places where it sits next to other Buttons, so sizes and colours match. Actions on touch screens, where a bigger target helps.

## Props
### CompactButton props
| Prop | Type | What it does |
| --- | --- | --- |
| `variant` | `CompactButtonVariant \| undefined` | Background and outline. Figma: Style. |
| `size` | `CompactButtonSize \| undefined` | lg is 28px with a 20px icon, md is 24px with a 16px icon. Figma: Size. |
| `round` | `boolean \| undefined` | Fully round corners instead of slightly rounded. Figma: Full radius. |
| `selected` | `boolean \| undefined` | Switched on, for buttons that toggle (like Bold). Sets aria-pressed. Figma: State=Selected. |
| `children` (required) | `ReactNode` | The icon. Figma: Change icon. |
| `aria-label` (required) | `string` | Compact buttons have no visible text, so they need a name for screen readers. |
| `classNames` | `Partial<Record<CompactButtonPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<CompactButtonPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { CompactButton, Tooltip } from '@halo-ds/react';
import { DotsThree, PencilSimple, Star, Trash } from '@phosphor-icons/react';

export default function Example() {
  return (
    <div style={{ display: 'flex', gap: 8 }}>
      <Tooltip content="Edit">
        <CompactButton aria-label="Edit"><PencilSimple /></CompactButton>
      </Tooltip>
      <Tooltip content="Favourite">
        <CompactButton variant="ghost" aria-label="Favourite" selected><Star /></CompactButton>
      </Tooltip>
      <Tooltip content="Delete">
        <CompactButton variant="ghost" aria-label="Delete"><Trash /></CompactButton>
      </Tooltip>
      <Tooltip content="More">
        <CompactButton variant="ghost" aria-label="More"><DotsThree /></CompactButton>
      </Tooltip>
    </div>
  );
}
```

### Styles
Stroke has a border, Ghost has none until you point at it, and Fill sits on a grey background.
```tsx
import { CompactButton } from '@halo-ds/react';
import { X } from '@phosphor-icons/react';

export default function Demo() {
  return (
    <div className="demo-row">
      <CompactButton variant="stroke" aria-label="Close"><X /></CompactButton>
      <CompactButton variant="ghost" aria-label="Close"><X /></CompactButton>
      <CompactButton variant="fill" aria-label="Close"><X /></CompactButton>
    </div>
  );
}
```

### Sizes and corners
Large is 24px with a 20px icon, medium is 20px with a 16px icon. Corners are slightly rounded or fully round.
```tsx
import { CompactButton } from '@halo-ds/react';
import { X } from '@phosphor-icons/react';

export default function Demo() {
  return (
    <div className="demo-row">
      <CompactButton size="lg" aria-label="Close"><X /></CompactButton>
      <CompactButton size="md" aria-label="Close"><X /></CompactButton>
      <CompactButton size="lg" round aria-label="Close"><X /></CompactButton>
      <CompactButton size="md" round aria-label="Close"><X /></CompactButton>
    </div>
  );
}
```

### Toggle
Selected is for buttons that switch something on and off. Click them to try it.
```tsx
import { useState } from 'react';
import { CompactButton } from '@halo-ds/react';
import { TextB, TextItalic, TextUnderline } from '@phosphor-icons/react';

export default function Demo() {
  const [on, setOn] = useState<Record<string, boolean>>({ bold: true });
  const toggle = (k: string) => setOn((s) => ({ ...s, [k]: !s[k] }));
  return (
    <div className="demo-row">
      <CompactButton variant="ghost" selected={!!on.bold} onClick={() => toggle('bold')} aria-label="Bold"><TextB /></CompactButton>
      <CompactButton variant="ghost" selected={!!on.italic} onClick={() => toggle('italic')} aria-label="Italic"><TextItalic /></CompactButton>
      <CompactButton variant="ghost" selected={!!on.underline} onClick={() => toggle('underline')} aria-label="Underline"><TextUnderline /></CompactButton>
    </div>
  );
}
```

### In a file row
Compact buttons keep row actions small, so the file name stays the focus.
```tsx
import { CompactButton } from '@halo-ds/react';
import { DownloadSimple, FilePdf, Trash } from '@phosphor-icons/react';

export default function Demo() {
  return (
    <div className="demo-panel" style={{ display: 'flex', alignItems: 'center', gap: 12, width: 340 }}>
      <FilePdf size={24} />
      <span style={{ flex: 1 }}>Project brief.pdf</span>
      <CompactButton variant="ghost" aria-label="Download Project brief.pdf"><DownloadSimple /></CompactButton>
      <CompactButton variant="ghost" aria-label="Delete Project brief.pdf"><Trash /></CompactButton>
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/compact-button
