Kbd
A key on the keyboard.
Previews are drawn in the theme you made.
Edit itA key #
Press Enter to send.
import { Kbd, KbdSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// A key names what to press, never an action: pair it with words.
export default example({
title: 'A key',
slots: KbdSlots,
recipe: Recipes.Kbd,
view: ({ style, h }) => h.p([], ['Press ', Kbd.view({ key: 'Enter', style }, h), ' to send.']),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Combinations #
Search with ⌘K.
Open the command palette with Ctrl+Shift+P.
import { Kbd, KbdSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// Keys pressed together are one `kbd` holding a `kbd` per key. A `joiner`
// sits between keys whose names run together without one, and is read aloud.
export default example({
title: 'Combinations',
slots: KbdSlots,
recipe: Recipes.Kbd,
view: ({ style, h }) =>
h.div(
[],
[
h.p([], ['Search with ', Kbd.combo({ keys: ['⌘', 'K'], style }, h), '.']),
h.p(
[],
[
'Open the command palette with ',
Kbd.combo({ keys: ['Ctrl', 'Shift', 'P'], joiner: '+', style }, h),
'.',
],
),
],
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Keys that are drawings #
Move with .
import { Kbd, KbdSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'
// A key may be a drawing: an arrow, or a modifier's own glyph. The key's
// accessible name is still its words, so a drawing carries its own label.
export default example({
title: 'Keys that are drawings',
slots: KbdSlots,
recipe: Recipes.Kbd,
view: ({ style, h }) =>
h.p(
[],
[
'Move with ',
Kbd.combo(
{
keys: [
h.span([h.Role('img'), h.AriaLabel('Left arrow')], [outline(h, 'M10 3L5 8l5 5')]),
h.span([h.Role('img'), h.AriaLabel('Right arrow')], [outline(h, 'M6 3l5 5-5 5')]),
],
style,
},
h,
),
'.',
],
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Beside a button #
import { Button, Kbd, KbdSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
const Face = Recipes.Button.style({ tone: 'neutral', variant: 'outline' })
// A shortcut beside a button's label: a Button's `trailing` holds the combination.
export default example({
title: 'Beside a button',
slots: KbdSlots,
recipe: Recipes.Kbd,
view: ({ style, h }) =>
row(h, [
Button.view(
{ label: 'Search', trailing: Kbd.combo({ keys: ['⌘', 'K'], style }, h), style: Face },
h,
),
Button.view(
{ label: 'Save', trailing: Kbd.combo({ keys: ['⌘', 'S'], style }, h), style: Face },
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.