Mixins / foldkit-mixins-ui

Tour

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

export * as Tour from './tour.js'

In the guides

Members

Tour.advanceOnClick

const · packages/mixins-ui/src/tour/advanceOnClick.ts:13

const advanceOnClick: Mount.MountDefinitionNoArgs<
  'Tour.AdvanceOnClick',
  { readonly _tag: 'Next' }
>

Moves the tour on when the reader presses the step's target through the cutout, as a step that says "press Save" expects; the last step's press ends it completed. Pass it as the view's advanceOnClick. The target is read from the layer when the press lands, so the one listener serves every step; it is on the dim, and attached only while the tour shows.

Tour.Config

interface · packages/mixins-ui/src/tour.ts:87

interface Config {
  readonly steps: ReadonlyArray<Step>
}

Steps given to one call in place of the Model's.

Tour.configure

function · packages/mixins-ui/src/tour.ts:518

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

The application's own Tour: base for every use, presets chosen at a use with preset, and the call over both. words merge key by key and mixins concatenate in that order (Tour.focusReturn goes in base); any other option given at the call replaces the preset's. The steps are the Model's.

Tour.conflict

function · packages/mixins-ui/src/tour.ts:316

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

The mixins:key-conflict that drawing an open step with routes would throw, or none: the application's routes against the step's own and against each other. A closed tour draws nothing, so the check is of the open one.

Tour.Ended

const · packages/mixins-ui/src/tour.ts:81

const Ended: Schema.TaggedStruct<
  'Ended',
  { readonly completed: Schema.Boolean }
>

Told to the application as the tour ends: by its last Next (completed), or skipped.

Tour.focusReturn

const · packages/mixins-ui/src/tour/focusReturn.ts:13

const focusReturn: readonly [Mixin<never>]

Gives focus back when the tour ends: to what had it before the tour, then by FocusReturn's rules (an element with the opener's id, the opener's FocusRecovery steps, the layer below, the page's first tabbable element). Focus the reader moved elsewhere is left alone. The one way focus returns: the tour keeps no opener of its own. Pass it among the mixins; opt in, as it sends no Message.

Tour.init

function · packages/mixins-ui/src/tour.ts:91

function init(options: {
  readonly id: string
  readonly steps?: ReadonlyArray<Step> | undefined
}): Model

Tour.Message

const · packages/mixins-ui/src/tour/message.ts:5

const Message: MessageUnion<{
  readonly Next: {}
  readonly Back: {}
  readonly Skipped: {}
  readonly Pressed: { readonly key: Schema.String }
  readonly Spotlit: {
    readonly target: Schema.String
    readonly found: Schema.Boolean
  }
  readonly Placed: {}
  readonly CompletedShowStep: {}
}>

A tour's Messages; a module of their own, as advanceOnClick sends one.

Tour.Model

const · packages/mixins-ui/src/tour.ts:67

const Model: Schema.Struct<{
  readonly id: Schema.String
  readonly open: Schema.Boolean
  readonly steps: Schema.$Array<
    Schema.Struct<{
      readonly title: Schema.String
      readonly description: Schema.String
      readonly target: Schema.optionalKey<Schema.String>
      readonly placement: Schema.optionalKey<
        Schema.Literals<
          readonly [
            'top',
            'right',
            'bottom',
            'left',
            'top-start',
            'top-end',
            'right-start',
            'right-end',
            'bottom-start',
            'bottom-end',
            'left-start',
            'left-end',
          ]
        >
      >
    }>
  >
  readonly step: Schema.Number
  readonly missing: Schema.Option<Schema.Number>
}>

Tour.PlaceStep

const · packages/mixins-ui/src/tour.ts:203

const PlaceStep: Mount.MountDefinitionWithArgs<
  'Tour.PlaceStep',
  {
    buttonId: Schema.String
    anchor: Schema.Struct<{
      readonly placement: Schema.optional<
        Schema.Literals<
          readonly [
            'top',
            'right',
            'bottom',
            'left',
            'top-start',
            'top-end',
            'right-start',
            'right-end',
            'bottom-start',
            'bottom-end',
            'left-start',
            'left-end',
          ]
        >
      >
      readonly gap: Schema.optional<Schema.Number>
      readonly offset: Schema.optional<Schema.Number>
      readonly padding: Schema.optional<
        Schema.Union<
          readonly [
            Schema.Number,
            Schema.Struct<{
              readonly top: Schema.optionalKey<Schema.Number>
              readonly right: Schema.optionalKey<Schema.Number>
              readonly bottom: Schema.optionalKey<Schema.Number>
              readonly left: Schema.optionalKey<Schema.Number>
            }>,
          ]
        >
      >
      readonly portal: Schema.optional<Schema.Boolean>
      readonly isPlacementLocked: Schema.optional<Schema.Boolean>
    }>
    arrowId: Schema.String
  },
  { readonly _tag: 'Placed' }
