# Panel

An collapsible panel component with support for titles, icons, toolbars, and multiple visual variants.

The header chrome is an `ixfx-titlebar` (see [`ixfx-titlebar`](./titlebar.md)); the panel adds the collapsible content area beneath it.

```html
<ixfx-panel title="Settings">
  <p>Panel content goes here.</p>
</ixfx-panel>
```

---

## `ixfx-panel`

### Properties / attributes

| Attribute / Property      | Type                                              | Default       | Description                                      |
|--------------------------|---------------------------------------------------|---------------|--------------------------------------------------|
| `collapsed`              | boolean                                           | `false`       | Whether the panel is collapsed (content hidden)  |
| `collapsible`            | boolean                                           | `true`        | Whether the caret is shown and the panel can be toggled (opt-out) |
| `orientation`            | `'horizontal'` \| `'vertical'`                    | `'horizontal'`| Layout direction of title bar                   |
| `title`                  | string                                            | `''`          | Panel title text; ellipsised when the panel is too narrow |
| `icon-name`              | string                                            | `''`          | Icon name from the registry                      |
| `closable`              | boolean                                           | `false`       | Shows a close button that removes the panel     |
| `keep-toolbar`          | boolean                                           | `false`       | Keep the toolbar visible even when collapsed     |
| `toggle-interaction`     | `'implicit'` \| `'explicit'` \| `'disabled'`       | `'implicit'`   | How users can toggle the panel (see below)      |
| `variant`                | `'titlebar'` \| `'midline'` \| `'tree'`            | `'titlebar'`  | Visual style of the panel                       |

### Toggle interaction modes

| Mode       | Behavior                                                                 |
|------------|--------------------------------------------------------------------------|
| `implicit` | Clicking the caret button or anywhere in the title bar toggles the panel |
| `explicit` | Only clicking the caret button toggles the panel                         |
| `disabled` | Caret is hidden; no user toggle possible (programmatic only)          |

Set `collapsible` to `false` (via property binding or JS — `collapsible` defaults to `true`, so a bare `collapsible="false"` attribute would still count as present) or use `toggle-interaction="disabled"` for a fixed header with no user toggle:

```html
<ixfx-panel id="fixed" title="Fixed" toggle-interaction="disabled">
  <p>This panel cannot be collapsed by the user.</p>
</ixfx-panel>
<script>
  // Opt out of collapsing entirely (hides the caret):
  document.querySelector('#fixed').collapsible = false;
</script>
```

### Slots

| Slot             | Description                                                     |
|------------------|-----------------------------------------------------------------|
| default          | Panel content (shown when expanded)                             |
| `toolbar`        | Buttons or other elements in the title bar toolbar (hidden when collapsed by default; set `keep-toolbar` to always show) |
| `title-context`  | Arbitrary content (e.g. an `ixfx-led`) immediately after the title text. Kept at its natural size while a long title truncates |

### Events

| Event    | Detail                             | Description                           |
|----------|------------------------------------|---------------------------------------|
| `toggle` | `{ collapsed: boolean }`           | Fired when panel expand/collapse state changes |
| `close`  | —                                 | Fired when close button is clicked; panel is removed from DOM |

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

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

panel.addEventListener('close', () => {
  console.log('Panel closed and removed');
});
```

### 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

### `titlebar` variant (default)

The standard panel style with a visible header bar above the content area:

```html
<ixfx-panel title="Settings" icon-name="settings">
  <p>Content here</p>
</ixfx-panel>
```

- Header uses `--surface-4` background
- Content area has inset shadow for depth
- Rounded corners (`--radius-m`)

### `midline` variant

A lightweight, minimal style with a horizontal line running through the title text:

```html
<ixfx-panel title="Settings" variant="midline" icon-name="settings">
  <p>Content here</p>
</ixfx-panel>
```

- No background or border on the host element
- Title bar is transparent with the title text overlaid
- A debossed line runs horizontally (or vertically for `orientation="vertical"`) behind the title text
- The line is visible between the title text and toolbar buttons
- Useful for section headers or metadata display

### `tree` variant

A VS Code explorer / Outline style with a minimal inline title bar:

```html
<ixfx-panel title="Explorer" variant="tree" icon-name="folder">
  <p>Content here</p>
</ixfx-panel>
```

- Caret is shown first, followed by the icon and title inline (no debossed line)
- Transparent background and border; minimal padding
- Toolbar is hidden when the panel is collapsed — set `keep-toolbar` to always show it

---

## Vertical orientation

Panels can display vertically with the title bar on the left side:

```html
<ixfx-panel title="Device" orientation="vertical" icon-name="server">
  <p>Content here</p>
