Mixins / foldkit-mixins-ui

Tabs

namespace · packages/mixins-ui/src/tabs.ts:1

export * as Tabs from './tabs.js'

In the guides

Members

Tabs.closing

function · packages/mixins-ui/src/tabs.ts:79

function closing<Value extends string>(
  tabs: ReadonlyArray<Value>,
  selected: Value,
  value: Value,
): {
  readonly tabs: ReadonlyArray<Value>
  readonly selected: Option.Option<Value>
  readonly focus: Option.Option<number>
}

What closing value leaves, as the APG asks: the tabs without it, the tab chosen after (the one after it, or before it at the end, when it was the chosen one; none once no tab is left), and the index to focus, the tab that followed it. Focus it with @foldkit/ui's FocusTab: the focused tab was taken from the page. A value not among tabs changes nothing and focuses none.

Tabs.configure

function · packages/mixins-ui/src/tabs.ts:288

function configure<const Names extends string = never>(
  config: Presets<TabsPreset, Names>,
): {
  readonly view: <Outer>(
    options: TabsView<Outer> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own Tabs: base for every use, presets chosen at a use with preset, and the call over both.

Tabs.conflict

function · packages/mixins-ui/src/tabs.ts:118

function conflict<Value extends string, Message>(
  routes: ReadonlyArray<Route<Value, Message>>,
  input?: Pick<TabsContext<Value, unknown, Message>, 'close'>,
): Option.Option<Diagnostic>

The mixins:key-conflict that resolving the tabs with routes would throw, or none: the application's routes against Delete, which a closable tab takes (close is the one the tabs are given), and against each other.

Tabs.fluid

const · packages/mixins-ui/src/tabs/fluid.ts:16

const fluid: readonly [Mixin<never>, Mixin<never>, Mixin<never>]

What moves the indicator and highlight: on the tablist, the chosen tab is measured (--fk-tabs-chosen-x, -y, -w, -h, -display) and one highlight follows the pointer to the nearest tab (--fk-tabs-hover-*), growing out of the chosen tab and returning to it. Pass them beside the style; until they run (before a page hydrates, or without them), each tab marks itself and the drawn indicator and highlight show nothing.

Tabs.readingKeys

const · packages/mixins-ui/src/tabs/readingKeys.ts:14

const readingKeys: Mixin<never>

Arrow keys read by the direction the tablist is drawn in: right to left, ArrowLeft goes to the next tab, as the APG asks. Upstream's keys know no direction, and its bundles no view option reaches, so this is a Mount (ReadingKeys) that reads the key before upstream's handler does. Pass it beside the style where the page may be right to left. It is not built in because a Scene test must resolve every Mount with a Message, and this one has none to give.

Tabs.resolve

function · packages/mixins-ui/src/tabs.ts:125

function resolve<Value extends string, Input, Message>(
  render: RenderInfo<Value>,
  mixins: MixinList<Message>,
  context: TabsContext<Value, Input, Message>,
): ResolvedTabs<Value, Message>

Resolves the tabs' nested render groups, preserving activeIndex.

Tabs.ResolvedTab

type · packages/mixins-ui/src/tabs.ts:15

type ResolvedTab<Value extends string, Message> = Omit<
  TabInfo<Value>,
  'tab' | 'panel'
> & {
  readonly item: SlotAttributes<Message>
  readonly tab: SlotAttributes<Message>
  readonly panel: SlotAttributes<Message>
  readonly close: Option.Option<SlotAttributes<Message>>
}

Tabs.ResolvedTabs

interface · packages/mixins-ui/src/tabs.ts:24

interface ResolvedTabs<Value extends string, Message> {
  readonly root: SlotAttributes<Message>
  readonly tablist: SlotAttributes<Message>
  readonly indicator: SlotAttributes<Message>
  readonly highlight: SlotAttributes<Message>
  readonly label: SlotAttributes<Message>
  readonly icon: SlotAttributes<Message>
  readonly tabs: ReadonlyArray<ResolvedTab<Value, Message>>
  readonly activeIndex: number
}

Tabs.Route

type · packages/mixins-ui/src/tabs.ts:54

type Route<Value extends string, Message> = Behaviors.Keys.Route<
  TabInfo<Value>,
  Message
>

A key the application answers on a tab; its input is the tab.

Tabs.TabsClose

interface · packages/mixins-ui/src/tabs.ts:47

interface TabsClose<Value extends string, Message> {
  readonly onClose: (value: Value) => Message
  readonly label?: ((value: Value) => string) | undefined
}

Closable tabs, as the APG's tabs with deletion: Delete on a tab sends onClose, and so does a press on its close button. The button is no tab stop and hidden from assistive technology, since a tablist holds tabs alone; the tab names the key in aria-keyshortcuts. Answer onClose with closing.

Tabs.TabsContext

interface · packages/mixins-ui/src/tabs.ts:56

interface TabsContext<
  Value extends string,
  Input,
  Message,
> extends ResolveContext<Input, Message> {
  readonly close?: TabsClose<Value, Message> | undefined
  readonly routes?: ReadonlyArray<Route<Value, NoInfer<Message>>> | undefined
}

Tabs.TabsPreset

type · packages/mixins-ui/src/tabs.ts:280

type TabsPreset = Pick<TabsView<never>, 'style' | 'orientation'> & {
  readonly mixins?: MixinList<never>
}

What Tabs are given once: their look and mixins. The Model, rows and value are each use's.

Tabs.TabsRow

interface · packages/mixins-ui/src/tabs.ts:183

interface TabsRow {
  readonly value: string
  readonly label: string
  readonly icon?: Html | undefined
  readonly trailing?: Html | undefined
  readonly disabled?: boolean | undefined
  readonly panel?: Html | undefined
}

One tab of Tabs.view: its words, what stands beside them, and the panel it shows.

Tabs.TabsSlots

const · packages/mixins-ui/src/tabs/slots.ts:19

const TabsSlots: Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly tablist: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"role">], readonly Slot.RequirementName[], boolean>; readonly item: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly tab: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">, Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-selected">, Attr.AttrToken<"disabled">, Attr.AttrToken<"aria-disabled">], readonly Slot.RequirementName[], boolean>; readonly label: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly icon: Slot. …;

