# Button

A composable button component with palette-based theming, loading/success status states, and flexible icon/content slots.

## Import

```jsx
import Button from '@zohodesk/components/es/v1/Button/Button';
```

## Usage

### Default

```jsx
<Button customId="saveBtn" testId="saveBtn">
  Save changes
</Button>
```

### With Palette

```jsx
<Button palette="brand">Save</Button>
<Button palette="danger">Delete</Button>
<Button palette="success">Confirm</Button>
```

### With Appearance

`appearance`, `hoverAppearance`, and `selectedAppearance` are objects with optional `bg`, `border`, and `text` keys. Each key accepts `true` (use palette color), `false` (suppress), or a palette name string.

```jsx
<Button palette="brand" appearance={{ bg: false, border: true }}>
  Ghost
</Button>

<Button
  palette="brand"
  appearance={{ bg: false, border: true }}
  hoverAppearance={{ bg: false, border: true }}
  selectedAppearance={{ bg: false, border: true }}
>
  Ghost with states
</Button>
```

### Using Presets

```jsx
import {
  BRAND_GHOST,
  BRAND_TEXT_ONLY,
  SECONDARY_GHOST_BRAND_TINTED_ONSELECT,
  SECONDARY_GHOST_CANCEL,
  BRAND_TINTED_OUTLINE,
  BRAND_TEXT_TINTED_HOVER
} from '@zohodesk/components/es/v1/Button/constants/presets';

<Button {...BRAND_GHOST}>Brand Ghost</Button>
<Button {...BRAND_TEXT_ONLY}>Brand Text Only</Button>
<Button {...SECONDARY_GHOST_BRAND_TINTED_ONSELECT}>Secondary Ghost</Button>
```

### With Icon

```jsx
<Button variant="icon" iconName="ZD-plus" iconSize={20} />

<Button variant="iconWithText" iconName="ZD-plus" iconPlacement="start">
  Add Item
</Button>
```

### Loading / Success State

```jsx
<Button status="loading" loaderPlacement="overlay">Saving...</Button>
<Button status="loading" loaderPlacement="start">Loading</Button>
<Button status="success">Done</Button>
```

### Disabled

```jsx
<Button isDisabled>Disabled</Button>
<Button isDisabled disabledAppearance="strike">Disabled Strike</Button>
```

### Shape

