Mixins / foldkit-mixins-ui

Listbox

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

export * as Listbox from './listbox.js'

In the guides

Members

Listbox.configure

function · packages/mixins-ui/src/listbox/view.ts:198

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

The application's own Listbox: base for every use, presets chosen at a use with preset, and the call over both. mixins concatenate in that order and words merge word by word; any other option given at the call replaces the preset's.

Listbox.drawOption

function · packages/mixins-ui/src/listbox.ts:51

function drawOption<Message>(
  builders: {
    readonly [K in OptionSlot]: SlotBuilder<Message>
  } & {
    readonly match?: SlotBuilder<Message>
    readonly itemTrailing?: SlotBuilder<Message>
  },
  h: HtmlBuilder<Message>,
  content: Pick<
    RowContent,
    'label' | 'description' | 'icon' | 'trailing' | 'content'
  >,
  query?: string,
): Html

An option's content in the slots Listbox and Combobox share: its icon, its label (the stretches matching query marked, where a match slot is given) or content of its own in the label's place, its description, what it holds after the label where the widget has an itemTrailing slot, and the check the chosen row shows.

Listbox.fluid

const · packages/mixins-ui/src/listbox/fluid.ts:14

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

What moves the open panel's highlight and indicator: on its rows, the chosen row is measured (--fk-popup-chosen-*) and one highlight follows the pointer to the nearest row (--fk-popup-hover-*), and to the row the keys mark (data-active) while the pointer is away. Pass them beside the style; until they run, each row marks itself.

Listbox.ListboxPreset

type · packages/mixins-ui/src/listbox/view.ts:185

type ListboxPreset = Pick<
  ListboxView<string, unknown, never>,
  'placeholder' | 'anchor' | 'direction' | 'words' | 'style'
> & {
  readonly mixins?: MixinList<never>
}

What a Listbox is given once: its look and each option that holds no Message, no drawing and nothing of one field's value.

Listbox.ListboxSlots

const · packages/mixins-ui/src/listbox/slots.ts:25

const ListboxSlots: 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 wrapper: 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 button: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">, Event.EventToken<"pointerdown">, Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-expanded">, Attr.AttrToken<"disabled">, Attr.AttrToken<"aria-disabled">], readonly Slot.RequirementName[], boolean>; readonly backdrop: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly items: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"keydown">, Event.EventToken<"blur">], readonly …;

Listbox is a nested Submodel: one button/backdrop/items group plus an item per entry (and group/heading/separator where the caller groups), so the resolver runs once per bundle and each base attribute passes through by identity. hiddenInputs are the form inputs submitted under name: generated markup with no styling surface, passed through for the draw to place.

The button owns click (and pointerdown/keydown while enabled); an item owns click while interactive. A Behavior adding its own handler to one of those is a conflict, not a second silent owner. Disabled buttons and items publish no click, so the contract still lists it as allowed.

The slots from itemContent on are the parts of a select drawn over the listbox, which parts draws: an option's icon, label, description, what it holds after the label and its check, and the trigger's value (or placeholder) and chevron. root and clear are Listbox.view's: the element around the listbox, and the button that empties the choice.

A module of its own, which the adapter re-exports: the Behaviors that attach to these slots are files of their own and read it at load.

Listbox.ListboxView

interface · packages/mixins-ui/src/listbox/view.ts:26

interface ListboxView<Item extends string, Value, Outer> {
  readonly model: UiListbox.Model
  readonly onMessage: (message: UiListbox.Message) => Outer
  readonly label: string
  readonly choice: Choice<Item, Value>
  readonly value: NoInfer<Value>
  readonly items?: ReadonlyArray<NoInfer<Item>> | undefined
  readonly option?: ((item: NoInfer<Item>) => RowContent) | undefined
  readonly groupBy?: ((item: NoInfer<Item>) => string) | undefined
  readonly heading?: ((group: string) => Html) | undefined
  readonly placeholder?: string | undefined
  readonly trigger?: ((chosen: ReadonlyArray<RowContent>) => Html) | undefined
  readonly clear?:
    | {
        readonly onClear: Outer
        readonly content?: Html | undefined
      }
    | undefined
  readonly disabled?: boolean | undefined
  readonly invalid?: boolean | undefined
  readonly readOnly?: boolean | undefined
  readonly name?: string | undefined
  readonly anchor?: AnchorConfig | undefined
  readonly direction?: 'ltr' | 'rtl' | undefined
  readonly words?: Partial<ListboxWords> | undefined
  readonly style?: NamedStyle<typeof ListboxSlots> | undefined
  readonly mixins?: MixinList<Outer> | undefined
}

Listbox.ListboxWords

interface · packages/mixins-ui/src/listbox/words.ts:2

interface ListboxWords {
  readonly clear: string
}

The fixed text a Listbox says. Each is text.

Listbox.many

