Documentation navigation

Published API · 0.1.0-rc.1

foldkit-ui · tabs

Published foldkit-ui API declarations for tabs.

./tabs

@wsagency/wseffect-foldkit-ui · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES

This entry point is published in @wsagency/wseffect-foldkit-ui@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.

import * as Wseffect from '@wsagency/wseffect-foldkit-ui/tabs'

Exported declarations

ActivationMode

Controls whether tabs activate on focus (`Automatic`) or require an explicit selection (`Manual`).

ActivationMode: Schema.Literals<readonly ["Automatic", "Manual"]>

ActivationMode

export type ActivationMode = typeof ActivationMode.Type;

Bundle

The `view` and `update` pair that `Tabs.create` returns, bound to one `Value` type. Name it to annotate a value that holds a created bundle, such as a field on a config object or a function parameter that takes the bundle rather than calling `create` itself.

export type Bundle<Value extends string = string> = Readonly<{
    view: SubmodelView<Model, Message, ViewInputs<Value>>;
    update: (model: Model, message: Message) => Update.ReturnWithOutMessage<Model, Message, OutMessage<Value>>;
}>;

create

Pairs the tabs `view` and `update` behind a single Value-typed entry point. Declare once at module scope so consumers receive `tab.value: Value` in `toView` and the `Selected` OutMessage without an `as` cast: ```ts const DemoTabs = Tabs.create<DemoTab>() // In view (selectedValue is the parent-owned active tab): h.submodel({ view: DemoTabs.view, viewInputs: { selectedValue, ... }, ... }) // In the parent update, pass DemoTabs.update to Update.foldChild and // fold the Selected OutMessage into your Model. ``` The internal view stays typed `ReadonlyArray<string>`; consumers can pass a `ReadonlyArray<MyUnion>` (assignable) and the fenced cast inside `create` types `TabInfo.value` as `MyUnion`.

create: <Value extends string = string>() => Bundle<Value>

FocusedTab

export type FocusedTab = typeof Message.FocusedTab.Type;

FocusTab

Moves focus to the tab at the given index.

FocusTab: Command.CommandDefinitionWithArgs<"FocusTab", {
    id: Schema.String;
    index: Schema.Number;
}, Effect.Effect<{
    readonly _tag: "CompletedFocusTab";
}, never, never>>

init

Creates an initial tabs model from a config. Focus follows the selected tab until the user navigates in `Manual` mode, so `maybeFocusedIndex` starts `None`. Defaults to automatic activation.

init: (config: InitConfig) => Model

InitConfig

Configuration for creating a tabs model with `init`.

export type InitConfig = Readonly<{
    id: string;
    activationMode?: ActivationMode;
}>;

Message

export type Message = typeof Message.Type;

Message

Union of all messages the tabs component can produce.

Message: import("@wsagency/wseffect-foldkit/message").MessageUnion<{
    readonly SelectedTab: {
        index: Schema.Number;
        value: Schema.String;
    };
    readonly FocusedTab: {
        index: Schema.Number;
    };
    readonly CompletedFocusTab: {};
}>

Model

export type Model = typeof Model.Type;

Model

Schema for the tabs component's private interaction state. The active tab is owned by the parent and passed in via `ViewInputs.selectedValue`, so it is not stored here. `maybeFocusedIndex` is the roving-tabindex cursor: `None` means keyboard focus follows the selected tab, and `Manual` activation stores `Some(index)` while focus diverges from the selection.

Model: Schema.Struct<{
    readonly id: Schema.String;
    readonly maybeFocusedIndex: Schema.Option<Schema.Number>;
    readonly activationMode: Schema.Literals<readonly ["Automatic", "Manual"]>;
}>

Orientation

export type Orientation = typeof Orientation.Type;

Orientation

Controls the tab list layout direction and which arrow keys navigate between tabs.

Orientation: Schema.Literals<readonly ["Horizontal", "Vertical"]>

OutMessage

Generic over `Value extends string` so consumers using `Tabs.create<MyUnion>()` receive `value: MyUnion` in the `Selected` OutMessage. Defaults to `string`.

export type OutMessage<Value extends string = string> = Selected<Value>;

OutMessage

Union of OutMessages the tabs component can produce. The parent's `Update.foldChild` config handles them through `foldOutMessage`.

OutMessage: import("@wsagency/wseffect-foldkit/message").MessageUnion<{
    readonly Selected: {
        value: Schema.String;
        index: Schema.Number;
    };
}>

PanelMount

export type PanelMount = typeof PanelMount.Type;

PanelMount

Describes whether a consumer renders only the active tab panel or keeps every panel mounted and hides inactive ones. Tab-to-panel references follow the rendered panel strategy.

PanelMount: Schema.Literals<readonly ["ActiveOnly", "All"]>

RenderInfo

Render-time payload published to the consumer's `toView`. - `tablist`: ARIA + role attributes for the wrapping tablist element. - `tabs`: one entry per tab in `viewInputs.tabs`, in the same order, with the tab button's attribute bundle, the panel's attribute bundle, and derived state. - `activeIndex`: the index of `viewInputs.selectedValue` within `viewInputs.tabs`, convenient when the consumer wants to render only the active panel (vs all panels with `Hidden` for transitions).

export type RenderInfo<Value extends string = string> = Readonly<{
    tablist: ReadonlyArray<ChildAttribute>;
    tabs: ReadonlyArray<TabInfo<Value>>;
    activeIndex: number;
}>;

Selected

export type Selected<Value extends string = string> = Readonly<{
    readonly _tag: 'Selected';
    readonly value: Value;
    readonly index: number;
}>;

SelectedTab

export type SelectedTab = typeof Message.SelectedTab.Type;

TabInfo

Per-tab render info passed to the consumer's `toView`. Generic over `Value extends string`: when `Tabs.create<MyUnion>()` is declared, `tab.value` is typed `MyUnion` so the consumer can switch on it without casting.

export type TabInfo<Value extends string = string> = Readonly<{
    value: Value;
    index: number;
    isActive: boolean;
    isFocused: boolean;
    isDisabled: boolean;
    tab: ReadonlyArray<ChildAttribute>;
    panel: ReadonlyArray<ChildAttribute>;
}>;

ViewInputs

Per-render view inputs passed to `view` via `h.submodel`'s `viewInputs` field. Generic over `Value extends string` so consumers using `Tabs.create<MyUnion>()` receive `tab.value: MyUnion` in `toView` and `(value: MyUnion, index) => boolean` in `isTabDisabled`, without casting. - `selectedValue`: the active tab, read straight from the parent Model. `aria-selected`, the `data-selected` marker, and which panel is active all derive from it. - `panelMount`: defaults to `ActiveOnly`, where the consumer renders only the active panel. Set `All` when the consumer keeps every panel mounted and hides inactive ones, so every tab retains its panel relationship.

export type ViewInputs<Value extends string = string> = Readonly<{
    tabs: ReadonlyArray<Value>;
    selectedValue: Value;
    ariaLabel: string;
    toView: (render: RenderInfo<Value>) => Html;
    isTabDisabled?: (value: Value, index: number) => boolean;
    orientation?: Orientation;
    panelMount?: PanelMount;
}>;