```jsx
<Button shape="pill">Pill</Button>
<Button shape="rectangle">Rectangle</Button>
<Button shape="roundedRectangle">Rounded</Button>
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `palette` | `oneOf: brand, brandLighter, info, infoLighter, secondary, secondaryLighter, danger, dangerLighter, success, successLighter, warning, warningLighter` | `''` | Color palette |
| `appearance` | `{ bg?, border?, text? }` | `{ bg: true, text: true }` | Color treatments at rest. Values: `true`, `false`, or a palette name |
| `hoverAppearance` | `{ bg?, border?, text? }` | `{ bg: true, text: true }` | Color treatments on hover/focus/active |
| `selectedAppearance` | `{ bg?, border?, text? }` | `{ bg: true, text: true }` | Color treatments when `isSelected` is true |
| `variant` | `oneOf: text, icon, iconWithText` | `text` | Display variant |
| `size` | `oneOf: small, medium, large, full` | `medium` | Size variant |
| `status` | `oneOf: default, loading, success` | `default` | Status state |
| `loaderPlacement` | `oneOf: start, end, overlay` | `overlay` | Where the loader appears |
| `shape` | `oneOf: pill, rectangle, roundedRectangle` | `roundedRectangle` | Border shape |
| `iconName` | `string` | — | Icon name from `@zohodesk/icons` |
| `iconSize` | `number` | `16` | Icon size in pixels |
| `iconPlacement` | `oneOf: start, end` | `start` | Icon position relative to text |
| `disabledAppearance` | `oneOf: none, dull, strike` | `dull` | Visual style when disabled |
| `isDisabled` | `bool` | `false` | Disables the button |
| `isSelected` | `bool` | `false` | Selected/pressed state (`aria-pressed`) |
| `type` | `oneOf: button, submit, reset` | `button` | HTML button type |
| `onClick` | `func` | — | Click handler (suppressed when disabled or loading) |
| `title` | `string` | — | Tooltip / `data-title` attribute |
| `children` | `node` | — | Button label content |
| `renderIcon` | `node \| func` | — | Custom icon render slot |
| `renderBefore` | `node \| func` | — | Slot before main content |
| `renderAfter` | `node \| func` | — | Slot after main content |
| `renderLoader` | `node \| func` | — | Custom loader render slot |
| `renderSuccess` | `node \| func` | — | Custom success render slot |
| `customId` | `string` | — | `data-id` attribute |
| `testId` | `string` | — | `data-test-id` attribute |
| `dataSelectorId` | `string` | — | `data-selector-id` attribute |
| `a11yAttributes` | `object` | `{}` | Extra ARIA/accessibility attributes spread onto `<button>` |
| `customClass` | `{ wrapper?, text?, icon?, loader?, success? }` | `{}` | CSS class overrides per part |
| `customProps` | `{ text?, icon? }` | `{}` | Extra props forwarded to text/icon sub-elements |
| `customAttributes` | `{ button?, contentWrapper?, loader?, success?, icon?, text? }` | `{}` | Extra HTML attributes per internal element |

## Presets

Ready-made palette + appearance combinations exported from `constants/presets`:

| Name | Palette | Appearance | Description |
|---|---|---|---|
| `BRAND_GHOST` | `brand` | `{ bg: false, border: true }` | Transparent bg, brand border |
| `BRAND_TEXT_ONLY` | `brand` | `{ bg: false }` | Text only, no border |
| `BRAND_TINTED_OUTLINE` | `brandLighter` | `{ border: true }` | Tinted fill, brand border |
| `SUCCESS_GHOST` | `success` | `{ bg: false, border: true }` | Transparent bg, success border |
| `SUCCESS_TEXT_ONLY` | `success` | `{ bg: false }` | Text only, no border |
| `SUCCESS_TINTED_OUTLINE` | `successLighter` | `{ border: true }` | Tinted fill, success border |
| `SECONDARY_GHOST_BRAND_TINTED_ONSELECT` | `secondary` | `{ bg: false, border: true }` | Secondary ghost; selected state switches to brand tint |
| `SECONDARY_GHOST_CANCEL` | `secondary` | `{ bg: false, border: true }` | Secondary ghost without a selected state; cancel / dismiss buttons |
| `BLACK_TEXT_BRAND_ONHOVER` | `brand` | `{ bg: false, text: 'black' }` | Black text, brand color on hover |
| `BRAND_BG_ONSELECT` | `brand` | `{ bg: false, border: true }` | Ghost without a defined selected state |
| `BRAND_TEXT_TINTED_HOVER` | `brandLighter` | `{ bg: false }` | Ghost that becomes tinted on hover |
| `BRAND_TEXT_TINTED_DANGER_HOVER` | `brandLighter` | `{ bg: false }` | Ghost that becomes danger-tinted on hover |

## Customization

### Parts

| Part key | Element | Description |
|---|---|---|
| `button` | `<button>` | Outermost button element |
| `contentWrapper` | Inner `<Flex>` | Wraps icon + text content |
| `text` | `<Typography>` | Text label |
| `icon` | `<Icon>` | Icon element |
| `loader` | `<Flex>` | Loader wrapper |
| `success` | `<Flex>` | Success tick wrapper |

Pass class overrides via `customClass`, extra props via `customProps`, or arbitrary HTML attributes via `customAttributes`.

```jsx
<Button
  customClass={{ wrapper: 'myBtn', text: 'myBtnText' }}
  customAttributes={{ button: { 'data-analytics': 'save' } }}
  a11yAttributes={{ 'aria-label': 'Save document' }}
>
  Save
</Button>
```