>

Places the step against its target, focusing it once placed.

Tour.Return

type · packages/mixins-ui/src/tour.ts:84

type Return = ReturnWithOutMessage<Model, Message, Ended>

Tour.Route

type · packages/mixins-ui/src/tour.ts:287

type Route<ParentMessage> = Behaviors.Keys.Route<undefined, ParentMessage>

A key the application answers on a step.

Tour.ShowStep

const · packages/mixins-ui/src/tour.ts:113

const ShowStep: Command.CommandDefinitionWithArgs<
  'Tour.ShowStep',
  { id: Schema.String; target: Schema.Option<Schema.String> },
  Effect.Effect<{ readonly _tag: 'CompletedShowStep' }, never, never>
>

Brings a step's target into the middle of the viewport, smoothly unless the reader asked for reduced motion; a step with no target it focuses once drawn. One with a target is hidden until the anchor first places it, and focus does not land on a hidden element, so the anchor focuses it.

Tour.start

function · packages/mixins-ui/src/tour.ts:138

function start(model: Model, config?: Config): Return

Starts the tour at its first step; one already running starts over.

Tour.Step

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

const Step: Schema.Struct<{
  readonly title: Schema.String
  readonly description: Schema.String
  readonly target: Schema.optionalKey<Schema.String>
  readonly placement: Schema.optionalKey<
    Schema.Literals<
      readonly [
        'top',
        'right',
        'bottom',
        'left',
        'top-start',
        'top-end',
        'right-start',
        'right-end',
        'bottom-start',
        'bottom-end',
        'left-start',
        'left-end',
      ]
    >
  >
}>

A step of the tour.

Tour.TourPreset

type · packages/mixins-ui/src/tour.ts:498

type TourPreset = Pick<
  TourView<never>,
  | 'padding'
  | 'interactive'
  | 'dismissOnOutside'
  | 'closeOnEscape'
  | 'advanceOnClick'
  | 'direction'
  | 'words'
  | 'style'
> & {
  readonly mixins?: MixinList<never>
}

What a Tour is given once: its look, words and the options that hold no Message.

Tour.TourSlots

const · packages/mixins-ui/src/tour/slots.ts:4

const TourSlots: Slots.Contract<{ readonly layer: 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 blocker: 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 spotlight: 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 panel: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">], readonly Slot.RequirementName[], boolean>; readonly arrow: 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 progress: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly …;

A tour's pieces: the layer with its dim and cutout, and the step's panel.

Tour.TourView

interface · packages/mixins-ui/src/tour.ts:243

interface TourView<ParentMessage> {
  readonly model: Model
  readonly config?: Config | undefined
  readonly onMessage: (message: Message) => NoInfer<ParentMessage>
  readonly content?: ((step: Step, index: number) => Html) | undefined
  readonly advanceOnClick?: AdvanceOnClick | undefined
  readonly padding?: number | undefined
  readonly interactive?: boolean | undefined
  readonly dismissOnOutside?: boolean | undefined
  readonly closeOnEscape?: boolean | undefined
  readonly words?: Partial<TourWords> | undefined
  readonly direction?: 'ltr' | 'rtl' | undefined
  readonly routes?: ReadonlyArray<Route<NoInfer<ParentMessage>>> | undefined
  readonly style?: NamedStyle<typeof TourSlots> | undefined
  readonly mixins?: MixinList<ParentMessage> | undefined
}

Tour.TourWords

interface · packages/mixins-ui/src/tour.ts:226

interface TourWords {
  readonly back: string
  readonly next: string
  readonly done: string
  readonly skip: string
  readonly progress: string
}

The fixed text a tour draws; progress with {step} (from 1) and {count}.

Tour.update

function · packages/mixins-ui/src/tour.ts:151

function update(config?: Config): (model: Model, message: Message) => Return

The tour's update, over the steps config gives where given and the Model's otherwise; the same Model when nothing changes.

Tour.view

function · packages/mixins-ui/src/tour.ts:325

function view<ParentMessage>(
  options: TourView<ParentMessage>,
  h: HtmlBuilder<ParentMessage>,
): Html

Tour.words

const · packages/mixins-ui/src/tour.ts:235

const words = { back, next, done, skip, progress }