@kb.ui/react 0.10.4 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -707
- package/dist/components/Accordion/Accordion.d.ts +33 -0
- package/dist/components/Avatar/Avatar.d.ts +19 -0
- package/dist/components/Code/Code.d.ts +26 -3
- package/dist/components/Code/tokenize.d.ts +5 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +10 -0
- package/dist/components/Collection/Collection.d.ts +99 -0
- package/dist/components/Collection/useCollection.d.ts +66 -0
- package/dist/components/CollectionList/CollectionList.d.ts +12 -0
- package/dist/components/CollectionRow/CollectionRow.d.ts +17 -0
- package/dist/components/Combobox/Combobox.d.ts +14 -2
- package/dist/components/ConfirmAction/ConfirmAction.d.ts +42 -0
- package/dist/components/CopyableText/CopyableText.d.ts +38 -0
- package/dist/components/CopyableText/content.d.ts +14 -0
- package/dist/components/Dashboard/Dashboard.d.ts +17 -0
- package/dist/components/DescriptionList/DescriptionList.d.ts +20 -0
- package/dist/components/Dialog/Dialog.d.ts +3 -1
- package/dist/components/Disclosure/Disclosure.d.ts +21 -0
- package/dist/components/EmptyState/EmptyState.d.ts +30 -0
- package/dist/components/Form/Form.d.ts +19 -0
- package/dist/components/FormSection/FormSection.d.ts +26 -0
- package/dist/components/Gallery/Gallery.d.ts +26 -0
- package/dist/components/Grid/Grid.d.ts +17 -6
- package/dist/components/Image/Image.d.ts +20 -0
- package/dist/components/Link/Link.d.ts +15 -2
- package/dist/components/PageHeader/PageHeader.d.ts +27 -0
- package/dist/components/Panel/Panel.d.ts +3 -1
- package/dist/components/Popover/Popover.d.ts +55 -0
- package/dist/components/Settings/Settings.d.ts +11 -0
- package/dist/components/Skeleton/Skeleton.d.ts +34 -0
- package/dist/components/Spinner/Spinner.d.ts +26 -0
- package/dist/components/Stack/Stack.d.ts +15 -0
- package/dist/components/StatsRow/StatsRow.d.ts +33 -0
- package/dist/components/SupportingPane/SupportingPane.d.ts +15 -0
- package/dist/components/Table/Table.d.ts +65 -0
- package/dist/components/Tabs/Tabs.d.ts +69 -0
- package/dist/components/Tabs/index.d.ts +1 -0
- package/dist/components/Thumbnail/Thumbnail.d.ts +14 -0
- package/dist/components/Toast/Toast.d.ts +72 -0
- package/dist/index.d.ts +39 -4
- package/dist/index.js +3901 -1238
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utils/CollapsiblePanel.d.ts +10 -0
- package/dist/utils/useClipboard.d.ts +28 -0
- package/docs/components/Accordion.md +66 -0
- package/docs/components/Avatar.md +80 -0
- package/docs/components/Badge.md +37 -0
- package/docs/components/Button.md +46 -0
- package/docs/components/Callout.md +41 -0
- package/docs/components/Card.md +41 -0
- package/docs/components/Checkbox.md +60 -0
- package/docs/components/Code.md +77 -0
- package/docs/components/CodeBlock.md +77 -0
- package/docs/components/Collection.md +183 -0
- package/docs/components/CollectionList.md +44 -0
- package/docs/components/CollectionRow.md +62 -0
- package/docs/components/Combobox.md +88 -0
- package/docs/components/ConfirmAction.md +100 -0
- package/docs/components/Container.md +41 -0
- package/docs/components/CopyableText.md +93 -0
- package/docs/components/Dashboard.md +81 -0
- package/docs/components/DescriptionList.md +61 -0
- package/docs/components/Dialog.md +84 -0
- package/docs/components/Disclosure.md +53 -0
- package/docs/components/EmptyState.md +50 -0
- package/docs/components/ErrorSummary.md +48 -0
- package/docs/components/Fieldset.md +42 -0
- package/docs/components/FileInput.md +74 -0
- package/docs/components/Form.md +67 -0
- package/docs/components/FormActions.md +45 -0
- package/docs/components/FormSection.md +57 -0
- package/docs/components/Gallery.md +84 -0
- package/docs/components/Grid.md +66 -0
- package/docs/components/Heading.md +40 -0
- package/docs/components/Image.md +62 -0
- package/docs/components/Inline.md +42 -0
- package/docs/components/Input.md +82 -0
- package/docs/components/Link.md +52 -0
- package/docs/components/Menu.md +44 -0
- package/docs/components/MultiSelect.md +59 -0
- package/docs/components/NumberField.md +65 -0
- package/docs/components/PageHeader.md +68 -0
- package/docs/components/Panel.md +153 -0
- package/docs/components/Popover.md +89 -0
- package/docs/components/Progress.md +37 -0
- package/docs/components/RadioGroup.md +69 -0
- package/docs/components/ScrollArea.md +40 -0
- package/docs/components/Select.md +71 -0
- package/docs/components/Separator.md +40 -0
- package/docs/components/Settings.md +57 -0
- package/docs/components/Skeleton.md +86 -0
- package/docs/components/Spinner.md +45 -0
- package/docs/components/Split.md +47 -0
- package/docs/components/Stack.md +54 -0
- package/docs/components/Stat.md +34 -0
- package/docs/components/StatsRow.md +80 -0
- package/docs/components/Status.md +48 -0
- package/docs/components/SupportingPane.md +59 -0
- package/docs/components/Switch.md +73 -0
- package/docs/components/Table.md +105 -0
- package/docs/components/Tabs.md +89 -0
- package/docs/components/Text.md +36 -0
- package/docs/components/Textarea.md +47 -0
- package/docs/components/Thumbnail.md +66 -0
- package/docs/components/Toast.md +130 -0
- package/docs/components/Toolbar.md +39 -0
- package/docs/components/Tooltip.md +42 -0
- package/package.json +3 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
type CollapsiblePanelProps<State> = {
|
|
3
|
+
nativeProps: useRender.ElementProps<"div">;
|
|
4
|
+
state: State;
|
|
5
|
+
render?: useRender.RenderProp<State> | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function CollapsiblePanel<State extends {
|
|
8
|
+
open: boolean;
|
|
9
|
+
}>({ nativeProps, state, render, }: CollapsiblePanelProps<State>): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type CopyState = "idle" | "pending" | "copied" | "failed";
|
|
2
|
+
export type CopyFeedbackProps = {
|
|
3
|
+
/** Disable copying while keeping content selectable. */
|
|
4
|
+
disabled?: boolean | undefined;
|
|
5
|
+
/** Idle copy button text and accessible name. */
|
|
6
|
+
copyLabel?: string | undefined;
|
|
7
|
+
/** Pending copy button text. */
|
|
8
|
+
copyingLabel?: string | undefined;
|
|
9
|
+
/** Successful copy button text. */
|
|
10
|
+
copiedLabel?: string | undefined;
|
|
11
|
+
/** Failed copy button text; activation retries. */
|
|
12
|
+
copyErrorLabel?: string | undefined;
|
|
13
|
+
/** Polite success announcement. */
|
|
14
|
+
successMessage?: string | undefined;
|
|
15
|
+
/** Visible, polite failure message with recovery instructions. */
|
|
16
|
+
errorMessage?: string | undefined;
|
|
17
|
+
/** Success feedback lifetime in milliseconds; zero keeps feedback until next action. */
|
|
18
|
+
feedbackDuration?: number | undefined;
|
|
19
|
+
/** Called after clipboard write succeeds for current content. */
|
|
20
|
+
onCopy?: ((value: string) => void) | undefined;
|
|
21
|
+
/** Called when current clipboard write fails, including unavailable Clipboard API. */
|
|
22
|
+
onCopyError?: ((error: unknown) => void) | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare function useClipboard(value: string, { disabled, feedbackDuration, onCopy, onCopyError }: CopyFeedbackProps): {
|
|
25
|
+
state: CopyState;
|
|
26
|
+
copy: () => Promise<void>;
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Accordion
|
|
2
|
+
|
|
3
|
+
Group related disclosures under headings. Single expansion is the default; enable `multiple` when several answers or sections should remain visible together.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-accordion--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Accordion } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function DeliveryQuestions() {
|
|
14
|
+
return (
|
|
15
|
+
<Accordion multiple defaultValue={["delivery"]}>
|
|
16
|
+
<Accordion.Item value="delivery">
|
|
17
|
+
<Accordion.Header render={<h2 />}>
|
|
18
|
+
<Accordion.Trigger>When will my order arrive?</Accordion.Trigger>
|
|
19
|
+
</Accordion.Header>
|
|
20
|
+
<Accordion.Panel>Orders dispatch within two working days.</Accordion.Panel>
|
|
21
|
+
</Accordion.Item>
|
|
22
|
+
<Accordion.Item value="returns">
|
|
23
|
+
<Accordion.Header render={<h2 />}>
|
|
24
|
+
<Accordion.Trigger>Can I return an item?</Accordion.Trigger>
|
|
25
|
+
</Accordion.Header>
|
|
26
|
+
<Accordion.Panel>Contact support with your order number.</Accordion.Panel>
|
|
27
|
+
</Accordion.Item>
|
|
28
|
+
</Accordion>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## More examples
|
|
34
|
+
|
|
35
|
+
- [Multiple](https://kbui.kcb.pro/storybook/?path=/story/components-accordion--multiple): independent expanded sections.
|
|
36
|
+
- [Controlled](https://kbui.kcb.pro/storybook/?path=/story/components-accordion--controlled): application-owned values.
|
|
37
|
+
- [Nested](https://kbui.kcb.pro/storybook/?path=/story/components-accordion--nested): independent groups with contextual heading ranks.
|
|
38
|
+
- [Disabled](https://kbui.kcb.pro/storybook/?path=/story/components-accordion--disabled): unavailable controls with readable expanded details.
|
|
39
|
+
|
|
40
|
+
## Reference
|
|
41
|
+
|
|
42
|
+
| Part / prop | Type | Default | Purpose |
|
|
43
|
+
|---|---|---|---|
|
|
44
|
+
| `Accordion<Value>` | Base UI `Accordion` root props | `div` | Groups items; generic values preserve callback types. |
|
|
45
|
+
| `value` / `defaultValue` | `Value[]` | `[]` | Controlled or initial expanded item values. Use arrays in both modes. |
|
|
46
|
+
| `onValueChange` | `(values, details) => void` | — | Requests expansion changes; `details.cancel()` rejects them. |
|
|
47
|
+
| `multiple` | `boolean` | `false` | Allows independent expanded items. |
|
|
48
|
+
| `disabled` | `boolean` | `false` | Disables all triggers; does not conceal already open content. |
|
|
49
|
+
| `keepMounted` / `hiddenUntilFound` | `boolean` | `false` | Root defaults for panel retention or supported browser search reveal. |
|
|
50
|
+
| `Accordion.Item` | Base UI `Accordion` item props | `div` | Requires a stable unique `value` for controlled usage; accepts item `disabled`. |
|
|
51
|
+
| `Accordion.Header` | Base UI `Accordion` heading props | `h3` | Contains the trigger; use `render={<h2 />}` or another heading for document hierarchy. |
|
|
52
|
+
| `Accordion.Trigger` | Base UI `Accordion` trigger props | `button` | Visible section label and expansion control. |
|
|
53
|
+
| `Accordion.Panel` | Base UI `Accordion` panel props | Named `region` | Owns content; accepts per-panel retention options. |
|
|
54
|
+
| `className` / `render` / `ref` | Part-specific native props | — | Customize each part; class names accept strings. |
|
|
55
|
+
|
|
56
|
+
Tab and Shift+Tab visit enabled triggers and expanded controls in DOM order. Enter/Space toggle the focused item. Base UI 1.9 uses normal Tab navigation; its deprecated orientation and `loopFocus` props do not add arrow-key navigation. Closing the last open item is allowed. No business validation is inferred from expansion.
|
|
57
|
+
|
|
58
|
+
Keep essential information discoverable and interactive actions outside the heading button. Avoid an excessive number of region landmarks: keep groups focused and split large documents into meaningful sections. Hidden/unmounted content does not supply persistent form state: use `keepMounted` or caller-owned values. Nested groups own separate state.
|
|
59
|
+
|
|
60
|
+
Style `--kb-accordion-padding`, `-radius`, `-background`, `-color`, `-border` and `-trigger-height`; classes cover root, item, header, trigger and panel. Preserve expanded/disabled attributes and native focus outlines when composing custom renderers.
|
|
61
|
+
|
|
62
|
+
Panels expand and collapse through measured height transitions; reversing mid-transition follows the latest toggle. Content grows naturally once expanded. `--kb-accordion-motion-duration` and `-motion-easing` control panel and caret motion; reduced motion disables transitions. `.kb-accordion-panel-content` owns inner padding, keeping the outer `Panel` measurable without clipping collapsed padding. `Panel` props, `className`, render and ref still target the outer node.
|
|
63
|
+
|
|
64
|
+
## Related components
|
|
65
|
+
|
|
66
|
+
Use [`Disclosure`](Disclosure.md) for a single optional section or [`Panel`](Panel.md) for a structured work surface. Use [`Popover`](Popover.md) for controls anchored outside normal document flow.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Avatar
|
|
2
|
+
|
|
3
|
+
Keep people and organizations recognizable through photo loading, missing images and request failures. Fallback initials share the same fixed frame as the image.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-avatar--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Avatar, Inline, Link, Text } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return (
|
|
15
|
+
<Inline align="center" gap="md">
|
|
16
|
+
<Avatar name="Maya Chen" src="/people/maya.jpg" decorative />
|
|
17
|
+
<div>
|
|
18
|
+
<Link href="/people/maya">Maya Chen</Link>
|
|
19
|
+
<Text size="sm" tone="muted">Design director</Text>
|
|
20
|
+
</div>
|
|
21
|
+
</Inline>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## More examples
|
|
27
|
+
|
|
28
|
+
- [Shapes](https://kbui.kcb.pro/storybook/?path=/story/components-avatar--shapes): Circular, square, rounded, hexagonal and diamond silhouettes with photos and initials.
|
|
29
|
+
- [Sizes](https://kbui.kcb.pro/storybook/?path=/story/components-avatar--sizes): Five fixed dimensions.
|
|
30
|
+
- [Fallbacks](https://kbui.kcb.pro/storybook/?path=/story/components-avatar--fallbacks): Missing/broken photos, multilingual names and organization initials.
|
|
31
|
+
- [People](https://kbui.kcb.pro/storybook/?path=/story/components-avatar--people): Visible identity, profile link and role.
|
|
32
|
+
|
|
33
|
+
## Shapes
|
|
34
|
+
|
|
35
|
+
`AvatarShape` accepts `circle`, `square`, `rounded`, `hexagon` and `diamond`. `square` has zero corner radius; `rounded` uses softly rounded corners.
|
|
36
|
+
|
|
37
|
+
Shape changes only the silhouette. Photos and initials remain upright, and the accessible identity, size and image request state stay unchanged. Hexagon and diamond clip the media frame to their polygon; they do not rotate the content.
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import "@kb.ui/react/styles.css";
|
|
41
|
+
import { Avatar, type AvatarShape, Inline } from "@kb.ui/react";
|
|
42
|
+
|
|
43
|
+
const organizationShape: AvatarShape = "hexagon";
|
|
44
|
+
|
|
45
|
+
export function ShapedIdentity() {
|
|
46
|
+
return (
|
|
47
|
+
<Inline gap="lg" align="center">
|
|
48
|
+
<Avatar name="Maya Chen" shape="circle" />
|
|
49
|
+
<Avatar name="North Studio" initials="N" shape="square" />
|
|
50
|
+
<Avatar name="Design team" initials="D" shape="rounded" style={{ borderRadius: "var(--kb-radius-sm)" }} />
|
|
51
|
+
<Avatar name="Field team" initials="F" shape={organizationShape} />
|
|
52
|
+
<Avatar name="Studio collection" initials="S" shape="diamond" />
|
|
53
|
+
</Inline>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The default circle uses `--kb-avatar-radius`; rounded uses the existing `--kb-avatar-square-radius` token. A root `style.borderRadius` overrides the circle, square or rounded frame and is inherited by its media. Polygon clipping remains in effect for hexagon and diamond. Choose short initials that remain legible inside the silhouette, especially at smaller sizes.
|
|
59
|
+
|
|
60
|
+
## Reference
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Notes |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `name` | `string` | required | Full accessible identity; blank names use `Unknown person` |
|
|
65
|
+
| `src`, `srcSet`, `sizes`, `loading` | native image attributes | unset | Photo request and responsive selection |
|
|
66
|
+
| `initials` | `string` | first and last name initials | Override for local naming conventions, handles or brand marks |
|
|
67
|
+
| `decorative` | `boolean` | `false` | Hide duplicate identity when adjacent text supplies it |
|
|
68
|
+
| `size` | `"xs"` \| `"sm"` \| `"md"` \| `"lg"` \| `"xl"` | `"md"` | Defaults: 24, 32, 44, 56 and 80 CSS pixels |
|
|
69
|
+
| `shape` | `AvatarShape` | `"circle"` | `circle`, `square`, `rounded`, `hexagon` or `diamond`; clips upright media |
|
|
70
|
+
| `onLoad`, `onError` | native image handlers | unset | Photo result callbacks |
|
|
71
|
+
| `classNames` | keyed classes | unset | `root`, `media`, `initials` |
|
|
72
|
+
| `ref` | `Ref<HTMLSpanElement>` | unset | Root element; native `span` props pass through |
|
|
73
|
+
|
|
74
|
+
Initials use the first Unicode code point of the first and last whitespace-separated names, uppercased; a single word contributes one initial. This is a convenience, not a universal naming rule. Supply `initials` for the person's preferred form. Empty identities render `?`; localize `Unknown person` through `aria-label`. The accessible name remains the full identity, not the initials.
|
|
75
|
+
|
|
76
|
+
`Avatar` adds no focus stop. Place navigation in a named `Link` or an action in a `Button`. Use `decorative` when an equivalent visible name is adjacent or the parent control already supplies the identity. Keep presence and account state in separately labeled `Status`/`Badge` content. See [media recipes](../../../../docs/guides/media-and-identity.md).
|
|
77
|
+
|
|
78
|
+
## Related components
|
|
79
|
+
|
|
80
|
+
Use [`Image`](Image.md) for flexible media framing, [`Thumbnail`](Thumbnail.md) for captioned previews, and [`Status`](Status.md) for changing state.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Badge
|
|
2
|
+
|
|
3
|
+
Add a short label to a person, record, or resource. Keep the text meaningful without its color. Use `Status` when the information changes over time.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Examples](#more-examples) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-badge--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Badge } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return <Badge>New</Badge>;
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## More examples
|
|
19
|
+
|
|
20
|
+
- [Literal identifiers](https://kbui.kcb.pro/storybook/?path=/story/components-badge--mono): Show an identifier in a monospace font.
|
|
21
|
+
- [Semantic tones](https://kbui.kcb.pro/storybook/?path=/story/components-badge--tones): Check text remains meaningful across tones.
|
|
22
|
+
|
|
23
|
+
## Reference
|
|
24
|
+
|
|
25
|
+
| Prop | Type | Default | Notes |
|
|
26
|
+
| -------------- | ----------------------------------------------------- | --------- | --------------------------------------------------------------------------- |
|
|
27
|
+
| `children` | `ReactNode` | unset | Short metadata such as Reviewer, Draft, or a branch name |
|
|
28
|
+
| `tone` | `neutral` / `info` / `success` / `warning` / `danger` | `neutral` | Reinforces the text with ink and tint |
|
|
29
|
+
| `appearance` | `chip` / `plain` | `chip` | Chip adds a tinted surface; plain stays inline |
|
|
30
|
+
| `mono` | `boolean` | `false` | Small uppercase monospace for short identifiers |
|
|
31
|
+
| `preserveCase` | `boolean` | `false` | Preserve case and spacing for branch names, paths, and other literal values |
|
|
32
|
+
|
|
33
|
+
You can pass native `<span>` props. `Badge` adds no Tab stop or live announcement.
|
|
34
|
+
|
|
35
|
+
## Related components
|
|
36
|
+
|
|
37
|
+
Use [`Status`](Status.md) for changing state and [`Code`](Code.md) for code within prose.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Button
|
|
2
|
+
|
|
3
|
+
Use a `Button` for an action such as saving a form or opening a dialog. Choose a variant to match the action’s importance.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Examples](#more-examples) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-button--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Button } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return <Button type="submit">Save changes</Button>;
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## More examples
|
|
19
|
+
|
|
20
|
+
- [Styled navigation](https://kbui.kcb.pro/storybook/?path=/story/components-button--as-link): Render a link with the correct semantics.
|
|
21
|
+
- [Icon-only actions](https://kbui.kcb.pro/storybook/?path=/story/components-button--icon-only): Give the action an accessible name.
|
|
22
|
+
- [Size choices](https://kbui.kcb.pro/storybook/?path=/story/components-button--sizes): Compare button sizes.
|
|
23
|
+
|
|
24
|
+
## Reference
|
|
25
|
+
|
|
26
|
+
| Prop | Type | Default | Notes |
|
|
27
|
+
| ----------- | ------------------------------------------------- | ----------- | -------------------------------------------------------------------------- |
|
|
28
|
+
| `children` | `ReactNode` | unset | Visible action label, or an icon paired with `aria-label` |
|
|
29
|
+
| `variant` | `"primary" \| "secondary" \| "ghost" \| "danger"` | `"primary"` | Main, supporting, quiet, or destructive action emphasis |
|
|
30
|
+
| `size` | `sm` / `md` / `lg` / `icon` | `md` | Height and padding; `icon` is square and requires `aria-label` |
|
|
31
|
+
| `type` | native `button` type | `button` | Set `type="submit"` for form submission; use `type="button"` for other form actions |
|
|
32
|
+
| `disabled` | `boolean` | `false` | Blocks interaction; explain unavailable actions in nearby text when needed |
|
|
33
|
+
| `render` | element | unset | Use an anchor with `nativeButton={false}` and `role="link"` for navigation |
|
|
34
|
+
| `className` | `string` | unset | Extra classes on the rendered control; function values are not supported |
|
|
35
|
+
|
|
36
|
+
All props accepted by a native `button` or Base UI's `Button` also work. To render a link, pass an anchor and tell Base UI it is not a native `button`:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
<Button render={<a href="/docs" />} nativeButton={false} role="link">
|
|
40
|
+
Docs
|
|
41
|
+
</Button>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Related components
|
|
45
|
+
|
|
46
|
+
Use [`Link`](Link.md) for navigation. Group coordinated actions with [`Toolbar`](Toolbar.md), or independent wrapping actions with [`Inline`](Inline.md).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Callout
|
|
2
|
+
|
|
3
|
+
Keep a useful message close to the content it explains. Give people a concrete next step when they can resolve the issue.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Examples](#more-examples) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-callout--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Callout } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return (
|
|
15
|
+
<Callout title="Changes saved" tone="success">
|
|
16
|
+
You can close this page.
|
|
17
|
+
</Callout>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## More examples
|
|
23
|
+
|
|
24
|
+
- [Resolvable messages](https://kbui.kcb.pro/storybook/?path=/story/components-callout--with-actions): Place a next step beside its explanation.
|
|
25
|
+
- [Message tones](https://kbui.kcb.pro/storybook/?path=/story/components-callout--tones): Compare how tone reinforces written meaning.
|
|
26
|
+
|
|
27
|
+
## Reference
|
|
28
|
+
|
|
29
|
+
| Prop | Type | Default | Notes |
|
|
30
|
+
| ------------ | ----------------------------------------------------- | --------- | --------------------------------------------------------------- |
|
|
31
|
+
| `children` | `ReactNode` | unset | Message body; explain what happened and what to do next |
|
|
32
|
+
| `title` | `ReactNode` | unset | Short summary above the message |
|
|
33
|
+
| `tone` | `neutral` / `info` / `success` / `warning` / `danger` | `neutral` | Reinforces the message without replacing its wording |
|
|
34
|
+
| `icon` | `ReactNode` | unset | Decorative icon; hidden from assistive technology |
|
|
35
|
+
| `actions` | `ReactNode` | unset | Named buttons or links that help resolve the message; end-aligned, primary last |
|
|
36
|
+
| `live` | `boolean` | `false` | Adds `role=status` for changing message text; does not move focus |
|
|
37
|
+
| `classNames` | keyed classes | unset | Style icon, content, title, body, or actions |
|
|
38
|
+
|
|
39
|
+
## Related components
|
|
40
|
+
|
|
41
|
+
Use [`Status`](Status.md) for a short changing state and [`Dialog`](Dialog.md) for a focused modal task.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Card
|
|
2
|
+
|
|
3
|
+
Group related content with an optional title, summary, links, and actions. `Card` renders an article by default and adds no interaction of its own.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Examples](#more-examples) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-card--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Card } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return (
|
|
15
|
+
<Card>
|
|
16
|
+
<h2>Project summary</h2>
|
|
17
|
+
<p>Three tasks remain.</p>
|
|
18
|
+
</Card>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## More examples
|
|
24
|
+
|
|
25
|
+
- [A navigable card](https://kbui.kcb.pro/storybook/?path=/story/components-card--single-link): Use a real link for the primary destination.
|
|
26
|
+
- [Quiet content rows](https://kbui.kcb.pro/storybook/?path=/story/components-card--plain): Show a flat card without a raised surface.
|
|
27
|
+
|
|
28
|
+
## Reference
|
|
29
|
+
|
|
30
|
+
| Prop | Type | Default | Notes |
|
|
31
|
+
| --------------------------- | ------------------------ | ---------- | --------------------------------------------------------------------- |
|
|
32
|
+
| `as` | `article` / `div` / `li` | `article` | Choose the container for the document structure; use li inside a list |
|
|
33
|
+
| `appearance` | `outlined` / `plain` | `outlined` | Outlined adds a raised surface; plain stays flat with a dividing line |
|
|
34
|
+
| `children` | `ReactNode` | unset | Related content; your app provides headings, links, and actions |
|
|
35
|
+
| `className`, `style`, `ref` | native element props | unset | Style and reference the chosen container |
|
|
36
|
+
|
|
37
|
+
`Card` adds no link, button, keyboard handler, or tab stop. If a link covers the whole card, keep other controls outside that link and style its focus state. Restyle with the card background, face, shadow, color, border, radius, and padding tokens; they share the theme's tactile materials.
|
|
38
|
+
|
|
39
|
+
## Related components
|
|
40
|
+
|
|
41
|
+
Arrange a collection with [`Grid`](Grid.md). Use [`Panel`](Panel.md) when a section needs structured header, body, and footer parts.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
Use `Checkbox` when people can select options independently. It includes a label, help text, and error message. Pass `checked` and update it in `onCheckedChange`. Activating a mixed checkbox requests the checked state.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Examples](#more-examples) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-checkbox--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Checkbox } from "@kb.ui/react";
|
|
12
|
+
import { useState } from "react";
|
|
13
|
+
|
|
14
|
+
export function Example() {
|
|
15
|
+
const [checked, setChecked] = useState(false);
|
|
16
|
+
return (
|
|
17
|
+
<Checkbox
|
|
18
|
+
label="Include archived projects"
|
|
19
|
+
checked={checked}
|
|
20
|
+
onCheckedChange={setChecked}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## More examples
|
|
27
|
+
|
|
28
|
+
- [Partial selection](https://kbui.kcb.pro/storybook/?path=/story/components-checkbox--mixed): Show a partly selected group.
|
|
29
|
+
- [Validation feedback](https://kbui.kcb.pro/storybook/?path=/story/components-checkbox--invalid): Show an error for the choice.
|
|
30
|
+
|
|
31
|
+
## Reference
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Notes |
|
|
34
|
+
| ----------------------------- | ---------------------------- | -------- | ------------------------------------------------------- |
|
|
35
|
+
| `label` | `string` | required | Visible accessible label |
|
|
36
|
+
| `checked` | `boolean` | required | Controlled native checked state |
|
|
37
|
+
| `onCheckedChange` | `(checked: boolean) => void` | required | Next checked-state request |
|
|
38
|
+
| `indeterminate` | `boolean` | `false` | Announces mixed state; activation requests checked |
|
|
39
|
+
| `disabled` / `readOnly` | `boolean` | `false` | Block changes; disabled also leaves keyboard order |
|
|
40
|
+
| `description` / `error` | `string` | | Associated helper and invalid-state text |
|
|
41
|
+
| `visuallyHidden` | `boolean` | `false` | Hide label visually |
|
|
42
|
+
| `controlClassName` | `string` | | Added to the native checkbox |
|
|
43
|
+
| `ref` | `Ref<HTMLInputElement>` | | Native checkbox, including form and indeterminate state |
|
|
44
|
+
| `name` / `value` / `required` | native `input` props | | Form serialization and validation |
|
|
45
|
+
| `className` | `string` | | Root class |
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
<Checkbox
|
|
49
|
+
label="Receive release updates"
|
|
50
|
+
name="updates"
|
|
51
|
+
checked={updates}
|
|
52
|
+
onCheckedChange={setUpdates}
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Clicking the label or pressing Space calls `onCheckedChange`. The checkbox changes only when your app updates `checked`; otherwise its checked or mixed state stays as it was. Native input props are supported. `style` applies to the input, and CSS custom properties also reach the visible mark. Use `--kb-checkbox-size` to change its size. In forced colors, the native checkbox and its focus outline remain visible.
|
|
57
|
+
|
|
58
|
+
## Related components
|
|
59
|
+
|
|
60
|
+
Use [`RadioGroup`](RadioGroup.md) for one visible choice and [`Switch`](Switch.md) for an immediate on/off setting.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Code
|
|
2
|
+
|
|
3
|
+
Literal inline code in native `code`, or syntax-highlighted multiline code blocks with a header, copy action, line numbers, line emphasis, and collapsible viewport.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Examples](#more-examples) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-code--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { Code } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return (
|
|
15
|
+
<p>
|
|
16
|
+
Run <Code>bun run build</Code> before publishing.
|
|
17
|
+
</p>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## More examples
|
|
23
|
+
|
|
24
|
+
- [Multiline blocks](https://kbui.kcb.pro/storybook/?path=/story/components-code--multiline): Present source with a language label and copy action.
|
|
25
|
+
- [Line numbers and emphasis](https://kbui.kcb.pro/storybook/?path=/story/components-code--line-numbers-and-highlights): Highlight the relevant part of a listing.
|
|
26
|
+
- [Collapsible listings](https://kbui.kcb.pro/storybook/?path=/story/components-code--collapsible): Keep a long example within a bounded viewport.
|
|
27
|
+
- [Code within prose](https://kbui.kcb.pro/storybook/?path=/story/components-code--in-text): Keep code legible inside a sentence.
|
|
28
|
+
- [Long paths and commands](https://kbui.kcb.pro/storybook/?path=/story/components-code--long-token): Check wrapping with an unbroken token.
|
|
29
|
+
|
|
30
|
+
## Reference
|
|
31
|
+
|
|
32
|
+
| Prop | Type | Default | Notes |
|
|
33
|
+
| -------------------------------- | ------------------------------ | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
34
|
+
| `children` | `ReactNode` | unset | Pass source code as a string; multiline strings auto-switch to block mode |
|
|
35
|
+
| `block` | `boolean` | auto | Force block (`true`) or inline (`false`) rendering |
|
|
36
|
+
| `language` | `CodeLanguage` | `"tsx"` in block mode | Grammar (`tsx`, `ts`, `jsx`, `js`, `css`, `html`, `json`, `bash`, `sh`, `shell`, `plain`, `text`) and badge label |
|
|
37
|
+
| `title` | `string` | unset | Filename or caption in the block header, or native `title` when `block={false}` |
|
|
38
|
+
| `copyable` | `boolean` | `true` in block mode | Show the copy-to-clipboard button in the block header |
|
|
39
|
+
| `onCopy` | `(code: string) => void` | unset | Called with the raw code string after a successful clipboard copy |
|
|
40
|
+
| `lineNumbers` | `boolean` | `false` | Render a non-selectable line-number gutter in block mode |
|
|
41
|
+
| `startLine` | `number` | `1` | Starting line number for `lineNumbers` and `highlightLines` |
|
|
42
|
+
| `highlightLines` | `readonly number[]` | unset | Line numbers (relative to `startLine`) to emphasize |
|
|
43
|
+
| `minLines` | `number` | unset | Minimum visible line count for the block (and default collapsed line count when `collapsible` is enabled without `collapsedLines`) |
|
|
44
|
+
| `collapsible` | `boolean` | `false` | Add an expand/collapse toggle for longer listings |
|
|
45
|
+
| `collapsedLines` | `number` | `minLines` | Visible line count when a `collapsible` block is collapsed |
|
|
46
|
+
| `defaultCollapsed` / `collapsed` | `boolean` | `false` / uncontrolled | Initial or controlled collapsed state when `collapsible` is enabled |
|
|
47
|
+
| `onCollapsedChange` | `(collapsed: boolean) => void` | unset | Called when the user toggles the collapsed state |
|
|
48
|
+
| `maxHeight` | `string \| number` | unset | Maximum viewport height in block mode |
|
|
49
|
+
| `tokens` | `readonly CodeToken[]` | `tokenizeCode()` | Custom `[start, end, kind]` syntax ranges overriding the built-in tokenizer |
|
|
50
|
+
| `classNames` | `ClassNames<CodePart>` | unset | Extra classes for `header`, `meta`, `title`, `language`, `actions`, `toggle`, `copy`, `viewport`, `pre`, `content`, `line`, `lineNumber`, and `lineText` |
|
|
51
|
+
| `className`, `ref` | Native element props | unset | Targets `code` in inline mode or root `div` in block mode |
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Code } from "@kb.ui/react";
|
|
55
|
+
|
|
56
|
+
export function SnippetExample() {
|
|
57
|
+
return (
|
|
58
|
+
<Code
|
|
59
|
+
title="src/theme.ts"
|
|
60
|
+
language="ts"
|
|
61
|
+
lineNumbers
|
|
62
|
+
highlightLines={[2]}
|
|
63
|
+
minLines={4}
|
|
64
|
+
>
|
|
65
|
+
{`export const defaultTheme = "light";\nexport const accent = "persimmon";`}
|
|
66
|
+
</Code>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Single-line strings without block props render as an inline `code` element that inherits surrounding line height and wraps long paths. Strings containing `\n` or any block prop (`language`, `title`, `copyable`, `lineNumbers`, `highlightLines`, `minLines`, `collapsible`, `collapsedLines`, `maxHeight`, `tokens`) switch automatically to a framed block listing unless `block={false}` is set. Line numbers use CSS `attr(data-line-number)` so selecting or reading `code.textContent` returns only the raw code. Customize block surfaces and syntax colors with `--kb-code-block-*` and `--kb-code-syntax-*`.
|
|
72
|
+
|
|
73
|
+
Block copying shares the [copy feedback props](CopyableText.md#reference): `disabled`, `copyLabel`, `copyingLabel`, `copiedLabel`, `copyErrorLabel`, `successMessage`, `errorMessage`, `feedbackDuration` and `onCopyError`. `Code` defaults to `Copy code`, `Copy failed`, `Code copied to clipboard` and `Failed to copy code. Select and copy the text manually.`. `onCopy` is a successful-write callback rather than a native clipboard event handler. Pending writes retain focus and ignore repeated activation; errors remain visible until retry or source change. `classNames.feedback` styles the persistent polite status region. Block viewports expose a named keyboard scroll region using `title` or the label “Code”.
|
|
74
|
+
|
|
75
|
+
## Related components
|
|
76
|
+
|
|
77
|
+
Use [`CodeBlock`](CodeBlock.md) for explicit block semantics, [`CopyableText`](CopyableText.md) for copyable identifiers, [`Text`](Text.md) for prose and [`Link`](Link.md) for a destination.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# CodeBlock
|
|
2
|
+
|
|
3
|
+
An explicit block listing for commands, configuration and source. Reuses `Code` highlighting, line numbers, line emphasis and collapse behavior, with shared copy feedback and a keyboard-scrollable viewport.
|
|
4
|
+
|
|
5
|
+
[All components](../../README.md#components) · [Usage](#usage) · [Reference](#reference) · [Live examples and accessibility](https://kbui.kcb.pro/storybook/?path=/docs/components-codeblock--docs)
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import "@kb.ui/react/styles.css";
|
|
11
|
+
import { CodeBlock } from "@kb.ui/react";
|
|
12
|
+
|
|
13
|
+
export function Example() {
|
|
14
|
+
return (
|
|
15
|
+
<CodeBlock title="Terminal" language="bash" copyLabel="Copy install command">
|
|
16
|
+
{"bun add @kb.ui/react"}
|
|
17
|
+
</CodeBlock>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`children` must be the exact source string. Copy excludes line numbers, syntax markup, highlighted-line decoration and display padding. Collapsed blocks copy the full source. Empty strings disable copying. `CodeBlock` always renders a block, including single-line commands. It uses `.kb-codeblock.kb-code[data-block]`; shared `.kb-code-*` parts and `--kb-code-*` tokens remain compatible with `Code`.
|
|
23
|
+
|
|
24
|
+
Clipboard feedback appears after the actual write resolves. Pending writes suppress repeat activation and preserve button focus. Errors stay visible with manual selection instructions until retry or source change. Success resets after `feedbackDuration` (two seconds by default, zero retains it). Changes to source or disabled state invalidate outstanding feedback; unmounted instances ignore completion. Already-issued operating-system writes cannot be cancelled.
|
|
25
|
+
|
|
26
|
+
The named viewport has a keyboard focus stop for horizontal and vertical scrolling. `title` names that region, falling back to `Code`. Syntax color and line emphasis supplement source text; explain important lines in surrounding prose. The collapse action exposes its expanded state and controlled viewport without moving focus. Use controlled `collapsed` with `onCollapsedChange`, or `defaultCollapsed` for local state.
|
|
27
|
+
|
|
28
|
+
Override `--kb-code-syntax-*` through `style` or a class to change individual syntax colors. The Colorful example maps keyword, string, tag, function and attribute colors to semantic theme tokens. All code and clipboard contents remain unchanged; verify contrast against the listing background after customization.
|
|
29
|
+
|
|
30
|
+
## More examples
|
|
31
|
+
|
|
32
|
+
- [Colorful](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--colorful): customize individual syntax roles with theme colors.
|
|
33
|
+
- [Source](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--source): highlighted TSX with line numbers and emphasis.
|
|
34
|
+
- [Configuration](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--configuration): JSON payload.
|
|
35
|
+
- [Collapsible](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--collapsible): bounded long listings with full-source copy.
|
|
36
|
+
- [Long command](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--long-command): keyboard scrolling without page overflow.
|
|
37
|
+
- [Copy feedback](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--copy-feedback): exact clipboard text and retained focus.
|
|
38
|
+
- [Copy failure](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--copy-failure): visible recovery instructions and retained source.
|
|
39
|
+
- [Localized](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--localized): long translated labels wrap within narrow listings.
|
|
40
|
+
- [Read only](https://kbui.kcb.pro/storybook/?path=/story/components-codeblock--read-only): source without a copy control.
|
|
41
|
+
|
|
42
|
+
## Reference
|
|
43
|
+
|
|
44
|
+
| Prop | Type | Default | Notes |
|
|
45
|
+
| --- | --- | --- | --- |
|
|
46
|
+
| `children` | `string` | required | Exact source, including whitespace and trailing newlines |
|
|
47
|
+
| `title` | `string` | unset | Header text and accessible viewport name |
|
|
48
|
+
| `language` | `CodeLanguage` | unset | `tsx`, `ts`, `jsx`, `js`, `css`, `html`, `json`, `bash` and aliases; `plain` disables syntax coloring |
|
|
49
|
+
| `copyable` | `boolean` | `true` | Show copy action and status region |
|
|
50
|
+
| `disabled` | `boolean` | `false` | Disable copy while retaining source and collapse interaction |
|
|
51
|
+
| `copyLabel`, `copyingLabel`, `copiedLabel`, `copyErrorLabel` | `string` | `"Copy code"`, `"Copying…"`, `"Copied"`, `"Copy failed"` | Visible button names; failed action retries |
|
|
52
|
+
| `successMessage` | `string` | `"Code copied to clipboard"` | Polite success announcement |
|
|
53
|
+
| `errorMessage` | `string` | `"Failed to copy code. Select and copy the text manually."` | Visible polite recovery instructions |
|
|
54
|
+
| `feedbackDuration` | `number` | `2000` | Success reset in milliseconds; zero retains feedback, invalid or negative uses default |
|
|
55
|
+
| `onCopy` | `(source: string) => void` | unset | Current clipboard write succeeded; replaces native clipboard event prop |
|
|
56
|
+
| `onCopyError` | `(error: unknown) => void` | unset | Current write failed or API unavailable |
|
|
57
|
+
| `lineNumbers` | `boolean` | `false` | Decorative line gutter |
|
|
58
|
+
| `startLine` | `number` | `1` | First displayed line number |
|
|
59
|
+
| `highlightLines` | `readonly number[]` | unset | Emphasized display line numbers, accounting for `startLine` |
|
|
60
|
+
| `minLines` | `number` | unset | Minimum displayed lines without altering source |
|
|
61
|
+
| `collapsible` | `boolean` | `false` | Show expand/collapse action |
|
|
62
|
+
| `collapsedLines` | `number` | unset | Collapsed viewport line count; falls back to `minLines` |
|
|
63
|
+
| `defaultCollapsed` | `boolean` | `false` | Initial local collapsed state |
|
|
64
|
+
| `collapsed` | `boolean` | unset | Controlled collapsed state |
|
|
65
|
+
| `onCollapsedChange` | `(collapsed: boolean) => void` | unset | Collapse state request |
|
|
66
|
+
| `maxHeight` | `string \| number` | unset | Scrollable viewport limit; number interpreted as CSS pixels |
|
|
67
|
+
| `tokens` | `readonly CodeToken[]` | automatic | Ordered, non-overlapping UTF-16 ranges for external syntax highlighting |
|
|
68
|
+
| `classNames` | `Partial<Record<CodePart, string>>` | unset | Shared `Code` slots including `copy`, `feedback`, `viewport`, `line`, `lineNumber`, `lineText` |
|
|
69
|
+
| `className`, `ref`, other props | Native root props | unset | Root `div`; ref typed as HTMLDivElement |
|
|
70
|
+
|
|
71
|
+
No syntax dependency is added. Supported languages use `Code`'s small tokenizer; external highlighting can supply tokens. When loading standalone CSS parts, import both `code.css` and `codeblock.css` in that order. The bundled stylesheet includes both.
|
|
72
|
+
|
|
73
|
+
Automated checks exercise exact copies, controlled collapse, keyboard activation, scrolling and accessibility scans. Verify real clipboard permission behavior and human screen-reader announcements in the consuming application. See [shared copy guidance](https://github.com/KhallilB/kbui/blob/main/docs/guides/copyable-content.md).
|
|
74
|
+
|
|
75
|
+
## Related components
|
|
76
|
+
|
|
77
|
+
Use [`Code`](Code.md) for inline literals or automatic block detection and [`CopyableText`](CopyableText.md) for identifiers and references outside source listings.
|