Mixins / foldkit-mixins-ui

Menubar

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

export * as Menubar from './menubar.js'

In the guides

Members

Menubar.configure

function · packages/mixins-ui/src/menubar.ts:419

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

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

Menubar.conflict

function · packages/mixins-ui/src/menubar.ts:306

function conflict<ParentMessage>(
  routes: ReadonlyArray<Route<ParentMessage>>,
  input?: Pick<MenubarView<ParentMessage>, 'direction'>,
): Option.Option<Diagnostic>

The mixins:key-conflict that drawing the bar with routes would throw, or none: the application's routes against the bar's own and against each other. direction is the one the view is given, since 'rtl' moves the arrows.

Menubar.init

function · packages/mixins-ui/src/menubar.ts:106

function init(ids: ReadonlyArray<string>, options?: InitOptions): Model

One shut menu per id, the first trigger the tab stop. options reach every menu, as Menu.init's do: animated, each panel carries upstream's transition marks and stays drawn while it leaves, so a recipe's fade runs. Modal, the rest of the page, the bar's other triggers among it, is inert while a menu is open: the pointer no longer moves between menus, the arrows still do.

interface · packages/mixins-ui/src/menubar.ts:244

interface MenubarMenu<Value extends string = string> {
  readonly label: string
  readonly rows: ReadonlyArray<LeafRow<Value>>
  readonly isRowDisabled?: ((value: Value) => boolean) | undefined
  readonly header?: Html | undefined
  readonly footer?: Html | undefined
}

type · packages/mixins-ui/src/menubar.ts:410

type MenubarPreset = Pick<
  MenubarView<never>,
  'direction' | 'style' | 'menuMixins' | 'kbd' | 'anchor'
>

What a Menubar is given once: its look and keys' look, and where its menus open. The Model, menus and Messages are each use's.

const · packages/mixins-ui/src/menubar.ts:52

const MenubarSlots: Slots.Contract<{
  readonly bar: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly [Event.EventToken<'keydown'>],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
  readonly menu: Slot.UnnamedSlot<
    Capability.Capability<
      'Container',
      readonly [
        Capability.Capability<
          'Interactive',
          readonly [Capability.Capability<'Base', readonly []>]
        >,
      ]
    >,
    readonly [Event.EventToken<'hover'>],
    readonly Slot.AttributeName[],
    readonly Slot.RequirementName[],
    boolean
  >
}>

A menu bar, shadcn's and the APG's: a row of @foldkit/ui Menus, so each menu's keys, typeahead, rows and dismissal stay the Menu's, and the bar adds what a row of them needs. One trigger is the bar's tab stop, and ArrowLeft and ArrowRight (Home and End while all are shut) move it, the two swapped under direction: 'rtl'; with a menu open they shut it and open the next, its first row active. While one is open, pointing at another trigger opens that one, and opening any menu shuts the rest. The menus' Models are this module's Model, which the application keeps and folds with update, as it folds a Menu's.

