Components

Disclosure

One button that shows and hides one panel, with a chevron that turns.

Previews are drawn in the theme you made.

Edit it
variant
indicator
scheme
direction

Basic #

import { Bundles, Disclosure, DisclosureSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// One button that shows and hides one panel. Whether it is open is the
// Bundle's Model; `controls` hands the view that flag and the press's Message.
export default example({
  title: 'Basic',
  slots: DisclosureSlots,
  recipe: Recipes.Disclosure,
  state: Bundles.Disclosure.with({}),
  view: ({ style, model, onMessage, h }) =>
    Disclosure.view(
      {
        id: 'disc-basic',
        label: 'Shipping details',
        content: 'Shipped in two days, tracked to your door.',
        ...Disclosure.controls(model, onMessage),
        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.

In a card, open at the start #

The kettle, its base, a cord that winds away, and a short manual.
import { Bundles, Disclosure, DisclosureSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// A box round the button and the panel, open at the start. The panel's height
// is animated by `@foldkit/ui`, over the same time the theme gives every
// disclosure.
export default example({
  title: 'In a card, open at the start',
  slots: DisclosureSlots,
  recipe: Recipes.Disclosure,
  pins: { variant: 'bordered' },
  state: Bundles.Disclosure.with({ isOpen: true }),
  view: ({ style, model, onMessage, h }) =>
    Disclosure.view(
      {
        id: 'disc-card',
        label: 'What is in the box',
        content: 'The kettle, its base, a cord that winds away, and a short manual.',
        ...Disclosure.controls(model, onMessage),
        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.

With an icon #

import { Bundles, Disclosure, DisclosureSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'

// An `icon` stands before the label, and a ghost button fills under the pointer.
export default example({
  title: 'With an icon',
  slots: DisclosureSlots,
  recipe: Recipes.Disclosure,
  pins: { variant: 'ghost' },
  state: Bundles.Disclosure.with({}),
  view: ({ style, model, onMessage, h }) =>
    Disclosure.view(
      {
        id: 'disc-icon',
        label: 'Notification settings',
        icon: outline(
          h,
          'M8 2a4 4 0 0 0-4 4v3l-1 2h10l-1-2V6a4 4 0 0 0-4-4zM6.5 13a1.5 1.5 0 0 0 3 0',
        ),
        content: 'Email me when someone replies, and once a week with what I missed.',
        ...Disclosure.controls(model, onMessage),
        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.

A preview while shut #

import { Bundles, Disclosure, DisclosureSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// A shut panel can keep a height as a preview of its content. The preview is
// inert, out of the tab order and the accessibility tree, until the panel opens.
export default example({
  title: 'A preview while shut',
  slots: DisclosureSlots,
  recipe: Recipes.Disclosure,
  state: Bundles.Disclosure.with({}),
  view: ({ style, model, onMessage, h }) =>
    Disclosure.view(
      {
        id: 'disc-peek',
        label: 'Read the full note',
        peek: '3em',
        content:
          'We moved the weekly review to Thursdays so that it lands after the release is cut. Notes from the last review are in the shared folder; please add yours before the meeting, and bring one thing you would change about how we ship.',
        ...Disclosure.controls(model, onMessage),
        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.

The button below its panel #

import * as UiDisclosure from '@foldkit/ui/disclosure'
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Disclosure, DisclosureSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Model = Schema.Struct({ isOpen: Schema.Boolean })
const Message = defineMessageUnion({ Toggled: { isOpen: Schema.Boolean } })

// The adapter is the rung for a layout of your own: `toView` hands you the
// button's and the panel's attributes with the style applied, and you place
// them. Here the button sits below its panel.
export default example({
  title: 'The button below its panel',
  slots: DisclosureSlots,
  recipe: Recipes.Disclosure,
  state: {
    Model,
    Message,
    init: () => ({ model: { isOpen: false } }),
    update: (_, message) =>
      Message.match(message, { Toggled: ({ isOpen }) => ({ model: { isOpen } }) }),
  },
  view: ({ style, model, onMessage, h }) =>
    UiDisclosure.view(
      {
        id: 'disc-below',
        isOpen: model.isOpen,
        onToggle: isOpen => onMessage(Message.Toggled({ isOpen })),
        toView: Disclosure.toView([style.mixin], { h }, drawn =>
          h.div(drawn.root, [
            drawn.animatePanel(h.div(drawn.panel, ['Three more photos, and the floor plan.'])),
            h.button(drawn.button, [
              h.span(drawn.label, [model.isOpen ? 'Show less' : 'Show more']),
            ]),
          ]),
        ),
      },
      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 #

import { Bundles, Disclosure, DisclosureSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Card = Recipes.Disclosure.style({ variant: 'bordered' })

// What every disclosure of an application starts from: its look, said once.
// A preset is a named set over it, chosen at a use.
const AppDisclosure = Disclosure.configure({
  base: { style: Card },
  presets: { preview: { peek: '2em' } },
})

export default example({
  title: 'Configure once',
  slots: DisclosureSlots,
  recipe: Recipes.Disclosure,
  state: Bundles.Disclosure.with({}),
  view: ({ model, onMessage, h }) =>
    AppDisclosure.view(
      {
        id: 'disc-configure',
        preset: 'preview',
        label: 'Terms of the offer',
        content: 'The offer ends on the last day of the month and cannot be combined with another.',
        ...Disclosure.controls(model, onMessage),
      },
      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 ↗

Keyboard and accessibility

  • The button is a real button: Enter and Space toggle the panel, and Tab reaches it.
  • aria-expanded on the button says whether the panel is open, and aria-controls names the panel while it is.
  • Through animatePanel a shut panel is inert and aria-hidden, so its links are not tab stops while it is out of sight.

Navigation and structure in the README ↗