Mixins / foldkit-mixins-ui

Carousel

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

export * as Carousel from './carousel.js'

In the guides

Members

Carousel.CarouselLayout

interface · packages/mixins-ui/src/carousel.ts:197

interface CarouselLayout {
  readonly count: number
  readonly perView?: number | undefined
  readonly loop?: boolean | undefined
}

What update and the view agree on: how many slides, how many show at once, and looping.

Carousel.CarouselPreset

type · packages/mixins-ui/src/carousel.ts:528

type CarouselPreset = Pick<
  CarouselView<never>,
  'picker' | 'words' | 'style'
> & {
  readonly mixins?: MixinList<never>
}

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

Carousel.CarouselSlots

const · packages/mixins-ui/src/carousel.ts:35

const CarouselSlots: Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"hover">, Event.EventToken<"focus">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly rotation: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly [Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly track: 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 slide: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly controls: 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 previous: Slot.Unna …;

A carousel, the APG's: a group with aria-roledescription="carousel" named by its label, each slide a group with aria-roledescription="slide" named "2 of 5", previous and next buttons, and a picker of a dot (or a thumbnail) per place the track can rest. The track is a CSS scroll-snap scroller, so a swipe or a trackpad moves it natively, and ScrollSettle reports where it came to rest.

button, dot, swipe, timer -> Message -> update -> index -> ShowSlide -> track

The current slide, and whether it rotates, are this Model, which the application keeps and folds with update({ count }). Started with autoplay, it moves on every delay: a pointer over it pauses it, focus arriving by the keys stops it (the APG's rule), and the rotation button, first in the tab order, stops and starts it. The current dot fills as the delay runs. A polite status says the slide shown once it changes, and is quiet while the carousel rotates.

Carousel.CarouselView

interface · packages/mixins-ui/src/carousel.ts:302

interface CarouselView<ParentMessage> extends Omit<CarouselLayout, 'count'> {
  readonly label: string
  readonly model: Model
  readonly slides: ReadonlyArray<Html>
  readonly onMessage: (message: Message) => NoInfer<ParentMessage>
  readonly picker?: boolean | undefined
  readonly thumbnails?: ReadonlyArray<Html> | undefined
  readonly words?: Partial<CarouselWords> | undefined
  readonly style?: NamedStyle<typeof CarouselSlots> | undefined
  readonly mixins?: MixinList<ParentMessage> | undefined
}

Carousel.CarouselWords

interface · packages/mixins-ui/src/carousel.ts:321

interface CarouselWords {
  readonly slide: string
  readonly previous: string
  readonly next: string
  readonly picker: string
  readonly stop: string
  readonly start: string
}

What the carousel says that is no one use's content.

Carousel.configure

function · packages/mixins-ui/src/carousel.ts:537

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

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

Carousel.DELAY

const · packages/mixins-ui/src/carousel.ts:122

const DELAY: 4000

The default delay, Embla's autoplay's.

Carousel.init

function · packages/mixins-ui/src/carousel.ts:124

function init(options: {
  readonly id: string
  readonly index?: number
  readonly autoplay?: boolean
  readonly reducedMotion?: boolean
  readonly delay?: number
  readonly count?: number
  readonly perView?: number
  readonly loop?: boolean
}): Model

Carousel.Message

const · packages/mixins-ui/src/carousel.ts:105

const Message: MessageUnion<{
  readonly Chose: { readonly index: Schema.Number }
  readonly Settled: { readonly index: Schema.Number }
  readonly StartedRotation: {}
  readonly StoppedRotation: {}
  readonly PointerEntered: {}
  readonly PointerLeft: {}
  readonly FocusEntered: {}
  readonly Elapsed: { readonly turn: Schema.Number }
  readonly CompletedShowSlide: {}
}>

Carousel.Model

const · packages/mixins-ui/src/carousel.ts:82

const Model: Schema.Struct<{
  readonly id: Schema.String
  readonly index: Schema.Number
  readonly rotation: Schema.Literals<readonly ['None', 'Stopped', 'Rotating']>
  readonly hovered: Schema.Boolean
  readonly delay: Schema.Number
  readonly turn: Schema.Number
  readonly counting: Schema.Boolean
  readonly count: Schema.Number
  readonly perView: Schema.Number
  readonly loop: Schema.Boolean
}>

Carousel.Rotation

const · packages/mixins-ui/src/carousel.ts:79

const Rotation: Schema.Literals<readonly ['None', 'Stopped', 'Rotating']>

Whether the carousel moves by itself: None never (no rotation button is drawn), Stopped until the rotation button starts it, Rotating on every delay while no pointer rests on it.

Carousel.ShowSlide

const · packages/mixins-ui/src/carousel.ts:171

const ShowSlide: Command.CommandDefinitionWithArgs<
  'Carousel.ShowSlide',
  { id: Schema.String; index: Schema.Number },
  Effect.Effect<{ readonly _tag: 'CompletedShowSlide' }, never, never>
>

Scrolls the carousel id's track to slide index, its start at the track's start, once the render that marked it current has committed, and brings its thumbnail into view in a picker that scrolls. The scroll is smooth where the recipe says so, which it does only without reduced motion. A slide not drawn is left alone.

Carousel.slideId

function · packages/mixins-ui/src/carousel.ts:160

function slideId(id: string, index: number): string

The id of slide index of the carousel id, which ShowSlide looks up.

Carousel.update

function · packages/mixins-ui/src/carousel.ts:296

function update(
  layout?: CarouselLayout,
): (model: Model, message: Message) => Return

The carousel's update. With no layout it reads the one the Model holds (init's count, perView and loop); given one, that layout wins.

Carousel.view

function · packages/mixins-ui/src/carousel.ts:354

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

Carousel.words

const · packages/mixins-ui/src/carousel.ts:334

const words = { slide, previous, next, picker, stop, start }