Components

Popover

A panel placed beside its button, closed by Escape or a press outside.

Previews are drawn in the theme you made.

Edit it
size
arrow
scheme
direction

Below #

import * as UiPopover from '@foldkit/ui/popover'
import { Bundles, Popover, PopoverSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// In the browser's top layer, below its trigger by default and kept inside
// the viewport; the arrow points back at the trigger. `isAnimated` keeps the
// panel drawn while it leaves, so the recipe's fade runs both ways.
export default example({
  title: 'Below',
  slots: PopoverSlots,
  recipe: Recipes.Popover,
  state: Bundles.Popover.with({ id: 'share-popover', isAnimated: true }),
  view: ({ style, model, onMessage, h }) =>
    h.submodel({
      slotId: model.id,
      model,
      view: UiPopover.view,
      viewInputs: {
        anchor: Popover.anchor(),
        toView: Popover.toView([style.mixin], { h }, popover =>
          h.div(
            [],
            [
              h.button(popover.button, ['Share']),
              ...(popover.isVisible
                ? [
                    h.div(popover.backdrop, []),
                    h.div(popover.layer, [
                      h.div(popover.panel, [
                        h.div(popover.arrow, []),
                        h.p([], ['Anyone with the link can view this page.']),
                      ]),
                    ]),
                  ]
                : []),
            ],
          ),
        ),
      },
      toParentMessage: onMessage,
    }),
})

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.

Top start #

import * as UiPopover from '@foldkit/ui/popover'
import { Bundles, Popover, PopoverSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// Above its trigger, their start edges lined up; it flips below when there
// is no room. `Popover.anchor` takes any `placement`, gap and padding.
export default example({
  title: 'Top start',
  slots: PopoverSlots,
  recipe: Recipes.Popover,
  state: Bundles.Popover.with({ id: 'share-top-start', isAnimated: true }),
  view: ({ style, model, onMessage, h }) =>
    h.submodel({
      slotId: model.id,
      model,
      view: UiPopover.view,
      viewInputs: {
        anchor: Popover.anchor({ placement: 'top-start' }),
        toView: Popover.toView([style.mixin], { h }, popover =>
          h.div(
            [],
            [
              h.button(popover.button, ['Share']),
              ...(popover.isVisible
                ? [
                    h.div(popover.backdrop, []),
                    h.div(popover.layer, [
                      h.div(popover.panel, [
                        h.div(popover.arrow, []),
                        h.p([], ['Anyone with the link can view this page.']),
                      ]),
                    ]),
                  ]
                : []),
            ],
          ),
        ),
      },
      toParentMessage: onMessage,
    }),
})

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.

No arrow #

import * as UiPopover from '@foldkit/ui/popover'
import { Bundles, Popover, PopoverSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// The same panel with no arrow: the recipe's `arrow: 'none'`, over the same
// markup, so the arrow element is still drawn and only hidden.
export default example({
  title: 'No arrow',
  slots: PopoverSlots,
  recipe: Recipes.Popover,
  pins: { arrow: 'none' },
  state: Bundles.Popover.with({ id: 'share-no-arrow', isAnimated: true }),
  view: ({ style, model, onMessage, h }) =>
    h.submodel({
      slotId: model.id,
      model,
      view: UiPopover.view,
      viewInputs: {
        anchor: Popover.anchor(),
        toView: Popover.toView([style.mixin], { h }, popover =>
          h.div(
            [],
            [
              h.button(popover.button, ['Share']),
              ...(popover.isVisible
                ? [
                    h.div(popover.backdrop, []),
                    h.div(popover.layer, [
                      h.div(popover.panel, [
                        h.div(popover.arrow, []),
                        h.p([], ['Anyone with the link can view this page.']),
                      ]),
                    ]),
                  ]
                : []),
            ],
          ),
        ),
      },
      toParentMessage: onMessage,
    }),
})

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 clipped card #

import * as UiPopover from '@foldkit/ui/popover'
import { Bundles, Popover, PopoverSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// Its trigger in a card that clips what overflows it: the panel, in the top
// layer, paints past the card's edge all the same.
export default example({
  title: 'In a clipped card',
  slots: PopoverSlots,
  recipe: Recipes.Popover,
  state: Bundles.Popover.with({ id: 'share-clipped', isAnimated: true }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [
        h.Style({
          overflow: 'hidden',
          padding: '1rem',
          blockSize: '4.5rem',
          border: '1px dashed currentColor',
          borderRadius: '0.5rem',
        }),
      ],
      [
        h.submodel({
          slotId: model.id,
          model,
          view: UiPopover.view,
          viewInputs: {
            anchor: Popover.anchor(),
            toView: Popover.toView([style.mixin], { h }, popover =>
              h.div(
                [],
                [
                  h.button(popover.button, ['Share']),
                  ...(popover.isVisible
                    ? [
                        h.div(popover.backdrop, []),
                        h.div(popover.layer, [
                          h.div(popover.panel, [
                            h.div(popover.arrow, []),
                            h.p([], ['Anyone with the link can view this page.']),
                          ]),
                        ]),
                      ]
                    : []),
                ],
              ),
            ),
          },
          toParentMessage: onMessage,
        }),
      ],
    ),
})

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.