# API of `@koobiq/components/actions-panel`

Documented on [Actions panel](https://koobiq.io/en/components/actions-panel.md). NgModule: `KbqActionsPanelModule`.

## Services

### KbqActionsPanel (service)

Service for opening actions panel.

```ts
@Injectable({ providedIn: 'root' })
class KbqActionsPanel {
    open<T, D = unknown, R = unknown>(
        component: ComponentType<T>,
        config?: KbqActionsPanelConfig<D>
    ): KbqActionsPanelRef<T, R>;
    open<T, D = unknown, R = unknown>(
        template: TemplateRef<T>,
        config?: KbqActionsPanelConfig<D>
    ): KbqActionsPanelRef<T, R>;
    close<R>(result?: R): void;
}
```

- `open()`: `KbqActionsPanelRef<T, R>` — Opens actions panel.
  - `config`: `KbqActionsPanelConfig<D>` — Additional configuration options for the actions panel.
  - returns `KbqActionsPanelRef<T, R>` — A reference to the opened actions panel.
- `close()`: `void` — Closes the currently opened actions panel.

## Classes

### KbqActionsPanelConfig (class)

Configuration for opened actions panel.
Based on cdk `DialogConfig`.

```ts
class KbqActionsPanelConfig<D = unknown> {
    injector?: Injector;
    data?: D | null;
    containerClass?: string | string[];
    closeOnNavigation?: boolean;
    overlayContainer?: ElementRef<HTMLElement>;
    overlayPanelClass?: string | string[];
    width?: string;
    minWidth?: number | string;
    maxWidth?: number | string;
    direction?: Direction;
    scrollStrategy?: (overlay: Overlay) => ScrollStrategy;
    disableClose?: boolean;
}
```

- `injector?`: `Injector` — Injector used for the instantiation of the component to be attached.
- `data?`: `D | null` — Data being injected into the child component with `KBQ_ACTIONS_PANEL_DATA`.
- `containerClass?`: `string | string[]` — Extra CSS classes to be added to the actions panel container.
- `closeOnNavigation?`: `boolean` — Whether the actions panel should be closed of when the user goes backwards/forwards in history.
  Defaults to `true`.
  NOTE! This does not apply to router navigation.
- `overlayContainer?`: `ElementRef<HTMLElement>` — Element the actions panel overlay is rendered into, instead of the application-wide overlay container. The panel
  is pinned to the bottom center of that element and resizes with it. An element that sets `overflow: hidden`
  clips it; at the default `overflow: visible` the entrance animation renders it below the element.

  The element is mutated for as long as the panel is open: it gains one child node holding the overlay, and a
  `static` element is promoted to `position: relative`, since the overlay is positioned against it.

  NOTE: the panel bypasses a globally provided `OverlayContainer` while this is set.
- `overlayPanelClass?`: `string | string[]` — Extra CSS classes to be added to the overlay panel.
- `width?`: `string` — Width of the actions panel.
- `minWidth?`: `number | string` — Min-width of the actions panel.
  If a number is provided, assumes pixel units.
- `maxWidth?`: `number | string` — Max-width of the actions panel.
  If a number is provided, assumes pixel units.

  When omitted, the panel is capped by the width of the overlay container it is rendered into.
- `direction?`: `Direction` — Direction of the text in the actions panel. Defaults to `'ltr'`.
- `scrollStrategy?`: `(overlay: Overlay) => ScrollStrategy` — Scroll strategy to be used for the actions panel. Defaults to `RepositionScrollStrategy`.
- `disableClose?`: `boolean` — Whether the user can use ESC or click on close button to close the actions panel. Defaults to `false`.

### KbqActionsPanelRef (class)

Reference to actions panel opened by `KbqActionsPanel` service.

```ts
class KbqActionsPanelRef<I = unknown, R = unknown> {
    readonly keydownEvents: Observable<KeyboardEvent>;
    readonly beforeOpened: Observable<void>;
    readonly afterOpened: Observable<void>;
    readonly beforeClosed: Observable<R | undefined>;
    readonly afterClosed: Observable<R | undefined>;
    constructor(
        dialogRef: DialogRef<R, I>,
        containerInstance: KbqActionsPanelContainer
    );
    close(result?: R): void;
}
```

- `keydownEvents`: `Observable<KeyboardEvent>` — Emits when keydown events are targeted on the overlay.
- `beforeOpened`: `Observable<void>` — Emits when the actions panel starts opening, before its entrance animation plays.
- `afterOpened`: `Observable<void>` — Emits when the actions panel has opened and appeared, or once closing cuts its entrance short.
- `beforeClosed`: `Observable<R | undefined>` — Emits when the actions panel starts closing, before its exit animation plays.
- `afterClosed`: `Observable<R | undefined>` — Emits when the actions panel is finished closing.
- `close()`: `void` — Closes the actions panel.

## Types

### KbqActionsPanelTemplateContext (type)

Context for actions panel template.

```ts
type KbqActionsPanelTemplateContext<T = unknown, D = unknown, R = unknown> = {
    $implicit?: D | null;
    data?: D | null;
    actionsPanelRef: KbqActionsPanelRef<T, R>;
};
```

- `$implicit?`: `D | null` — Data passed to actions panel.

  Example:

  ```html
  <ng-template #actionsPanel let-data>{{ data.KEY }}</ng-template>
  ````
- `data?`: `D | null` — Data passed to actions panel.

  Example:

  ```html
  <ng-template #actionsPanel let-data="data">{{ data.KEY }}</ng-template>
  ````
- `actionsPanelRef`: `KbqActionsPanelRef<T, R>` — Opened actions panel reference.

  Example:

  ```html
  <ng-template #actionsPanel let-actionsPanelRef="actionsPanelRef">
    <button (click)="actionsPanelRef.close()">close</button>
  </ng-template>
  ````

## Constants

### KBQ_ACTIONS_PANEL_DATA (const)

Injection token that can be used to access the data that was passed in to actions panel.

```ts
const KBQ_ACTIONS_PANEL_DATA: InjectionToken<unknown>;
```

### KBQ_ACTIONS_PANEL_DEFAULT_CONFIG (const)

Injection token that can be used to specify default actions panel config.

```ts
const KBQ_ACTIONS_PANEL_DEFAULT_CONFIG: InjectionToken<KbqActionsPanelConfig>;
```

### KBQ_ACTIONS_PANEL_LOCALE_CONFIGURATION (const)

Localization configuration provider.

```ts
const KBQ_ACTIONS_PANEL_LOCALE_CONFIGURATION: InjectionToken<KbqActionsPanelLocaleConfiguration>;
```

### kbqActionsPanelDefaultConfigProvider (const)

Utility for providing default actions panel config through `KBQ_ACTIONS_PANEL_DEFAULT_CONFIG`.

```ts
const kbqActionsPanelDefaultConfigProvider: <D>(
    config: KbqActionsPanelConfig<D>
) => Provider;
```

### kbqActionsPanelLocaleConfigurationProvider (const)

Utility provider for `KBQ_ACTIONS_PANEL_LOCALE_CONFIGURATION`. Only the strings you pass are
overridden; the rest keep following the active locale.

```ts
const kbqActionsPanelLocaleConfigurationProvider: (
    configuration: KbqDeepPartial<KbqActionsPanelLocaleConfiguration>
) => Provider;
```
