Components

Accordion

Sections that open under their headings, one at a time or several.

Previews are drawn in the theme you made.

Edit it
variant
separators
indicator
indicatorPosition
active
scheme
direction

Basic #

Seats, invoices and receipts, billed monthly.

Invite people, remove them, and assign their roles.

Mint a key per service, scope it, and revoke it.
import { Accordion, AccordionSlots, Bundles, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// Which sections are open is the Bundle's Model; `controls` hands the view
// that list and the Message a press sends. One open at a time, and a press on
// the open one shuts it: the Bundle's defaults.
export default example({
  title: 'Basic',
  slots: AccordionSlots,
  recipe: Recipes.Accordion,
  state: Bundles.Accordion.with({ open: ['billing'] }),
  view: ({ style, model, onMessage, h }) =>
    Accordion.view(
      {
        id: 'acc-basic',
        items: [
          {
            id: 'billing',
            title: 'Billing',
            content: 'Seats, invoices and receipts, billed monthly.',
          },
          {
            id: 'team',
            title: 'Team',
            content: 'Invite people, remove them, and assign their roles.',
          },
          {
            id: 'keys',
            title: 'API keys',
            content: 'Mint a key per service, scope it, and revoke it.',
          },
        ],
        ...Accordion.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.

Cards with a plus #

Within 30 days, to the card that paid.

Add or remove them at any time.

On the Business plan.
import { Accordion, AccordionSlots, Bundles, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// `multiple` is an arg of the Bundle, so the press that opens a second
// section is folded the same way wherever it is sent from.
export default example({
  title: 'Cards with a plus',
  slots: AccordionSlots,
  recipe: Recipes.Accordion,
  pins: { variant: 'separated', indicator: 'plus', indicatorPosition: 'start' },
  state: Bundles.Accordion.with({ open: ['refunds'], multiple: true }),
  view: ({ style, model, onMessage, h }) =>
    Accordion.view(
      {
        id: 'acc-plus',
        items: [
          { id: 'refunds', title: 'Refunds', content: 'Within 30 days, to the card that paid.' },
          { id: 'seats', title: 'Seats', content: 'Add or remove them at any time.' },
          { id: 'sso', title: 'Single sign-on', content: 'On the Business plan.', disabled: true },
        ],
        ...Accordion.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.

Ghost, the open one tinted #

Seats, invoices and receipts.

Invite people and assign roles.
import { Accordion, AccordionSlots, Bundles, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'

// A ghost accordion whose open section is tinted, row and panel, with its
// own indicator in place of the chevron.
export default example({
  title: 'Ghost, the open one tinted',
  slots: AccordionSlots,
  recipe: Recipes.Accordion,
  pins: { variant: 'ghost', separators: 'off', active: 'item' },
  state: Bundles.Accordion.with({ open: ['billing'] }),
  view: ({ style, model, onMessage, h }) =>
    Accordion.view(
      {
        id: 'acc-tinted',
        items: [
          { id: 'billing', title: 'Billing', content: 'Seats, invoices and receipts.' },
          { id: 'team', title: 'Team', content: 'Invite people and assign roles.' },
        ],
        icon: outline(h, 'M4 6l4 4 4-4'),
        ...Accordion.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.

Avatars and roles #

Owns billing and can remove anyone.

Manages the team and its API keys.

Reads reports and cannot change settings.
import { Accordion, AccordionSlots, Avatar, Badge, Bundles, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { portrait } from '../../snippets/portrait.js'

const Face = Recipes.Avatar.style({ size: 'sm' })
const Mark = Recipes.Badge.style({})

// A row's `icon` stands before its title and its `trailing` after it: an
// avatar and a role here, any drawing the application makes. The title stays
// text, since it names the row and keeps its width when the row turns bold.
export default example({
  title: 'Avatars and roles',
  slots: AccordionSlots,
  recipe: Recipes.Accordion,
  state: Bundles.Accordion.with({ open: ['ada'] }),
  view: ({ style, model, onMessage, h }) =>
    Accordion.view(
      {
        id: 'acc-rows',
        items: [
          {
            id: 'ada',
            title: 'Ada Lovelace',
            icon: Avatar.view({ name: 'Ada Lovelace', src: portrait(210), style: Face }, h),
            trailing: Badge.view({ text: 'Owner', tone: 'accent', style: Mark }, h),
            content: 'Owns billing and can remove anyone.',
          },
          {
            id: 'alan',
            title: 'Alan Turing',
            icon: Avatar.view({ name: 'Alan Turing', src: portrait(140), style: Face }, h),
            trailing: Badge.view({ text: 'Admin', style: Mark }, h),
            content: 'Manages the team and its API keys.',
          },
          {
            id: 'grace',
            title: 'Grace Hopper',
            icon: Avatar.view({ name: 'Grace Hopper', src: portrait(20), style: Face }, h),
            trailing: Badge.view({ text: 'Viewer', tone: 'neutral', style: Mark }, h),
            content: 'Reads reports and cannot change settings.',
          },
        ],
        ...Accordion.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.

Configure once #

Every accordion draws as cards.

Open as many as you like.
import { Accordion, AccordionSlots, Bundles, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Cards = Recipes.Accordion.style({
  variant: 'separated',
  indicator: 'plus',
  indicatorPosition: 'start',
})

// What every accordion of an application starts from: its look and its
// heading level, said once. Which sections open stays the Bundle's.
const AppAccordion = Accordion.configure({
  base: { style: Cards, headingLevel: 4 },
  presets: { page: { headingLevel: 2 } },
})

export default example({
  title: 'Configure once',
  slots: AccordionSlots,
  recipe: Recipes.Accordion,
  state: Bundles.Accordion.with({ open: ['one'], multiple: true }),
  view: ({ model, onMessage, h }) =>
    AppAccordion.view(
      {
        id: 'acc-configure',
        preset: 'page',
        items: [
          { id: 'one', title: 'One look', content: 'Every accordion draws as cards.' },
          { id: 'two', title: 'Many sections', content: 'Open as many as you like.' },
        ],
        ...Accordion.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 ↗