</ixfx-panel>
```

For `variant="midline"` with `orientation="vertical"`, the debossed line runs vertically alongside the rotated title text.

---

## With toolbar

Add buttons or other controls to the title bar using the `toolbar` slot:

```html
<ixfx-panel title="Document">
  <div slot="toolbar">
    <button type="button" data-tooltip="Print">
      <ixfx-icon name="printer"></ixfx-icon>
    </button>
  </div>
  <p>Document content</p>
</ixfx-panel>
```

Clicking toolbar buttons does not toggle the panel when `toggle-interaction="implicit"`.

---

## Title context

Use the `title-context` slot for status indicators or other content next to the title. The element stays in the panel's light DOM, so you can keep a reference and update it externally:

```html
<ixfx-panel title="Connection" id="connection-panel">
  <ixfx-led slot="title-context" id="connection-status" color="oklch(70% 0.2 145)"></ixfx-led>
  <p>Panel content</p>
</ixfx-panel>

<script>
  const status = document.querySelector('#connection-status');
  status.lit = true;
</script>
```

Long titles ellipsise instead of overlapping the caret, close button or toolbar. The icon, title context and toolbar keep their intrinsic sizes.

---

## Collapsed by default

Use the `collapsed` attribute to start the panel in collapsed state:

```html
<ixfx-panel title="Advanced" collapsed>
  <p>This content is hidden initially</p>
</ixfx-panel>
```

---

## CSS custom properties

| Property                | Default                   | Description                                      |
|-------------------------|--------------------------|--------------------------------------------------|
| `--surface-3`           | theme-dependent          | Panel background                                |
| `--surface-3-text`     | theme-dependent          | Title text color                                |
| `--surface-4`           | theme-dependent          | Title bar background (titlebar variant)          |
| `--border-subtle`       | theme-dependent          | Border color (titlebar variant)                  |
| `--radius-m`            | `4px`                    | Border radius (titlebar variant)                 |
| `--space-s`             | `4px`                    | Small spacing                                   |
| `--space-m`             | `8px`                    | Medium spacing                                  |
| `--transition`           | `0.15s ease-out`        | Animation transition duration                    |
| `--panel-width`         | `auto`                   | Width for vertical panels                       |
| `--panel-height`        | `auto`                   | Height for horizontal panels                    |
| `--panel-content-shadow`| `var(--deboss-3)`        | `box-shadow` of the content area (the inset 3D effect). `none` removes it |
| `--panel-content-border`| `none`                   | `border` of the content area                    |
| `--prominence-idle-opacity` | `0.6`             | Opacity of caret when idle                     |
| `--prominence-tickled-opacity` | `1.0`         | Opacity of caret on hover                      |

### Midline-specific line appearance

| Property     | Description                                    |
|--------------|------------------------------------------------|
| `--surface-1` | Shadow color for debossed line (darker)       |
| `--surface-2` | Line background color                         |
| `--surface-5` | Highlight color for debossed line (lighter)   |

---

## `ixfx-panel-group`

A container component that manages multiple panels with flexible open behavior.

### Properties / attributes

| Attribute / Property   | Type                                              | Default        | Description                                                   |
|------------------------|---------------------------------------------------|----------------|---------------------------------------------------------------|
| `accordion`            | boolean                                           | `false`        | Restrict to one open panel at a time                         |
| `allow-reorder`        | boolean                                           | `false`        | Enable drag-and-drop reordering of panels via their titlebars |
| `collapsible`          | boolean                                           | `true`         | Collapse behaviour propagated to child panels                |
| `gap`                  | string                                            | (unset)        | Explicit gap between panels; sets `--group-gap` when provided |
| `orientation`          | `'horizontal'` \| `'vertical'`                   | `'horizontal'` | Layout direction of the group                                 |
| `sticky-headers`       | boolean (`"false"` disables)                      | `true`         | Pin each panel's titlebar to the scroll area edge (top, or left for vertical titlebars) |
| `toggle-interaction`   | `'implicit'` \| `'explicit'` \| `'disabled'`     | `'implicit'`   | Toggle behavior applied to all child panels                   |
| `variant`              | `'titlebar'` \| `'midline'` \| `'tree'`          | `'titlebar'`   | Visual style applied to all child panels                     |

### Group orientation vs child panel orientation

The group's `orientation` controls:
1. How the group lays out its child panels (flex row vs flex column)
2. What `orientation` is automatically applied to child panels

| Group `orientation` | Group layout direction | Child panels get `orientation` |
|---------------------|------------------------|-------------------------------|
| `horizontal`        | Flex row (horizontal)  | `vertical`                    |
| `vertical`          | Flex column (vertical)  | `horizontal`                  |

Explicit attributes on child panels take precedence over group-propagated values.

### Example

```html
<ixfx-panel-group orientation="horizontal">
  <ixfx-panel title="Panel 1">
    <p>Content 1</p>
  </ixfx-panel>
  <ixfx-panel title="Panel 2">
    <p>Content 2</p>
  </ixfx-panel>
  <ixfx-panel title="Panel 3">
    <p>Content 3</p>
  </ixfx-panel>