function · packages/mixins-ui/src/choice/many.ts:6

function many<const Item extends string>(
  items: ReadonlyArray<Item>,
): Choice<Item, ReadonlyArray<Item>>

Any number of items, in the order they were chosen: Selected flips one.

Listbox.one

function · packages/mixins-ui/src/choice/one.ts:5

function one<const Item extends string>(
  items: ReadonlyArray<Item>,
): SingleChoice<Item, Option.Option<Item>>

At most one of items: the value is an Option of an item.

Listbox.overlayBars

const · packages/mixins-ui/src/listbox/overlayBars.ts:11

const overlayBars: readonly [Mixin<never>]

What draws the open panel's scrollBar over its scroll (ScrollBars), in place of the browser's bar, on a pointer that can hover. Pass it beside the style when the listbox scrolls (itemsScrollAttributes); without a scroll there is no bar.

Listbox.parts

function · packages/mixins-ui/src/listbox.ts:97

function parts<Message>(
  mixins: MixinList<Message>,
  context: ResolveContext<unknown, Message>,
): {
  option: (content: RowContent) => Html
  trigger: (
    chosen: ReadonlyArray<RowContent>,
    placeholder: string,
    shown?: Html | undefined,
  ) => Html
}

The parts of a select over this listbox, in its slots: option is an item's content (itemToConfig), and trigger the button's (buttonContent): what is chosen, or the placeholder, then the chevron. One chosen row shows its icon and label, several their labels joined, none the placeholder, muted; shown draws what it holds in place of that. Pass the mixins the listbox's toView gets.

Listbox.resolve

function · packages/mixins-ui/src/listbox.ts:172

function resolve<Input, Message>(
  render: ListboxRenderInfo,
  mixins: MixinList<Message>,
  context: ResolveContext<Input, Message>,
): ResolvedListbox<Message>

Resolves the listbox's bundles (and every item's); pass-throughs stay intact.

Listbox.ResolvedListbox

type · packages/mixins-ui/src/listbox.ts:145

type ResolvedListbox<Message> = Omit<
  ListboxRenderInfo,
  'wrapper' | 'button' | 'backdrop' | 'items' | 'scroll' | 'groups'
> & {
  readonly wrapper: SlotAttributes<Message>
  readonly button: SlotAttributes<Message>
  readonly buttonContent: Html
  readonly hiddenInputs: ReadonlyArray<Html>
  readonly backdrop:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly items:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly scroll: SlotAttributes<Message> | undefined
  readonly rows: SlotAttributes<Message> | undefined
  readonly highlight: SlotAttributes<Message> | undefined
  readonly indicator: SlotAttributes<Message> | undefined
  readonly scrollBar: SlotAttributes<Message> | undefined
  readonly scrollThumb: SlotAttributes<Message> | undefined
  readonly groups: ReadonlyArray<ResolvedListboxGroup<Message>>
}

Listbox.ResolvedListboxGroup

type · packages/mixins-ui/src/listbox.ts:135

type ResolvedListboxGroup<Message> = Omit<
  ListboxGroupRender,
  'heading' | 'group' | 'separator' | 'items'
> & {
  readonly heading: ResolvedListboxHeading<Message> | undefined
  readonly group:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly separator:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly items: ReadonlyArray<ResolvedListboxItem<Message>>
}

Listbox.ResolvedListboxHeading

type · packages/mixins-ui/src/listbox.ts:131

type ResolvedListboxHeading<Message> = Omit<
  ListboxHeadingRender,
  'attributes'
> & {
  readonly attributes: SlotAttributes<Message>
}

Listbox.ResolvedListboxItem

type · packages/mixins-ui/src/listbox.ts:127

type ResolvedListboxItem<Message> = Omit<ListboxItemRender, 'attributes'> & {
  readonly attributes: SlotAttributes<Message>
}

Listbox.toView

function · packages/mixins-ui/src/listbox.ts:247

function toView<Message>(
  mixins: MixinList<Message>,
  context: ResolveContext<unknown, Message>,
  draw?: (resolved: ResolvedListbox<Message>) => Html,
): (render: ListboxRenderInfo) => Html

The listbox's toView: draw receives its bundles with mixins applied. Without one, it draws upstream's markup from them.

Listbox.view

function · packages/mixins-ui/src/listbox/view.ts:84

function view<const Item extends string, Value, Outer>(
  options: ListboxView<Item, Value, Outer>,
  h: HtmlBuilder<Outer>,
): Html

A Listbox: a button showing the choice that opens a list of rows, the chosen ones marked; with the recipe, a custom select. The value is the application's: it is passed at every draw, and what the reader chooses is reported by the state (Bundles.Listbox's ChoiceChange) for the application to fold through the same choice.

Listbox.words

const · packages/mixins-ui/src/listbox/words.ts:8

const words = { clear }

The words a Listbox uses when none are given.