Kbd
A keyboard shortcut drawn for both platforms, such as ⌘K and Ctrl+K; CSS shows the one for the current platform.
Import
import { Kbd } from '@nizivo/react/kbd';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/kbd.css';Static or interactive
Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build
mode; its code is bundled only when a client component (a 'use client' file) imports it. It
renders both platforms' keys and CSS shows one, from the data-nz-platform attribute that
ThemeScript sets; without ThemeScript the Ctrl spelling shows. How to choose.
In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.
Examples
Basic
Search with ⌘KCtrl+K, duplicate with ⌘⇧DCtrl+Shift+D, move with ↑↓ and close with esc.
import type { JSX } from 'react';
import { Kbd } from '@nizivo/react/kbd';
export function KbdExample(): JSX.Element {
return (
<p>
Search with <Kbd keys="mod+k" />, duplicate with <Kbd keys="mod+shift+d" />, move with{' '}
<Kbd>↑↓</Kbd> and close with <Kbd keys="esc" />.
</p>
);
}
Props
Server component Renders data-slot="kbd" with the class nz-kbd. Props: KbdProps. Source: src/kbd/kbd.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | Literal key text, for example |
keys | string | – | A shortcut such as |
render | RenderProp<Record<string, never>> | – |
- Also takes every attribute of
<kbd>;childrenis redeclared above. (ComponentPropsWithRef<"kbd">)
render takes an element, or, in client code, a function of the props and no state.
Other exports
KbdPlatformtypeimport type { KbdPlatform } from '@nizivo/react/kbd'The
data-platformvalues of the glyph spans; they matchdata-nz-platform(§8.3).type KbdPlatform = "apple" | "other"KbdPropstypeimport type { KbdProps } from '@nizivo/react/kbd'The props of
Kbd, listed above.
Data attributes and slots
Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.
| Slot | Rendered by | Data attributes |
|---|---|---|
kbd.nz-kbd | Kbdroot (takes render) | none |
kbd-glyphs.nz-kbd-glyphs | Kbdinner element (CSS only) |
|
CSS hooks
Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.
| Hook | Default | Read as |
|---|---|---|
--nz-kbd-bg | --nz-bg-subtle |
|
--nz-kbd-border | --nz-border-default |
|
--nz-kbd-fg | --nz-text-secondary |
|
--nz-kbd-radius | --nz-radius-xs |
|
Layers: nz.components. Classes: .nz-kbd, .nz-kbd-glyphs.
Tokens this stylesheet reads (8)
--nz-bg-subtle, --nz-border-default, --nz-border-width-default, --nz-font-mono-m, --nz-radius-xs, --nz-space-1-5, --nz-text-secondary, --nz-tracking-mono-m
Accessibility
Nothing in this component takes focus or keyboard input.
Keyboard
None.
Figma
Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.
- Canonical: none
- Ghost masters: none
Input
A single-line native text input in a bordered box, with optional icons and text affixes. Inside a Field it is labelled, described and validated by the Field.
KpiTile
One number, its change and its shape, on Card's surface. Tint a row of related KPIs with tone, which no longer follows the trend. The Suspense fallback is the same tile with status="loading".