# Panel

A titled container with optional header actions and footer that can collapse its body. Use it for dashboard sections and settings groups that users may want to fold away.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-panel`, `[vigPanelActions]`, `[vigPanelFooter]`
- Source: [libs/ui/src/lib/molecules/panel/panel.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/panel/panel.ts)

```typescript title="Import"
import { Panel, PanelActions, PanelFooter } from '@vigdx/ui/panel';
```

## Basic

`heading` renders a real heading; `[vigPanelActions]` content sits beside it and `[vigPanelFooter]` content below the body.

```typescript title="panel-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Button, ButtonIcon } from '@vigdx/ui/button';
import { Icon } from '@vigdx/ui/icon';
import { Panel, PanelActions, PanelFooter } from '@vigdx/ui/panel';

@Component({
  selector: 'app-panel-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Panel, PanelActions, PanelFooter, Button, ButtonIcon, Icon],
  template: `
    <vig-panel heading="Recent activity" class="w-full max-w-xl">
      <vig-button vigPanelActions variant="ghost" size="sm" ariaLabel="More actions">
        <vig-icon vigButtonIcon name="more-horizontal" />
      </vig-button>
      Three orders shipped and one was returned since yesterday.
      <div vigPanelFooter>
        <vig-button label="View all" variant="secondary" size="sm" />
      </div>
    </vig-panel>
  `,
})
export class PanelBasicDemo {}
```

## Collapsible

`collapsible` turns the heading into a disclosure button; `[(collapsed)]` holds the state, so it can be preset or changed from outside. `headingLevel` (2–6, default 3) fits the heading into the page outline.

```typescript title="panel-collapsible.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Panel } from '@vigdx/ui/panel';

@Component({
  selector: 'app-panel-collapsible',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Panel, Button],
  template: `
    <div class="flex w-full max-w-xl flex-col gap-3">
      <vig-panel heading="Filters" [headingLevel]="3" collapsible [(collapsed)]="collapsed">
        Status, owner and date range filters.
      </vig-panel>
      <vig-button
        variant="secondary"
        size="sm"
        [label]="collapsed() ? 'Expand filters' : 'Collapse filters'"
        (click)="collapsed.set(!collapsed())"
      />
    </div>
  `,
})
export class PanelCollapsibleDemo {
  readonly collapsed = signal(false);
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="panel"][data-part="root"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="panel"]`

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The `vig-panel` host. | `open, closed` |
| `header` | The header row: heading and `[vigPanelActions]`. |   |
| `heading` | The `h2`–`h6` of `heading`. |   |
| `trigger` | The disclosure button of a `collapsible` panel (`aria-expanded`). | `open, closed` |
| `indicator` | The chevron of the trigger. |   |
| `label` | The heading text inside the trigger. |   |
| `actions` | Wrapper of the `[vigPanelActions]` slot. |   |
| `content` | The collapsible part: body and footer (`hidden="until-found"` while collapsed); `data-state` only when collapsible. | `open, closed` |
| `body` | The padded body. |   |
| `footer` | Wrapper of the `[vigPanelFooter]` slot. |   |

## Accessibility

- The heading is a native `<h2>`–`<h6>`; when collapsible, a `<button>` inside it carries `aria-expanded` and `aria-controls`, so heading navigation still finds the panel. Header actions are separate buttons next to it, never inside it.
- Not a native `<details>`: a `<summary>` cannot hold a heading (screen readers drop it) or the action buttons.
- A collapsed body (with its footer) stays in the DOM as `hidden="until-found"`: skipped by screen readers and the tab order, but find-in-page and text-fragment links reveal it, which expands the panel. Where `interpolate-size` is supported the height animates, except with reduced motion.

## API

### Panel

Selector: `vig-panel` · Kind: component

A titled container: a `heading` (a real `h2`–`h6`, `headingLevel`), header actions (`[vigPanelActions]`), the projected body and a footer (`[vigPanelFooter]`).

**Example :**

```html
<vig-panel heading="Activity" collapsible [(collapsed)]="closed">
  <vig-button vigPanelActions variant="ghost" ariaLabel="Refresh">…</vig-button>
  Recent events…
</vig-panel>
```

`collapsible` turns the heading into a disclosure button (inside the heading, so heading navigation still finds it) with `aria-expanded` and `aria-controls`; the actions stay outside it. A collapsed body stays in the DOM as `hidden="until-found"`: find-in-page and text-fragment links reveal it, which expands the panel (browsers without `until-found` treat it as plain `hidden`). Not a native `<details>`: a `summary` cannot hold the heading or the action buttons.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `collapsed` (model) | `boolean` | `false` | Whether the body is collapsed; two-way bindable. Ignored unless `collapsible`. |
| `collapsible` | `boolean` | `false` | Turns the heading into a button that collapses and expands the body. |
| `heading` | `string \| undefined` | `undefined` | Title text, rendered as a real heading. Needed for `collapsible`. |
| `headingLevel` | `PanelHeadingLevel` | `3` | Level of the `h2`–`h6` heading. |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `collapsedChange` | `boolean` | Whether the body is collapsed; two-way bindable. Ignored unless `collapsible`. |

#### Methods

| Signature | Description |
| --- | --- |
| `toggle(): void` | Collapses an expanded panel or expands a collapsed one. |

### Templates and directives

| Selector | Export | Description |
| --- | --- | --- |
| `[vigPanelActions]` | `PanelActions` | Marks projected content as the panel's header actions (buttons beside the heading). |
| `[vigPanelFooter]` | `PanelFooter` | Marks projected content as the panel's footer (collapses with the body). |
