On this pageFunctions
Ui/Tabs
/**
* Creates a completed Tabs Block refined to one Value type. Declare
* `Tabs.create<DemoTab>()` once at module scope, then connect that Block to
* the parent. Its view inputs and `Selected.value` share the Value type;
* the parent Model owns the active tab.
*/
<Value extends string = string>(): Completed<Value>/** Configuration for creating a tabs model with `init`. */
type InitConfig = Readonly<{
activationMode: ActivationMode
id: string
}>/**
* 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).
*/
type RenderInfo = Readonly<{
activeIndex: number
tablist: ReadonlyArray<ChildAttribute>
tabs: ReadonlyArray<TabInfo<Value>>
}>/**
* 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.
*/
type TabInfo = Readonly<{
index: number
isActive: boolean
isDisabled: boolean
isFocused: boolean
panel: ReadonlyArray<ChildAttribute>
tab: ReadonlyArray<ChildAttribute>
value: Value
}>/**
* Per-render view inputs passed to `view` via `h.block`'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.
*/
type ViewInputs = Readonly<{
ariaLabel: string
isTabDisabled: (value: Value, index: number) => boolean
orientation: Orientation
panelMount: PanelMount
selectedValue: Value
tabs: ReadonlyArray<Value>
toView: (render: RenderInfo<Value>) => Html
}>/** A completed Tabs Block refined to one Value type. */
interface Completed {
[CompletionTypeId]: true
[DefaultViewTypeId]: OwnedAuthoredView<BlockView<{
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, AuthoredViewInputs<Readonly<{
ariaLabel: string
isTabDisabled: (value: Value, index: number) => boolean
orientation: "Horizontal" | "Vertical"
panelMount: "ActiveOnly" | "All"
selectedValue: Value
tabs: readonly Array<Value>
toView: (render: RenderInfo<Value>) => Html
}>>, never>, Owner<"Tabs", true>, {
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, never>
bindings: readonly []
EffectsLayer: CompleteEffectsLayer<Layer<Handler<"Tabs/FocusTab", {
id: string
index: number
}, {
_tag: "CompletedFocusTab"
}>, never, never>, readonly []>
hostHandlers: readonly []
init: (args: [
config: Readonly<{
activationMode: "Automatic" | "Manual"
id: string
}>
]) => Return<{
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, never>
makeView: DefineView<Owner<"Tabs", true>, {
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, never>
managedResources: Readonly<Record<never, never>>
Message: MessageUnion
Model: Struct
mounts: readonly Array<never>
operations: ImplementationExposedOperations<ImplementationValue>
OutMessage: MessageUnion
provideHandlers: never
replaceEffectsLayer: ReplaceEffectsLayer<Owner<"Tabs", true>, Struct<{
activationMode: Literals<readonly ["Automatic", "Manual"]>
id: String
maybeFocusedIndex: Option<Number>
}>, MessageUnion<{
CompletedFocusTab: {}
FocusedTab: {
index: Number
}
SelectedTab: {
index: Number
value: String
}
}>, MessageUnion<Omit<{
Selected: {
index: Number
value: String
}
}, "Selected"> & Readonly<{
Selected: Omit<{
index: Number
value: String
}, "value"> & Readonly<{
value: Schema<Value>
}>
}>>, readonly [], readonly [], Readonly<{
EffectsLayer: Layer<Handler<"Tabs/FocusTab", {
id: string
index: number
}, {
_tag: "CompletedFocusTab"
}>, never, never>
init: (args: [
config: Readonly<{
activationMode: "Automatic" | "Manual"
id: string
}>
]) => Return<{
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, never>
update: (message: {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}) => (model: {
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, context: readonly []) => ReturnWithOutMessage<{
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, Readonly<{
_tag: "Selected"
index: number
value: Value
}>, Handler<"Tabs/FocusTab", {
id: string
index: number
}, {
_tag: "CompletedFocusTab"
}>>
view: OwnedAuthoredView<BlockView<{
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, AuthoredViewInputs<Readonly<{
ariaLabel: string
isTabDisabled: (value: Value, index: number) => boolean
orientation: "Horizontal" | "Vertical"
panelMount: "ActiveOnly" | "All"
selectedValue: Value
tabs: readonly Array<Value>
toView: (render: RenderInfo<Value>) => Html
}>>, never>, Owner<"Tabs", true>, {
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, never>
}>>
subscriptions: Readonly<Record<never, never>>
update: (message: {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}) => (model: {
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, context: readonly []) => ReturnWithOutMessage<{
activationMode: "Automatic" | "Manual"
id: string
maybeFocusedIndex: Option<number>
}, {
_tag: "SelectedTab"
index: number
value: string
} | {
_tag: "FocusedTab"
index: number
} | {
_tag: "CompletedFocusTab"
}, Readonly<{
_tag: "Selected"
index: number
value: Value
}>, Handler<"Tabs/FocusTab", {
id: string
index: number
}, {
_tag: "CompletedFocusTab"
}>>
}/** Controls whether tabs activate on focus (`Automatic`) or require an explicit selection (`Manual`). */
const ActivationMode: Literals<readonly ["Automatic", "Manual"]>