Components

Carousel

Slides in a track that snaps, with previous, next, dots or thumbnails, several at once, and a rotation that pauses.

Previews are drawn in the theme you made.

Edit it
peek
scheme
direction

Basic #

Dunes
Coast
Ridge
Valley
1 of 4
import { Bundles, Carousel, CarouselSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const places = ['Dunes', 'Coast', 'Ridge', 'Valley']

// The slide shown is the Bundle's Model. The layout (how many slides, how many
// at once, looping) is its args, kept in the Model, so `update` and the view
// read it from one place; the Bundle hears a swipe settle as well as the buttons.
export default example({
  title: 'Basic',
  slots: CarouselSlots,
  recipe: Recipes.Carousel,
  state: Bundles.Carousel.with({ id: 'car-basic', count: places.length }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [
        Carousel.view(
          {
            label: 'Places',
            model,
            onMessage,
            slides: places.map(place =>
              h.div(
                [
                  h.Style({
                    display: 'grid',
                    placeItems: 'center',
                    blockSize: '10rem',
                    // A fill, not a border: the slide rounds its corners by clipping.
                    background: 'color-mix(in oklab, currentColor 8%, transparent)',
                  }),
                ],
                [place],
              ),
            ),
            style,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Autoplay #

Dunes
Coast
Ridge
Valley
Delta
1 of 5
import { Bundles, Carousel, CarouselSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const shots = ['Dunes', 'Coast', 'Ridge', 'Valley', 'Delta']

// Moves on every four seconds, the current dot filling as it waits. A pointer
// on it pauses it, focus from the keys stops it, and the button in its corner,
// first in the tab order, stops and starts it.
export default example({
  title: 'Autoplay',
  slots: CarouselSlots,
  recipe: Recipes.Carousel,
  state: Bundles.Carousel.with({ id: 'car-auto', count: shots.length, loop: true, autoplay: true }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [
        Carousel.view(
          {
            label: 'Places',
            model,
            onMessage,
            slides: shots.map(place =>
              h.div(
                [
                  h.Style({
                    display: 'grid',
                    placeItems: 'center',
                    blockSize: '10rem',
                    background: 'color-mix(in oklab, currentColor 8%, transparent)',
                  }),
                ],
                [place],
              ),
            ),
            style,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Thumbnails #

Dunes
Coast
Ridge
Valley
Delta
1 of 5
import { Bundles, Carousel, CarouselSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const shots = ['Dunes', 'Coast', 'Ridge', 'Valley', 'Delta']

// A small copy of each slide in place of the dots; the one shown is ringed.
export default example({
  title: 'Thumbnails',
  slots: CarouselSlots,
  recipe: Recipes.Carousel,
  state: Bundles.Carousel.with({ id: 'car-thumbs', count: shots.length }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [
        Carousel.view(
          {
            label: 'Places',
            model,
            onMessage,
            slides: shots.map(place =>
              h.div(
                [
                  h.Style({
                    display: 'grid',
                    placeItems: 'center',
                    blockSize: '10rem',
                    background: 'color-mix(in oklab, currentColor 8%, transparent)',
                  }),
                ],
                [place],
              ),
            ),
            thumbnails: shots.map(place =>
              h.span(
                [h.Style({ display: 'grid', placeItems: 'center', fontSize: '0.625rem' })],
                [place],
              ),
            ),
            style,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Two per view #

Dunes
Coast
Ridge
Valley
Delta
1 of 5
import { Bundles, Carousel, CarouselSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const shots = ['Dunes', 'Coast', 'Ridge', 'Valley', 'Delta']

// Two slides at once, a dot per place the track can rest: four for five slides.
// `perView` is an arg, so the Bundle and the view agree on it without being told twice.
export default example({
  title: 'Two per view',
  slots: CarouselSlots,
  recipe: Recipes.Carousel,
  pins: { peek: 'none' },
  state: Bundles.Carousel.with({ id: 'car-two', count: shots.length, perView: 2 }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(32rem, 100%)' })],
      [
        Carousel.view(
          {
            label: 'Places',
            model,
            onMessage,
            slides: shots.map(place =>
              h.div(
                [
                  h.Style({
                    display: 'grid',
                    placeItems: 'center',
                    blockSize: '10rem',
                    background: 'color-mix(in oklab, currentColor 8%, transparent)',
                  }),
                ],
                [place],
              ),
            ),
            style,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Configure once #

Dunes
Coast
Ridge
Diapositive 1 sur 3
import { Bundles, Carousel, CarouselSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const shots = ['Dunes', 'Coast', 'Ridge']

// What every carousel of an application starts from: its words, said once (here
// in French). `words` merge key by key, so a use may change one and keep the rest.
const AppCarousel = Carousel.configure({
  base: {
    words: {
      slide: 'Diapositive {index} sur {count}',
      previous: 'Précédente',
      next: 'Suivante',
      picker: 'Choisir une diapositive',
    },
  },
})

export default example({
  title: 'Configure once',
  slots: CarouselSlots,
  recipe: Recipes.Carousel,
  state: Bundles.Carousel.with({ id: 'car-conf', count: shots.length }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [
        AppCarousel.view(
          {
            label: 'Lieux',
            model,
            onMessage,
            slides: shots.map(place =>
              h.div(
                [
                  h.Style({
                    display: 'grid',
                    placeItems: 'center',
                    blockSize: '10rem',
                    background: 'color-mix(in oklab, currentColor 8%, transparent)',
                  }),
                ],
                [place],
              ),
            ),
            style,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Usage

Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.

The recipe ↗This code ↗

  • Right to left The direction switch above turns the preview over; this is what each widget reads.