Components

Alert

A notice in four tones, tinted or bold: inline in the content, or a banner across the page.

Previews are drawn in the theme you made.

Edit it
tone
emphasis
scheme
direction

Inline #

A new version is out

Reload to pick up the latest fixes. Your drafts are kept.

import { Alert, AlertSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// Inline, a status inside the content: a live region, so a screen reader
// speaks it when it appears. `assertive: true` makes it `role="alert"`.
export default example({
  title: 'Inline',
  slots: AlertSlots,
  recipe: Recipes.Alert,
  view: ({ style, h }) =>
    Alert.view(
      {
        layout: 'inline',
        title: 'A new version is out',
        description: 'Reload to pick up the latest fixes. Your drafts are kept.',
        actions: [{ label: 'Reload', href: '#' }],
        style,
      },
      h,
    ),
})

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

Version 2 is out, with offline sync.

import { Alert, AlertSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// As a banner, a named landmark across the page: it is there when the page
// loads, so it is a region a screen reader can find, not a live one.
export default example({
  title: 'Banner',
  slots: AlertSlots,
  recipe: Recipes.Alert,
  view: ({ style, h }) =>
    Alert.view(
      {
        layout: 'banner',
        label: 'Announcement',
        title: 'Version 2 is out, with offline sync.',
        actions: [{ label: 'Read the notes', href: '#' }],
        style,
      },
      h,
    ),
})

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

Dismissed #

Your trial ends in 3 days

Add a card to keep every page.

import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Alert, AlertSlots, Button, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const Action = Recipes.Button.style({ variant: 'outline', size: 'sm' })

const Model = Schema.Struct({ shown: Schema.Boolean })
const Message = defineMessageUnion({ Dismissed: {}, Restored: {} })

// `onDismiss` draws the button and asks; the application's Model decides
// whether the next view draws the alert, so nothing hides it behind your back.
export default example({
  title: 'Dismissed',
  slots: AlertSlots,
  recipe: Recipes.Alert,
  state: {
    Model,
    Message,
    init: () => ({ model: { shown: true } }),
    update: (model, message) => {
      const shown = Message.match(message, { Dismissed: () => false, Restored: () => true })
      return { model: shown === model.shown ? model : { shown } }
    },
  },
  view: ({ style, model, onMessage, h }) =>
    model.shown
      ? Alert.view(
          {
            layout: 'inline',
            title: 'Your trial ends in 3 days',
            description: 'Add a card to keep every page.',
            onDismiss: onMessage(Message.Dismissed()),
            style,
          },
          h,
        )
      : Button.view(
          { label: 'Show the alert again', onClick: onMessage(Message.Restored()), style: Action },
          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.

Every tone #

Heads up

Something worth knowing.

Saved

Every change is in.

Almost full

You have used 90% of your storage.

Could not publish

The server did not answer.

No changes

Nothing changed since the last save.

New: themes

Pick a look for the whole site.

import { Alert, AlertSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

const tones = [
  { tone: 'info', title: 'Heads up', description: 'Something worth knowing.' },
  { tone: 'success', title: 'Saved', description: 'Every change is in.' },
  { tone: 'warning', title: 'Almost full', description: 'You have used 90% of your storage.' },
  { tone: 'danger', title: 'Could not publish', description: 'The server did not answer.' },
  { tone: 'neutral', title: 'No changes', description: 'Nothing changed since the last save.' },
  { tone: 'accent', title: 'New: themes', description: 'Pick a look for the whole site.' },
] as const

// One alert per tone, each its own selection of the recipe.
export default example({
  title: 'Every tone',
  slots: AlertSlots,
  recipe: Recipes.Alert,
  view: ({ h }) =>
    h.div(
      [h.Style({ display: 'grid', gap: '0.75rem' })],
      tones.map(({ tone, title, description }) =>
        Alert.view(
          {
            layout: 'inline',
            title,
            description,
            style: Recipes.Alert.style({ tone }),
          },
          h,
        ),
      ),
    ),
})

In your application: recipe goes to forSlots, 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 ↗

  • Keeping focus when something is removed A control that leaves the page takes its focus with it: say where focus goes next, to a neighbour (FocusRecovery), to the opener (focusReturn) or to a control (keepFocus).