Mixins / foldkit-mixins-ui

Segmented

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

export * as Segmented from './segmented.js'

In the guides

Members

Segmented.configure

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

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

The application's own Segmented: base for every use, presets chosen at a use with preset, and the call over both. mixins concatenate in that order (Segmented.fluid goes in base); any other option given at the call replaces the preset's.

Segmented.fluid

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

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

What moves the indicator and highlight, on the group: the pressed option is measured (--fk-segmented-chosen-*) and one highlight follows the pointer to the nearest option (--fk-segmented-hover-*), born at the pressed one. Pass them beside the style; until they run, the pressed option fills itself.

Segmented.SegmentedMultiple

interface · packages/mixins-ui/src/segmented.ts:58

interface SegmentedMultiple<
  Value extends string,
  Message,
> extends SegmentedCommon<Value, Message> {
  readonly multiple: true
}

Any number of the options: a group of pressed buttons, each a tab stop.

Segmented.SegmentedOption

interface · packages/mixins-ui/src/segmented.ts:14

interface SegmentedOption<Value extends string> {
  readonly value: Value
  readonly label: string
  readonly icon?: Html | undefined
  readonly iconOnly?: boolean | undefined
  readonly disabled?: boolean | undefined
}

One option of a segmented control: what it stands for, and its words.

Segmented.SegmentedPreset

type · packages/mixins-ui/src/segmented.ts:211

type SegmentedPreset = Pick<
  SegmentedSingle<string, never>,
  'orientation' | 'direction' | 'style'
> & {
  readonly mixins?: MixinList<never>
}

What a Segmented is given once: its look and the options that hold no Message and nothing of one use's choice.

Segmented.SegmentedSingle

interface · packages/mixins-ui/src/segmented.ts:46

interface SegmentedSingle<
  Value extends string,
  Message,
> extends SegmentedCommon<Value, Message> {
  readonly multiple?: false | undefined
  readonly id: string
  readonly direction?: 'ltr' | 'rtl' | undefined
}

One of the options: a radio group, whose arrows choose as they move.

Segmented.SegmentedSlots

const · packages/mixins-ui/src/segmented/slots.ts:15

const SegmentedSlots: Slots.Contract<{ readonly group: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">, Attr.AttrToken<"aria-disabled">], readonly Slot.RequirementName[], boolean>; readonly option: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-pressed">, Attr.AttrToken<"aria-checked">, 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.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly content: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slo …;

A segmented control: one group of options. A single choice, the default, is the APG's radio group: role="radiogroup" of role="radio" options with aria-checked, one tab stop (the chosen option, else the first enabled), and the arrows, Home and End moving the choice and focus together. With multiple it is shadcn's and Zag's toggle group: a role="group" of buttons with aria-pressed, any number on, each filling itself (draw it without fluid, whose pill marks one), every one a tab stop. indicator and highlight, drawn first in the group, are the chosen option's sliding pill and the hover that follows the pointer, which fluid moves. hiddenInput carries the form value when the group has a name.

Segmented.SegmentedView

type · packages/mixins-ui/src/segmented.ts:65

type SegmentedView<Value extends string, Message> =
  SegmentedSingle<Value, Message> | SegmentedMultiple<Value, Message>

Segmented.toggled

function · packages/mixins-ui/src/segmented.ts:74

function toggled<Value extends string>(
  pressed: ReadonlyArray<Value>,
  value: Value,
  options?: {
    readonly multiple?: boolean
    readonly optional?: boolean
  },
): ReadonlyArray<Value>

The pressed values after value is pressed. A single control keeps one pressed, so pressing the pressed one changes nothing unless it is optional; with multiple, a press turns its option on or off.

Segmented.view

function · packages/mixins-ui/src/segmented.ts:92

function view<Value extends string, Message>(
  options: SegmentedView<Value, Message>,
  h: HtmlBuilder<Message>,
): Html

A segmented control in one call: the options in a group, each label also in data-label so turning semibold when chosen moves nothing, after the indicator and highlight fluid moves. An option with an icon draws it and its words in a content row and is marked data-icon; one drawn iconOnly is named by its label.