ActivationMode
Controls whether tabs activate on focus (`Automatic`) or require an explicit selection (`Manual`).
ActivationMode: Schema.Literals<readonly ["Automatic", "Manual"]>Effect-native UI toolkit
Interactive demosPublished API · 0.1.0-rc.1
Published foldkit-ui API declarations for 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'ActivationModeControls whether tabs activate on focus (`Automatic`) or require an explicit selection (`Manual`).
ActivationMode: Schema.Literals<readonly ["Automatic", "Manual"]>ActivationModeexport type ActivationMode = typeof ActivationMode.Type;BundleThe `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>>;
}>;createPairs 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>FocusedTabexport type FocusedTab = typeof Message.FocusedTab.Type;FocusTabMoves 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>>initCreates 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) => ModelInitConfigConfiguration for creating a tabs model with `init`.
export type InitConfig = Readonly<{
id: string;
activationMode?: ActivationMode;
}>;Messageexport type Message = typeof Message.Type;MessageUnion 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: {};
}>Modelexport type Model = typeof Model.Type;ModelSchema 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"]>;
}>Orientationexport type Orientation = typeof Orientation.Type;OrientationControls the tab list layout direction and which arrow keys navigate between tabs.
Orientation: Schema.Literals<readonly ["Horizontal", "Vertical"]>OutMessageGeneric 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>;OutMessageUnion 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;
};
}>PanelMountexport type PanelMount = typeof PanelMount.Type;PanelMountDescribes 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"]>RenderInfoRender-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;
}>;Selectedexport type Selected<Value extends string = string> = Readonly<{
readonly _tag: 'Selected';
readonly value: Value;
readonly index: number;
}>;SelectedTabexport type SelectedTab = typeof Message.SelectedTab.Type;TabInfoPer-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>;
}>;ViewInputsPer-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;
}>;