Tabs is a nested Submodel: one tablist group plus a tab/panel pair per item, so the resolver runs once per group and each base ChildAttribute bundle passes through by identity.

Enabled tabs own click through the base OnClick; a Behavior adding its own click handler is a conflict rather than a second silent owner. Disabled tabs publish no click, so the contract still lists it as allowed.

indicator and highlight have no upstream bundle: they are this package's, drawn first in the tablist, for the marker under the chosen tab and the hover that follows the pointer, which fluid moves. So are the rest: item holds a tab and its close button side by side (a button in a button is not allowed), and label and icon are the tab's words, trimmed in a box of their own, and a mark before them.

Tabs.TabsView

interface · packages/mixins-ui/src/tabs.ts:196

interface TabsView<Message> {
  readonly model: UiTabs.Model
  readonly onMessage: (message: UiTabs.Message) => Message
  readonly label: string
  readonly tabs: ReadonlyArray<TabsRow>
  readonly value: string
  readonly orientation?: 'horizontal' | 'vertical' | undefined
  readonly close?: TabsClose<string, NoInfer<Message>> | undefined
  readonly routes?: ReadonlyArray<Route<string, NoInfer<Message>>> | undefined
  readonly style?: NamedStyle<typeof TabsSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
}

Tabs.toView

function · packages/mixins-ui/src/tabs.ts:173

function toView<Value extends string, Message>(
  mixins: MixinList<Message>,
  context: TabsContext<Value, unknown, Message>,
  draw: (resolved: ResolvedTabs<Value, Message>) => Html,
): (render: RenderInfo<Value>) => Html

The tabs' toView: draw receives their bundles with mixins applied.

Tabs.view

function · packages/mixins-ui/src/tabs.ts:224

function view<Message>(
  options: TabsView<Message>,
  h: HtmlBuilder<Message>,
): Html

Tabs in one call: the tablist with each row's mark, words and trailing, and the chosen row's panel below it. The tabs' focus is the Model's (Bundles.Tabs), the chosen value the application's.