# Buttons

`DButton` for actions with text, `DButtonIcon` for actions shown only as an icon. Exact props: `widgets-get-component-props`.

---

## DButton

From the template's reference feature:

```tsx
<DButton
  text={t('entities.list.create')}
  iconStart="Plus"
  onClick={() => openPortal('entity-create', { onCreate: createEntity })}
/>
```

```tsx
<DButton
  text={t('common.cancel')}
  variant="outline"
  onClick={() => closePortal()}
/>
<DButton
  text={t('common.save')}
  loading={isPending}
  onClick={() => {
    void submit();
  }}
/>
```

| Prop | Use |
|------|-----|
| `text` | The label. Children also render, but `text` is the documented form |
| `color` | Semantic color (`primary` by default) |
| `variant` | `solid` (default), `outline`, `link` or `soft` |
| `size` | `sm` or `lg`; omit for the default size. Also accepts a responsive map with those values |
| `iconStart`, `iconEnd` | Lucide icon names in PascalCase |
| `loading`, `loadingText`, `loadingAriaLabel` | Loading state, its visible text and its accessible name |
| `href`, `target`, `rel` | Render as a link |
| `type`, `onClick`, `disabled`, `aria-label` | Native button attributes (other `<button>` attributes are forwarded too) |

**Hierarchy:** one primary action (`solid`) per group; secondary actions with `outline`; tertiary actions with `link`. Place the primary action last in a row of actions.

---

## DButtonIcon

An icon-only button. It has no visible text, so give it an accessible name through `aria-label`:

```tsx
<DButtonIcon icon="Trash2" color="danger" variant="link" aria-label={t('common.delete')} onClick={onDelete} />
```

| Prop | Use |
|------|-----|
| `icon` | Required. Lucide name in PascalCase |
| `aria-label` | Accessible name; required in practice |
| `variant` | `solid`, `outline`, `link` or `soft` |
| `size` | `sm` or `lg` |
| `iconSize` | Size of the icon inside the button |
| `loading`, `disabled`, `color`, `href`, `onClick` | As in `DButton` |

---

## Common mistakes

| Wrong | Right |
|-------|-------|
| `theme="primary"` | `color="primary"` |
| `ariaLabel="…"` on a button | `aria-label="…"` |
| `size="md"`, `size="xs"` | `size="sm"`, `size="lg"`, or no `size` |
| Icon-only `DButton` without a label | `DButtonIcon` plus `aria-label` |
| `icon="trash-2"` | `icon="Trash2"` |

Menus of actions: `DDropdown` in `modyo://docs/widgets/components-overlay-widgets`.
