# Titlebar

Standalone titlebar chrome extracted from `ixfx-panel`: title text, icon, toolbar slot, close button and an optional collapse/expand caret. Use it when you need a panel-style header without the collapsible content wrapper (custom layouts, dock headers, section bars).

```html
<ixfx-titlebar title="Settings" icon-name="settings" collapsible>
  <div slot="toolbar">
    <button type="button"><ixfx-icon name="printer"></ixfx-icon></button>
  </div>
</ixfx-titlebar>
```

`ixfx-panel` composes this component internally, so the two stay visually in sync.

---

## `ixfx-titlebar`

### Properties / attributes

| Attribute / Property      | Type                                              | Default        | Description                                                     |
|--------------------------|---------------------------------------------------|----------------|-----------------------------------------------------------------|
| `title`                  | string                                            | `''`           | Title text; ellipsised when the bar is too narrow                |
| `icon-name`              | string                                            | `''`           | Icon name from the registry                                     |
| `orientation`            | `'horizontal'` \| `'vertical'`                    | `'horizontal'` | Layout direction of the bar                                     |
| `variant`                | `'titlebar'` \| `'midline'` \| `'tree'`             | `'titlebar'`   | Visual style (same variants as `ixfx-panel`)                    |
| `closable`               | boolean                                           | `false`        | Shows a close button that fires `close`                         |
| `collapsible`            | boolean                                           | `false`        | Shows the caret and enables toggle behaviour (opt-in)           |
| `collapsed`              | boolean                                           | `false`        | Collapsed state (controls caret rotation / label)               |
| `toggle-interaction`     | `'implicit'` \| `'explicit'` \| `'disabled'`      | `'implicit'`   | How users can toggle (only when `collapsible` is present)       |

### Collapsible vs toggle interaction

The caret is shown only when `collapsible` is present **and** `toggle-interaction` is not `disabled`. When `collapsible` is absent, `toggle-interaction` is inert and no `toggle` events fire.

| `collapsible` | `toggle-interaction` | Behaviour                                              |
|---------------|----------------------|--------------------------------------------------------|
| absent        | any                  | No caret, no user toggle                               |
| present       | `implicit`           | Clicking the caret or anywhere in the bar toggles      |
| present       | `explicit`           | Only clicking the caret toggles                        |
| present       | `disabled`           | Caret hidden, no user toggle (programmatic only)       |

Unlike `ixfx-panel`, toggling only flips the `collapsed` property and fires `toggle` — there is no content to hide. And unlike `ixfx-panel`, `close` does **not** remove the element; the host decides what closing means.

### Slots

| Slot             | Description                                                              |
|------------------|--------------------------------------------------------------------------|
| `toolbar`        | Buttons or other elements right-aligned in the bar                       |
| `title`          | Arbitrary content (inputs, buttons, tabs…) shown in the title area in place of the `title` text — leave `title` empty when using it. Fills the available space |
| `title-context`  | Arbitrary content (e.g. an `ixfx-led`) immediately after the title text. Kept at its natural size while a long title truncates |

Clicking toolbar or `title-context` content never toggles, even with `toggle-interaction="implicit"`.

### Title context

Use `title-context` for live status or other title-adjacent content. The slotted element stays in the light DOM, so keep a reference to it and update it from anywhere in your code:

```html
<ixfx-titlebar title="Connection" collapsible>
  <ixfx-led slot="title-context" id="status" color="oklch(70% 0.2 145)"></ixfx-led>
</ixfx-titlebar>

<script>
  const status = document.querySelector('#status');
  status.lit = true;        // update directly
  status.pulse();           // or drive it with mode="pulse"
</script>
```

The title text ellipsises when space is tight; the leading icon, title context and toolbar keep their intrinsic sizes.

### Events

| Event    | Detail                             | Description                              |
|----------|------------------------------------|------------------------------------------|
| `toggle` | `{ collapsed: boolean }`           | Fired when collapsed state changes       |
| `close`  | —                                  | Fired when the close button is clicked   |

```js
const bar = document.querySelector('ixfx-titlebar');

bar.addEventListener('toggle', e => {
  console.log('Collapsed:', e.detail.collapsed);
});

bar.addEventListener('close', () => {
  console.log('Close requested');
});
```

### Icons

Icon names resolve against the icon registry. Register custom icons with `registerIcon(name, svgString)` from `src/icons/registry.ts`.

Built-in icon names: `check`, `chevron-down`, `chevron-right`, `close`.

---

## Visual variants

Same `titlebar` (default) and `midline` styles as `ixfx-panel`, including vertical orientation support. The `tree` variant renders caret, icon and title in a compact inline layout with transparent chrome, matching VS Code explorer / Outline style:

```html
<ixfx-titlebar title="Explorer" variant="tree" icon-name="folder" collapsible></ixfx-titlebar>
```

---

## TypeScript types

```ts
import type { TitlebarOrientation, TitlebarVariant, TitlebarToggleInteraction, TitlebarToggleDetail } from 'ixfxfun-components';
```

---

## See also

- [`ixfx-panel`](./panel.md) — Collapsible panel that composes this titlebar
- [`ixfx-icon`](./icons.md) — Icon component used by the titlebar
