# Close Button

The × that closes a panel, dialog, toast or chip. A ghost square like the ⋯ icon button: a muted × that turns dark on hover, #f5f5f5 behind it on hover and #e9ebef pressed.

- Beta: ready to use; its API can still change in a minor release.
- Category: Actions

```tsx
import { CloseButton } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for the × on a panel, dialog, toast or chip, so every close looks and behaves the same: muted until hovered, named Close by default.
- Do: Set `aria-label` to say what closing does when Close isn't enough, like Remove Jane Citizen on a chip. In a list of chips each name must be unique.
- Do: Use `size="inline"` in toasts and chips. The × is 16 px but its hit area still reaches the 24 px minimum.
- Do: Match the size to the icon buttons beside it in the same header (xs 28, sm 32, md 36, lg 40), so the × lines up with them.
- Don't: Build a close with an `IconButton` and an X icon. Use `CloseButton`, which keeps the muted colour and the default name.
- Don't: Use it to delete a record, like a contact or a matter. Use a `Button` with `intent="destructive"` behind a confirmation.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Presses the focused button. |

## Related

- [Button](./button.md)
- [Panel Header](./panel-header.md)
- [Dialog](./dialog.md)
- [Drawer](./drawer.md)

## Examples

What the examples import:

```tsx
import { Fragment } from "react";
import { CloseButton } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const sizes = ["xs", "sm", "md", "lg", "inline"] as const;
```

### Sizes

xs 28, sm 32, md 36 and lg 40 match the icon button heights. Inline is a bare 16 px × for toasts and chips; its hit area still reaches 24 px.

```tsx
<div className="grid grid-cols-[auto_repeat(5,auto)] items-center justify-start gap-x-6 gap-y-3">
  {sizes.map(size => (
    <Fragment key={size}>
      <span className="text-small text-neutral-text-muted">{size}</span>
      <CloseButton size={size} />
      <span />
      <span />
      <span />
      <span />
    </Fragment>
  ))}
</div>
```

### Labelled

It's named Close by default. Say what closing does when that's clearer, like removing a person from a list.

```tsx
<span className="border-neutral-border text-small inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5">
  Jane Citizen
  <CloseButton size="inline" aria-label="Remove Jane Citizen" />
</span>
```

### Disabled

```tsx
<CloseButton size="sm" disabled />
```

## Props

Also takes every prop of ui-sdk's Button: onClick, disabled, focusableWhenDisabled and render.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "inline"` | `"xs"` | xs 28, sm 32, md 36 and lg 40 are ghost squares. Inline is a bare 16 px × for toasts and chips, with a 24 px hit area. |
| `aria-label` | `string` | `"Close"` | What closing does, when "Close" isn't enough, like "Remove Jane Citizen". |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
