# Toolbar components

Two components for building toolbars:

- **`ixfx-toolbar`** — a responsive toolbar container with overflow handling
- **`ixfx-toolbar-group`** — a labelled grouping container for toolbar items

---

## `ixfx-toolbar`

A responsive toolbar container that handles overflow by moving items to a popover. Supports horizontal and vertical orientations.

```html
<ixfx-toolbar>
  <ixfx-toolbar-group label="Clipboard">
    <ixfx-button icon="copy">Copy</ixfx-button>
    <ixfx-button icon="paste">Paste</ixfx-button>
  </ixfx-toolbar-group>
  <ixfx-toolbar-group label="Font">
    <ixfx-button>B</ixfx-button>
    <ixfx-button>I</ixfx-button>
  </ixfx-toolbar-group>
</ixfx-toolbar>
```

### Properties / attributes

| Attribute / Property | Type | Default | Description |
|---------------------|------|---------|-------------|
| `orientation` | `'horizontal'` \| `'vertical-left'` \| `'vertical-right'` | `'horizontal'` | Layout direction. `vertical-left` flips text upward. |
| `layout` | `'one-line'` \| `'wrap'` | `'one-line'` | `'one-line'` enables overflow handling; `'wrap'` allows items to wrap to multiple lines |
| `vertical-writing` | `'auto'` \| `'up'` \| `'down'` \| `'none'` | `'auto'` | Writing mode for vertical orientations |
| `toolbar-align` | `'near'` \| `'far'` | `'near'` | Horizontal justification: `near` = left, `far` = right |
| `show-group-labels` | boolean | `false` | Show labels as rows above group content |
| `invisible-groups` | boolean | `false` | Hide group borders and backgrounds |

### Slots

| Slot        | Description                              |
|-------------|------------------------------------------|
| default     | Toolbar items (buttons, groups, etc.)    |
| `overflow`  | Items in the overflow popover             |

### CSS custom properties

| Property | Default | Description |
|----------|---------|-------------|
| `--toolbar-gap` | `var(--space-s)` | Gap between toolbar items |
| `--toolbar-group-gap` | `var(--space-m)` | Gap between nested `ixfx-toolbar-group` elements |
| `--toolbar-bg` | `var(--surface-2)` | Toolbar background |
| `--toolbar-padding` | `var(--space-s)` | Toolbar padding |
| `--toolbar-border` | `var(--border-subtle)` | Toolbar border |
| `--toolbar-group-padding` | `var(--space-xs)` | Padding for nested `ixfx-toolbar-group` elements (set here to affect all groups) |
| `--toolbar-overflow` | `'auto'` | Overflow mode: `'auto'` (show items, hide overflow button when not needed), `'collapsed'` (all items in overflow, button always visible), `'disabled'` (no overflow, items always visible) |

### Alignment

`toolbar-align` controls justification along the main axis. For horizontal toolbars (the default orientation), `near` (default) left-justifies content (`justify-content: flex-start`) and `far` right-justifies it (`justify-content: flex-end`). The attribute is ignored for vertical orientations. Overflow handling (`layout="one-line"`) works with both values — the overflow popover remains right-aligned when `far` is set.

```html
<!-- Left-aligned (default) -->
<ixfx-toolbar toolbar-align="near">
  <ixfx-button>Save</ixfx-button>
  <ixfx-button>Cancel</ixfx-button>
</ixfx-toolbar>

<!-- Right-aligned horizontal toolbar -->
<ixfx-toolbar toolbar-align="far">
  <ixfx-button>Save</ixfx-button>
  <ixfx-button>Cancel</ixfx-button>
</ixfx-toolbar>
```

See `demo/toolbar.html` “Alignment – toolbar-align” for a live demo: side-by-side `near` vs `far` comparison, a `far` toolbar with many groups (resize to see overflow stay right-aligned), and an interactive toggle (`select#select-align` driving `toolbar#toolbar-align-demo`).

### Writing mode

For vertical toolbars, `vertical-writing` controls how text is displayed:

- `'auto'` — `vertical-right` uses `vertical-lr`, `vertical-left` uses `vertical-rl`
- `'up'` — Forces `vertical-rl` (text runs upward)
- `'down'` — Forces `vertical-lr` (text runs downward)
- `'none'` — Forces `horizontal-tb` (no vertical writing)

