Components

Tooltip

A hint on hover or focus, after a short wait.

Previews are drawn in the theme you made.

Edit it
arrow
scheme
direction

Above #

import * as UiTooltip from '@foldkit/ui/tooltip'
import { Bundles, Recipes, Tooltip, TooltipSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// In the top layer, above its trigger by default; the arrow points at the
// trigger, which `toView` finds by the Tooltip's id. A tooltip is never
// interactive: what needs a button inside is a Popover or a hover card.
export default example({
  title: 'Above',
  slots: TooltipSlots,
  recipe: Recipes.Tooltip,
  state: Bundles.Tooltip.with({ id: 'autosave' }),
  view: ({ style, model, onMessage, h }) =>
    h.submodel({
      slotId: model.id,
      model,
      view: UiTooltip.view,
      viewInputs: {
        anchor: Tooltip.anchor(),
        toView: Tooltip.toView([style.mixin], { h, id: model.id }, tooltip =>
          h.div(
            [],
            [
              h.button(tooltip.trigger, ['Autosave']),
              ...(tooltip.isVisible
                ? [
                    h.div(tooltip.layer, [
                      h.div(tooltip.panel, [
                        h.span(tooltip.arrow, []),
                        'Saved a second after you stop typing',
                      ]),
                    ]),
                  ]
                : []),
            ],
          ),
        ),
      },
      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.

import * as UiTooltip from '@foldkit/ui/tooltip'
import { Bundles, Recipes, Tooltip, TooltipSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// Beside its trigger, at the end of the line, after a longer rest of the
// pointer: `showDelay` is in milliseconds.
export default example({
  title: 'Right, after a pause',
  slots: TooltipSlots,
  recipe: Recipes.Tooltip,
  state: Bundles.Tooltip.with({ id: 'autosave-right', showDelay: 600 }),
  view: ({ style, model, onMessage, h }) =>
    h.submodel({
      slotId: model.id,
      model,
      view: UiTooltip.view,
      viewInputs: {
        anchor: Tooltip.anchor({ placement: 'right' }),
        toView: Tooltip.toView([style.mixin], { h, id: model.id }, tooltip =>
          h.div(
            [],
            [
              h.button(tooltip.trigger, ['Autosave']),
              ...(tooltip.isVisible
                ? [
                    h.div(tooltip.layer, [
                      h.div(tooltip.panel, [
                        h.span(tooltip.arrow, []),
                        'Saved a second after you stop typing',
                      ]),
                    ]),
                  ]
                : []),
            ],
          ),
        ),
      },
      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.

At the edge #

import * as UiTooltip from '@foldkit/ui/tooltip'
import { Bundles, Recipes, Tooltip, TooltipSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'

// A trigger at the viewport's edge: the pill shifts to stay 8px inside it,
// and the arrow still points at the trigger.
export default example({
  title: 'At the edge',
  slots: TooltipSlots,
  recipe: Recipes.Tooltip,
  state: Bundles.Tooltip.with({ id: 'autosave-edge' }),
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ display: 'flex', justifyContent: 'end' })],
      [
        h.submodel({
          slotId: model.id,
          model,
          view: UiTooltip.view,
          viewInputs: {
            anchor: Tooltip.anchor(),
            toView: Tooltip.toView([style.mixin], { h, id: model.id }, tooltip =>
              h.div(
                [],
                [
                  h.button(tooltip.trigger, ['Autosave']),
                  ...(tooltip.isVisible
                    ? [
                        h.div(tooltip.layer, [
                          h.div(tooltip.panel, [
                            h.span(tooltip.arrow, []),
                            'Saved a second after you stop typing',
                          ]),
                        ]),
                      ]
                    : []),
                ],
              ),
            ),
          },
          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.