</ixfx-panel-group>
```

By default, multiple panels can be open at the same time. Add `accordion` to restrict it to one open panel at a time:

```html
<ixfx-panel-group orientation="horizontal" accordion>
  <!-- panels -->
</ixfx-panel-group>
```

### Sticky headers

Panels in a group keep their titlebar pinned to the nearest scrolling ancestor while the panel is in view, so you don't lose track of which panel you're in. The titlebar stops sticking when the panel ends. Horizontal titlebars stick to the top, vertical titlebars to the left. Disable with `sticky-headers="false"`. A standalone `ixfx-panel` can opt in with `sticky-header`.

Sticking activates `overflow: clip` on the panel instead of `overflow: hidden`.

### Reordering

Set `allow-reorder` to let users rearrange panels by dragging their titlebars (pointer-only in v1; keyboard reorder is not included):

```html
<ixfx-panel-group orientation="vertical" allow-reorder>
  <ixfx-panel title="Panel 1">...</ixfx-panel>
  <ixfx-panel title="Panel 2">...</ixfx-panel>
</ixfx-panel-group>
```

Dragging starts anywhere on the titlebar except interactive chrome (buttons, toolbar slot, caret/close) — those controls always win over dragging. A drop-caret marks the insertion point and a floating ghost styled like the titlebar follows the pointer. Text selection is suppressed for the duration of the drag. Press <kbd>Esc</kbd> to abort a drag. The trailing click after a real reorder is swallowed so the panel doesn't also collapse/expand.

#### Events

| Event     | Detail                                          | Description                          |
|-----------|-------------------------------------------------|--------------------------------------|
| `reorder` | `{ fromIndex, toIndex, panel }`                 | Fired after panels are reordered     |

`fromIndex` / `toIndex` are positions in the group's real light-DOM `children` (which may include non-panel elements), not positions in the filtered panel list.

```js
group.addEventListener('reorder', e => {
  console.log('Moved from', e.detail.fromIndex, 'to', e.detail.toIndex);
});
```

### Group gap

The space between panels is controlled by the `--group-gap` CSS custom property, falling back to `var(--space-l)` when unset:

```css
ixfx-panel-group {
  --group-gap: var(--space-xl);
}
```

Alternatively set the `gap` property/attribute for the same effect (it mirrors its value into `--group-gap`).

### Content area styling

Inherited custom properties, so setting them on a group styles all its panels. To remove the inset effect or use your own:

```css
ixfx-panel-group {
  --panel-content-shadow: none;
  --panel-content-border: 1px solid var(--surface-4);
}
```


### Group-propagated properties

When you set `variant`, `toggle-interaction` or `collapsible` on the group, those values are automatically applied to all child panels that don't have an explicit value set. This simplifies declaration when all panels in a group share the same styling:

```html
<ixfx-panel-group variant="midline" toggle-interaction="explicit">
  <ixfx-panel title="Settings">...</ixfx-panel>
  <ixfx-panel title="Account">...</ixfx-panel>
  <ixfx-panel title="Help">...</ixfx-panel>
</ixfx-panel-group>
```

---

## TypeScript types

```ts
import type { PanelOrientation, PanelVariant, PanelToggleInteraction, PanelToggleDetail, PanelGroupOrientation, PanelGroupReorderDetail } from 'ixfxfun-components';
// Canonical titlebar types (Panel* are aliases):
import type { TitlebarOrientation, TitlebarVariant, TitlebarToggleInteraction, TitlebarToggleDetail } from 'ixfxfun-components';
```

---

## See also

- [`ixfx-titlebar`](./titlebar.md) — Standalone titlebar chrome composed by this panel
- [`ixfx-icon`](./icons.md) — Icon component used by panel
