# API of `@koobiq/components/splitter`

Documented on [Splitter](https://koobiq.io/en/components/splitter.md). NgModule: `KbqSplitterModule`.

## Components

### KbqSplitter (component)

Splits an area into panels the user can resize by dragging the separators between them.

Panels must be direct children of the splitter — a wrapper element around them hides them from the group.

```html
<kbq-splitter>
    <kbq-splitter-panel [minSize]="100">…</kbq-splitter-panel>
    <kbq-splitter-panel>…</kbq-splitter-panel>
</kbq-splitter>
```

```ts
@Component({ selector: 'kbq-splitter', exportAs: 'kbqSplitter' })
class KbqSplitter implements KbqSplitterGroup {
    readonly orientation = input<KbqSplitterOrientation>('horizontal');
    readonly appearance = input<KbqSplitterAppearance>(
        this.options.appearance
    );
    readonly disabled = input<boolean>(false);
    readonly layout = model<number[] | null>(null);
}
```

- `[orientation]`: `KbqSplitterOrientation` — Direction the panels are laid out in.
- `[appearance]`: `KbqSplitterAppearance` — How the separators are drawn. Defaults to the app-wide `KBQ_SPLITTER_OPTIONS`.
- `[disabled]`: `boolean` — Whether the panels can be resized at all.
- `[(layout)]`: `number[] | null` — Sizes of the panels as percentages of the splitter, in panel order.

  Two-way and, while `null`, derived from what the panels declare — so a host reads it to persist a
  layout, writes it to restore one, and shares the same signal between two splitters to keep their panels
  the same width. Setting it back to `null` returns the panels to their declared sizes.

### KbqSplitterPanel (component)

A resizable region of a `KbqSplitter`.

Every panel but the last renders the separator that follows it, so the separator sits between the two
panels it resizes in the tab order as well as on screen.

```ts
@Component({ selector: 'kbq-splitter-panel', exportAs: 'kbqSplitterPanel' })
class KbqSplitterPanel implements KbqSplitterPanelRef {
    readonly id = input<string>(
        inject(_IdGenerator).getId('kbq-splitter-panel-')
    );
    readonly size = input<KbqSplitterSize | undefined>();
    readonly minSize = input<KbqSplitterSize | undefined>();
    readonly maxSize = input<KbqSplitterSize | undefined>();
    readonly snapSizes = input<readonly KbqSplitterSize[]>([]);
    readonly snapTolerance = input<number>(this.options.snapTolerance);
    readonly collapsible = input<boolean>(false);
    readonly collapsedSize = input<KbqSplitterSize>(0);
    readonly collapsed = model<boolean>(false);
    readonly separatorAriaLabel = input<string | undefined>();
}
```

- `[id]`: `string` — Identifies the panel to the `aria-controls` of its own separator, and gives a host something to point
  `aria-labelledby` or a fragment link at. Generated when omitted.
- `[size]`: `KbqSplitterSize | undefined` — Size the panel starts at, in pixels (`240`, `'240px'`), as a share of the splitter (`'30%'`) or as a share
  of the viewport (`'30vw'`, `'30vh'`). Panels that leave it unset share whatever the sized ones did not claim.
- `[minSize]`: `KbqSplitterSize | undefined` — Smallest size the panel may be dragged to. Defaults to `0`.
- `[maxSize]`: `KbqSplitterSize | undefined` — Largest size the panel may be dragged to. Unbounded when omitted.
- `[snapSizes]`: `readonly KbqSplitterSize[]` — Sizes a drag is pulled onto when it is released near one. `minSize` and `maxSize` become snap points too
  as soon as either panel around a separator declares any snap size.

  The layout the panels start at settles onto them as well, so a splitter is never handed to the user
  sitting between two of its own snap points.
- `[snapTolerance]`: `number` — How close to one of this panel's `snapSizes` a drag has to be released for it to be pulled in, in
  pixels. Raise it to make the snap points reach further — past half the gap between two of them the panel
  can only ever land on a snap size.

  Defaults to the app-wide `KBQ_SPLITTER_OPTIONS`.
- `[collapsible]`: `boolean` — Whether dragging the panel past half of its `minSize` collapses it to `collapsedSize` instead of
  stopping at the minimum.
- `[collapsedSize]`: `KbqSplitterSize` — Size the panel takes while collapsed. `0` — the default — hides it completely.
- `[(collapsed)]`: `boolean` — Whether the panel is collapsed. Two-way, so a host can collapse and restore the panel itself — which is
  the only way back for a panel whose `collapsedSize` is `0` and which therefore has no separator to grab.
- `[separatorAriaLabel]`: `string | undefined` — Accessible name of the separator that follows the panel; falls back to the localized default.

## Functions

### kbqSplitterOptionsProvider (function)

Overrides the default splitter options within the given injector scope — the whole application from
`bootstrapApplication`, or one subtree from the `providers` of a component or a route.

```ts
function kbqSplitterOptionsProvider(
    options: Partial<KbqSplitterOptions>
): Provider;
```

### resizeSplitterSizesAt (function)

Moves the boundary that follows `index` by `delta` pixels and returns the new sizes.

The panels on one side of the boundary take the delta and the ones on the other side give it up, each walking
outwards from the boundary: a panel sitting at its limit hands the remainder to the next one instead of
stopping the drag. Walking outwards on the taking side too is what keeps a boundary reachable when the panel
right beside it is pinned — otherwise a neighbour at its maximum would freeze a boundary that the panels
further out could still move, and the drag would do nothing at all.

```ts
function resizeSplitterSizesAt(
    sizes: readonly number[],
    index: number,
    delta: number,
    min: readonly number[],
    max: readonly number[]
): number[];
```

## Types

### KbqSplitterAppearance (type)

How a splitter draws its separators.

- `divider` — a line between the panels, the default.
- `transparent` — nothing until the pointer reaches the separator, which then gives itself away by the cursor.
- `handle` — a grip centred on the boundary.

```ts
type KbqSplitterAppearance = 'divider' | 'transparent' | 'handle';
```

### KbqSplitterOptions (type)

Settings a whole application shares, rather than something a single splitter decides.

Only what a product picks once belongs here: how its separators look, and how far a snap size reaches. The
sizes and limits of the panels are a property of one layout and stay on the panels themselves.

```ts
type KbqSplitterOptions = {
    appearance: KbqSplitterAppearance;
    snapTolerance: number;
};
```

- `appearance`: `KbqSplitterAppearance` — How the separators are drawn.
- `snapTolerance`: `number` — How close to a snap size a drag has to be released for it to be pulled in, in pixels.

### KbqSplitterOrientation (type)

Direction the panels of a splitter are laid out in.

```ts
type KbqSplitterOrientation = 'horizontal' | 'vertical';
```

### KbqSplitterSize (type)

Size of a splitter panel: a number of pixels, a `<number>px` string, a `<number>%` share of the splitter's own
size along the resize axis, or a `<number>vw` / `<number>vh` share of the viewport's width / height. A size in
any other unit is ignored.

```ts
type KbqSplitterSize = number | string;
```

### KbqSplitterSnapPoint (type)

A size a drag is pulled onto, with the distance the release has to be within for the pull to happen.

```ts
type KbqSplitterSnapPoint = {
    size: number;
    tolerance: number;
};
```

## Constants

### KBQ_SPLITTER_OPTIONS (const)

Injection token holding the current `KbqSplitterOptions`.

```ts
const KBQ_SPLITTER_OPTIONS: InjectionToken<KbqSplitterOptions>;
```