The bar's keys and hover listen outside each menu's submodel (a handler inside it would speak the Menu's Messages): keydown on the bar, which the triggers and rows bubble to, and mouseenter on each menu. The triggers stand above an open menu's backdrop (z-index: 1), which holds only while nothing between the bar and the page makes a stacking context.

interface · packages/mixins-ui/src/menubar.ts:260

interface MenubarView<ParentMessage, Value extends string = string> {
  readonly label: string
  readonly model: Model
  readonly menus: ReadonlyArray<MenubarMenu<Value>>
  readonly onMessage: (message: Message) => NoInfer<ParentMessage>
  readonly direction?: 'ltr' | 'rtl' | undefined
  readonly routes?: ReadonlyArray<Route<NoInfer<ParentMessage>>> | undefined
  readonly style?: NamedStyle<typeof MenubarSlots> | undefined
  readonly menuMixins?: MixinList<ParentMessage> | undefined
  readonly kbd?: NamedStyle<typeof KbdSlots> | undefined
  readonly anchor?: AnchorConfig | undefined
}

Menubar.Message

const · packages/mixins-ui/src/menubar.ts:76

const Message: MessageUnion<{ readonly GotMenu: { readonly index: Schema.Number; readonly message: MessageUnion<{ readonly Opened: { maybeActiveItemIndex: Schema.Option<Schema.Number>; }; readonly Closed: {}; readonly BlurredItems: {}; readonly ActivatedItem: { index: Schema.Number; activationTrigger: Schema.Literals<readonly ["Pointer", "Keyboard"]>; }; readonly DeactivatedItem: {}; readonly SelectedItem: { index: Schema.Number; item: Schema.String; }; readonly RequestedItemClick: { index: Schema.Number; }; readonly Searched: { key: Schema.String; maybeTargetIndex: Schema.Option<Schema.Number>; }; readonly CompletedDelayClearSearch: { version: Schema.Number; }; readonly MovedPointerOverItem: { index: Schema.Number; screenX: Schema.Number; screenY: Schema.Number; }; readonly CompletedFocusItems: {}; readonly CompletedFocusButton: {}; readonly CompletedLockScroll: {}; readonly CompletedUnlockScroll: {}; readonly CompletedInertOthers: {}; readonly CompletedRestoreInert: {}; readonly CompletedScrollIntoView: {}; readonly CompletedClickItem: {}; readonly ClickedButton: {}; readonly IgnoredMouseClick: {}; readonly SuppressedSpaceScroll: {}; readonly CompletedAnchorMenu: {}; readonly CompletedPortalMenuBackdrop: {}; readonly GotAnimationMessage: { message: import("foldkit/message").MessageUnion<{ readonly Showed: {}; readonly Hid: {}; readonly CompletedWaitForPaint: { generation: Schema.Number; }; readonly EndedAnimation: { generation: Schema.Number; }; }>; }; readonly PressedPointerOnButton: { p …;

Menubar.Model

const · packages/mixins-ui/src/menubar.ts:57

const Model: Schema.Struct<{
  readonly menus: Schema.$Array<
    Schema.Struct<{
      readonly id: Schema.String
      readonly isOpen: Schema.Boolean
      readonly isAnimated: Schema.Boolean
      readonly isModal: Schema.Boolean
      readonly animation: Schema.Struct<{
        readonly id: Schema.String
        readonly isShowing: Schema.Boolean
        readonly transitionState: Schema.Literals<
          readonly [
            'Idle',
            'EnterStart',
            'EnterAnimating',
            'LeaveStart',
            'LeaveAnimating',
          ]
        >
        readonly transitionGeneration: Schema.Number
      }>
      readonly maybeActiveItemIndex: Schema.Option<Schema.Number>
      readonly activationTrigger: Schema.Literals<
        readonly ['Pointer', 'Keyboard']
      >
      readonly searchQuery: Schema.String
      readonly searchVersion: Schema.Number
      readonly maybeLastPointerPosition: Schema.Option<
        Schema.Struct<{
          readonly screenX: Schema.Number
          readonly screenY: Schema.Number
        }>
      >
      readonly maybeLastButtonPointerType: Schema.Option<Schema.String>
      readonly maybePointerOrigin: Schema.Option<
        Schema.Struct<{
          readonly screenX: Schema.Number
          readonly screenY: Schema.Number
          readonly timeStamp: Schema.Number
        }>
      >
    }>
  >
  readonly stop: Schema.Number
}>

Menubar.OutMessage

const · packages/mixins-ui/src/menubar.ts:92

const OutMessage: MessageUnion<{
  readonly Selected: {
    readonly menu: Schema.Number
    readonly value: Schema.String
  }
}>

Menubar.Route

type · packages/mixins-ui/src/menubar.ts:258

type Route<Message> = Behaviors.Keys.Route<unknown, Message>

A key the bar answers beside its own; it is pressed on the bar or a trigger or row inside it.

Menubar.update

function · packages/mixins-ui/src/menubar.ts:191

function update(model: Model, message: Message): Return

The bar after message; the same Model when nothing changes.

Menubar.view

function · packages/mixins-ui/src/menubar.ts:315

function view<ParentMessage, Value extends string = string>(
  options: MenubarView<ParentMessage, Value>,
  h: HtmlBuilder<ParentMessage>,
): Html