Components
CopyButton
Unstable: copies text to the clipboard, then reads "Copied" for 2 seconds and announces it. It lives on the dark code surface of a CodeBlock. Import it from @nizivo/react/unstable/copy-button.
Examples
Basic
On the dark code surface it lives on: a CodeBlock's Copy, which reads "Copied" for 2 seconds.
npm i @nizivo/reactimport type { JSX } from 'react';
import { CodeBlock } from '@nizivo/react/unstable/code-block';
export function CopyButtonExample(): JSX.Element {
return <CodeBlock variant="command" items={[{ label: 'npm', code: 'npm i @nizivo/react' }]} />;
}
Import
import { CopyButton } from '@nizivo/react/unstable/copy-button';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/copy-button.css';Static or interactive
Client. It writes to the clipboard. How to choose.
Use
value is the text to copy. After a copy the button reads "Copied" for 2 seconds, and a polite live
region says so; its name stays "Copy". onCopied hears the copy, and onCopyFailed hears why
the clipboard refused (nothing claims a copy then). It is drawn for the dark
CodeBlock surface.
Props
Client component Renders data-slot="copy-button" with the class nz-copy-button. Props: CopyButtonProps. Source: src/unstable/copy-button/copy-button.client.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
labels | Partial<CopyButtonLabels> | – | |
onCopied | (value: string) => void | – | |
onCopyFailed | (error: unknown) => void | – | |
render | RenderProp<CopyButtonState> | – | Must render a |
valuerequired | string | – | The text to copy. |
- Also takes every attribute of
<button>exceptchildren,value. (Omit<ComponentPropsWithRef<"button">, "value" | "children">)
render takes an element, or, in client code, a function of the props and this state (CopyButtonState):
| Name | Type | Default | Description |
|---|---|---|---|
copiedrequired | boolean | – |
Other exports
CopyButtonLabelstypeimport type { CopyButtonLabels } from '@nizivo/react/unstable/copy-button'CopyButton's own strings (§16.4): serialisable, English defaults.
Name Type Default Description copiedrequiredstring'Copied'Shown and announced for 2 seconds after a copy.
copyrequiredstring'Copy'CopyButtonPropstypeimport type { CopyButtonProps } from '@nizivo/react/unstable/copy-button'The props of
CopyButton, listed above.CopyButtonStatetypeimport type { CopyButtonState } from '@nizivo/react/unstable/copy-button'The render state of
CopyButton, 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 |
|---|---|---|
copy-button.nz-copy-button | CopyButtonroot (takes render); interactive, focus: self |
|
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.
This stylesheet reads no public hook.
Layers: nz.components. Classes: .nz-copy-button, .nz-copy-button-icon.
Tokens this stylesheet reads (8)
--nz-bg-code-elevated, --nz-font-label-s, --nz-radius-sm, --nz-size-icon-sm, --nz-space-1-5, --nz-space-2, --nz-text-code, --nz-text-inverse-accent
Accessibility
These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:
copy-button: draws the focus outline itself on keyboard focus.
Keyboard
To be written.
Container
Centres page content: at most --nz-layout-content-max wide (358, 976, 1280 px by viewport), with the responsive page margin --nz-grid-margin (16, 24, 32 px) on both sides.
CtaBand
Unstable: the last ask on a page, a heading, one line and two actions centred on a dark band. Import it from @nizivo/react/unstable/cta-band.