### Layout mode

The `layout` attribute controls how items handle available space:

- `'one-line'` (default): Items stay on a single line. Items that don't fit are moved to an overflow popover.
- `'wrap'`: Items wrap to multiple lines as needed. No overflow handling occurs.

```html
<!-- Items wrap to new lines when they don't fit -->
<ixfx-toolbar layout="wrap">
  <ixfx-button>A</ixfx-button>
  <ixfx-button>B</ixfx-button>
  <ixfx-button>C</ixfx-button>
</ixfx-toolbar>
```

### Overflow handling

When `layout="one-line"` and items exceed available space, excess items are moved to an overflow popover. The popover is positioned using CSS Anchor Positioning relative to the overflow button.

```html
<ixfx-toolbar layout="one-line">
  <!-- Items that don't fit will be moved to overflow -->
  <ixfx-button>Item 1</ixfx-button>
  <ixfx-button>Item 2</ixfx-button>
  <!-- ... -->
</ixfx-toolbar>
```

#### Overflow modes

The `--toolbar-overflow` CSS variable controls how overflow behaves:

- `'auto'` (default): Items are shown initially. When they don't fit, they move to overflow and the overflow button appears.
- `'collapsed'`: All items start in overflow. The overflow button is always visible.
- `'disabled'`: Overflow is disabled. Items always remain visible and may overflow the container.

```css
/* All items hidden behind overflow button */
ixfx-toolbar {
  --toolbar-overflow: collapsed;
}

/* Never collapse - always show all items */
ixfx-toolbar {
  --toolbar-overflow: disabled;
}
```

#### Groups and overflow

Items with the `grow` attribute never go into overflow — they always remain visible and take remaining space.

---

## `ixfx-toolbar-group`

A grouping container for toolbar items. Groups can have a label and support grow behavior.

```html
<ixfx-toolbar-group label="Font">
  <ixfx-button>B</ixfx-button>
  <ixfx-button>I</ixfx-button>
</ixfx-toolbar-group>

<ixfx-toolbar-group grow>
  <!-- This group takes up remaining space -->
</ixfx-toolbar-group>
```

### Properties / attributes

| Attribute / Property | Type | Default | Description |
|---------------------|------|---------|-------------|
| `label` | string | `''` | Label text displayed above content |
| `grow` | boolean | `false` | Group grows to fill remaining space |

The `show-group-labels` attribute on the parent `ixfx-toolbar` controls whether group labels are displayed as rows above the group content.

### CSS custom properties

| Property | Default | Description |
|----------|---------|-------------|
| `--toolbar-group-padding` | `var(--space-xs)` | Padding inside the group (can be set on parent `ixfx-toolbar`) |
| `--toolbar-group-justify-content` | `flex-start` | Horizontal alignment of group contents |
| `--toolbar-group-align-items` | `center` | Vertical alignment of group contents |
| `--toolbar-group-border` | `var(--border-subtle)` | Border around the group (set to `none` with `invisible-groups` on parent to hide borders) |

The `--toolbar-gap` property is inherited from the parent `ixfx-toolbar`.

```html
<!-- Right-align items within a group -->
<ixfx-toolbar-group style="--toolbar-group-justify-content: flex-end;">
  <ixfx-button>Action</ixfx-button>
</ixfx-toolbar-group>
```

---

## Demos

See `demo/toolbar.html` for complete examples including:

- Word-style horizontal toolbar with font selection, formatting buttons, and paragraph controls
- Chrome-style toolbar with a growable search input
- Vertical toolbars with different orientations (`vertical-right`, `vertical-left`) and writing modes
- Horizontal alignment – `toolbar-align="near"` (left) vs `far` (right) with static examples, overflow example, and interactive toggle
- Footer toolbar with far-right justified group
- Toolbar with group labels displayed as rows
- Overflow modes: `collapsed` and `disabled` examples

---

## TypeScript types

```ts
import type {
  ToolbarOrientation, // 'horizontal' | 'vertical-left' | 'vertical-right'
  ToolbarLayout,      // 'one-line' | 'wrap'
  ToolbarVerticalWriting, // 'auto' | 'up' | 'down' | 'none'
  ToolbarAlign // 'near' | 'far'
} from 'ixfxfun-components';
```
