# API of `@koobiq/components/sidebar`

Documented on [Sidebar](https://koobiq.io/en/components/sidebar.md). NgModule: `KbqSidebarModule`.

## Components

### KbqSidebar (component)

```ts
@Component({ selector: 'kbq-sidebar', exportAs: 'kbqSidebar' })
class KbqSidebar {
    opened = input<boolean | undefined>();
    readonly position = input<SidebarPositions>();
    readonly stateChanged = output<boolean>();
    get hasSavedState(): boolean;
    saveState(): void;
    clearSavedState(): void;
    toggle(): void;
}
```

- `[useStateSaving]`: `boolean` — Whether the component remembers its state across reloads and restores it on the next render.
  Defaults to `true`, or to whatever `KBQ_STATE_SAVING_ENABLED` is provided as.
- `[stateSavingKey]`: `string` — The key the state is persisted under. While it is empty the key is derived from where the
  component sits in the document, which moves when the surrounding markup is restructured — an `id`
  on the component or any ancestor pins it just as well as this input does.
- `hasSavedState`: `boolean` — Whether state is currently persisted for this sidebar — restored on init, or written since.
  Always `false` while `useStateSaving` is unset, and `false` again after `clearSavedState()`.
- `saveState()`: `void` — Persists whether the sidebar is open and the width it was last left at.

  Called whenever `opened` changes. The width is only captured as the sidebar closes, so dragging it
  wider and reloading without closing it keeps the previous width — the same as before persistence.
- `clearSavedState()`: `void` — Removes the state persisted for this sidebar.

  Persistence itself stays on — the next change is written again. Unset `useStateSaving` to stop it.

## Directives

### KbqSidebarClosed (directive)

```ts
@Directive({ selector: '[kbq-sidebar-closed]', exportAs: 'kbqSidebarClosed' })
class KbqSidebarClosed {
    readonly width = input<string>();
}
```

### KbqSidebarOpened (directive)

```ts
@Directive({ selector: '[kbq-sidebar-opened]', exportAs: 'kbqSidebarOpened' })
class KbqSidebarOpened {
    readonly minWidth = input<string>();
    readonly width = input<string>();
    readonly maxWidth = input<string>();
}
```

## Types

### KbqSidebarState (interface)

The persisted state of a sidebar — whether it was open, and the width it was last left at.

```ts
interface KbqSidebarState {
    opened: boolean;
    width?: string;
}
```

- `width?`: `string` — Absent while the sidebar has never been resized away from the width its content declares.

## Enums

### SidebarPositions (enum)

```ts
enum SidebarPositions {
    Left = 'left',
    Right = 'right'
}
```
