@mitcsutt/kiln-ui 0.6.0 → 0.8.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/dist/components/actions/CopyButton/CopyButton.d.ts +58 -0
- package/dist/components/actions/CopyButton/CopyButton.js +63 -0
- package/dist/components/actions/CopyButton/CopyButton.js.map +1 -0
- package/dist/components/actions/CopyButton/CopyButton.module.js +9 -0
- package/dist/components/actions/CopyButton/CopyButton.module.js.map +1 -0
- package/dist/components/actions/CopyButton/index.d.ts +4 -0
- package/dist/components/actions/CopyButton/useClipboard.d.ts +35 -0
- package/dist/components/actions/CopyButton/useClipboard.js +62 -0
- package/dist/components/actions/CopyButton/useClipboard.js.map +1 -0
- package/dist/components/actions/ToggleChip/ToggleChip.d.ts +6 -0
- package/dist/components/actions/ToggleChip/ToggleChip.js +26 -24
- package/dist/components/actions/ToggleChip/ToggleChip.js.map +1 -1
- package/dist/components/display/Badge/Badge.d.ts +6 -0
- package/dist/components/display/Badge/Badge.js +16 -15
- package/dist/components/display/Badge/Badge.js.map +1 -1
- package/dist/components/display/CodeBlock/CodeBlock.js +45 -58
- package/dist/components/display/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/display/Swatch/Swatch.d.ts +52 -0
- package/dist/components/display/Swatch/Swatch.js +27 -0
- package/dist/components/display/Swatch/Swatch.js.map +1 -0
- package/dist/components/display/Swatch/Swatch.module.js +6 -0
- package/dist/components/display/Swatch/Swatch.module.js.map +1 -0
- package/dist/components/display/Swatch/index.d.ts +2 -0
- package/dist/components/display/Tag/Tag.d.ts +7 -0
- package/dist/components/display/Tag/Tag.js +31 -26
- package/dist/components/display/Tag/Tag.js.map +1 -1
- package/dist/components/display/TreeTable/TreeTable.d.ts +69 -0
- package/dist/components/display/TreeTable/TreeTable.js +152 -0
- package/dist/components/display/TreeTable/TreeTable.js.map +1 -0
- package/dist/components/display/TreeTable/TreeTable.module.js +12 -0
- package/dist/components/display/TreeTable/TreeTable.module.js.map +1 -0
- package/dist/components/display/TreeTable/index.d.ts +2 -0
- package/dist/components/feedback/Indicator/Indicator.d.ts +74 -0
- package/dist/components/feedback/Indicator/Indicator.js +50 -0
- package/dist/components/feedback/Indicator/Indicator.js.map +1 -0
- package/dist/components/feedback/Indicator/Indicator.module.js +12 -0
- package/dist/components/feedback/Indicator/Indicator.module.js.map +1 -0
- package/dist/components/feedback/Indicator/index.d.ts +2 -0
- package/dist/components/feedback/Toaster/Toaster.d.ts +71 -0
- package/dist/components/feedback/Toaster/Toaster.js +121 -0
- package/dist/components/feedback/Toaster/Toaster.js.map +1 -0
- package/dist/components/feedback/Toaster/Toaster.module.js +20 -0
- package/dist/components/feedback/Toaster/Toaster.module.js.map +1 -0
- package/dist/components/feedback/Toaster/index.d.ts +4 -0
- package/dist/components/feedback/Toaster/toast.d.ts +96 -0
- package/dist/components/feedback/Toaster/toast.js +131 -0
- package/dist/components/feedback/Toaster/toast.js.map +1 -0
- package/dist/components/inputs/Calendar/Calendar.d.ts +87 -0
- package/dist/components/inputs/Calendar/Calendar.js +217 -0
- package/dist/components/inputs/Calendar/Calendar.js.map +1 -0
- package/dist/components/inputs/Calendar/Calendar.module.js +18 -0
- package/dist/components/inputs/Calendar/Calendar.module.js.map +1 -0
- package/dist/components/inputs/Calendar/index.d.ts +2 -0
- package/dist/components/inputs/Combobox/Combobox.js +36 -44
- package/dist/components/inputs/Combobox/Combobox.js.map +1 -1
- package/dist/components/inputs/DateField/DateField.d.ts +17 -0
- package/dist/components/inputs/DateField/DateField.js +26 -0
- package/dist/components/inputs/DateField/DateField.js.map +1 -0
- package/dist/components/inputs/DateField/index.d.ts +2 -0
- package/dist/components/inputs/DateInput/DateInput.d.ts +75 -0
- package/dist/components/inputs/DateInput/DateInput.js +139 -0
- package/dist/components/inputs/DateInput/DateInput.js.map +1 -0
- package/dist/components/inputs/DateInput/index.d.ts +3 -0
- package/dist/components/inputs/DateRangeField/DateRangeField.d.ts +18 -3
- package/dist/components/inputs/DateRangeField/DateRangeField.js.map +1 -1
- package/dist/components/inputs/DateRangeField/DateRangeField.module.js +8 -3
- package/dist/components/inputs/DateRangeField/DateRangeField.module.js.map +1 -1
- package/dist/components/inputs/DateRangeField/DateRangePickerField.d.ts +48 -0
- package/dist/components/inputs/DateRangeField/DateRangePickerField.js +246 -0
- package/dist/components/inputs/DateRangeField/DateRangePickerField.js.map +1 -0
- package/dist/components/inputs/DateRangeField/index.d.ts +2 -0
- package/dist/components/inputs/DateTimeField/DateTimeField.d.ts +17 -0
- package/dist/components/inputs/DateTimeField/DateTimeField.js +26 -0
- package/dist/components/inputs/DateTimeField/DateTimeField.js.map +1 -0
- package/dist/components/inputs/DateTimeField/index.d.ts +2 -0
- package/dist/components/inputs/DateTimeInput/DateTimeInput.d.ts +83 -0
- package/dist/components/inputs/DateTimeInput/DateTimeInput.js +216 -0
- package/dist/components/inputs/DateTimeInput/DateTimeInput.js.map +1 -0
- package/dist/components/inputs/DateTimeInput/index.d.ts +2 -0
- package/dist/components/inputs/JsonField/JsonField.d.ts +23 -0
- package/dist/components/inputs/JsonField/JsonField.js +33 -0
- package/dist/components/inputs/JsonField/JsonField.js.map +1 -0
- package/dist/components/inputs/JsonField/index.d.ts +2 -0
- package/dist/components/inputs/JsonInput/JsonInput.d.ts +119 -0
- package/dist/components/inputs/JsonInput/JsonInput.js +282 -0
- package/dist/components/inputs/JsonInput/JsonInput.js.map +1 -0
- package/dist/components/inputs/JsonInput/JsonInput.module.js +16 -0
- package/dist/components/inputs/JsonInput/JsonInput.module.js.map +1 -0
- package/dist/components/inputs/JsonInput/index.d.ts +4 -0
- package/dist/components/inputs/JsonInput/json.d.ts +59 -0
- package/dist/components/inputs/JsonInput/json.js +231 -0
- package/dist/components/inputs/JsonInput/json.js.map +1 -0
- package/dist/components/inputs/TagsInput/TagsInput.js +5 -5
- package/dist/components/inputs/TimeField/TimeField.d.ts +17 -0
- package/dist/components/inputs/TimeField/TimeField.js +26 -0
- package/dist/components/inputs/TimeField/TimeField.js.map +1 -0
- package/dist/components/inputs/TimeField/index.d.ts +2 -0
- package/dist/components/inputs/TimeInput/TimeInput.d.ts +54 -0
- package/dist/components/inputs/TimeInput/TimeInput.js +107 -0
- package/dist/components/inputs/TimeInput/TimeInput.js.map +1 -0
- package/dist/components/inputs/TimeInput/index.d.ts +2 -0
- package/dist/components/inputs/internal/DateSegments.d.ts +80 -0
- package/dist/components/inputs/internal/DateSegments.js +345 -0
- package/dist/components/inputs/internal/DateSegments.js.map +1 -0
- package/dist/components/inputs/internal/dates.d.ts +101 -0
- package/dist/components/inputs/internal/dates.js +262 -0
- package/dist/components/inputs/internal/dates.js.map +1 -0
- package/dist/components/inputs/internal/filterOptions.d.ts +22 -1
- package/dist/components/inputs/internal/filterOptions.js +32 -1
- package/dist/components/inputs/internal/filterOptions.js.map +1 -1
- package/dist/components/inputs/internal/picker.d.ts +31 -0
- package/dist/components/inputs/internal/picker.js +29 -0
- package/dist/components/inputs/internal/picker.js.map +1 -0
- package/dist/components/inputs/internal/picker.module.js +15 -0
- package/dist/components/inputs/internal/picker.module.js.map +1 -0
- package/dist/components/inputs/internal/segments.module.js +10 -0
- package/dist/components/inputs/internal/segments.module.js.map +1 -0
- package/dist/components/layout/Collapse/Collapse.d.ts +39 -0
- package/dist/components/layout/Collapse/Collapse.js +24 -0
- package/dist/components/layout/Collapse/Collapse.js.map +1 -0
- package/dist/components/layout/Collapse/Collapse.module.js +6 -0
- package/dist/components/layout/Collapse/Collapse.module.js.map +1 -0
- package/dist/components/layout/Collapse/index.d.ts +2 -0
- package/dist/components/layout/Collapse/useHeightMotion.d.ts +16 -0
- package/dist/components/layout/Collapse/useHeightMotion.js +60 -0
- package/dist/components/layout/Collapse/useHeightMotion.js.map +1 -0
- package/dist/components/layout/ShowMore/ShowMore.d.ts +59 -0
- package/dist/components/layout/ShowMore/ShowMore.js +114 -0
- package/dist/components/layout/ShowMore/ShowMore.js.map +1 -0
- package/dist/components/layout/ShowMore/ShowMore.module.js +12 -0
- package/dist/components/layout/ShowMore/ShowMore.module.js.map +1 -0
- package/dist/components/layout/ShowMore/index.d.ts +2 -0
- package/dist/components/layout/Transition/Transition.d.ts +63 -0
- package/dist/components/layout/Transition/Transition.js +63 -0
- package/dist/components/layout/Transition/Transition.js.map +1 -0
- package/dist/components/layout/Transition/Transition.module.js +17 -0
- package/dist/components/layout/Transition/Transition.module.js.map +1 -0
- package/dist/components/layout/Transition/index.d.ts +2 -0
- package/dist/components/navigation/Collapsible/Collapsible.d.ts +49 -0
- package/dist/components/navigation/Collapsible/Collapsible.js +83 -0
- package/dist/components/navigation/Collapsible/Collapsible.js.map +1 -0
- package/dist/components/navigation/Collapsible/Collapsible.module.js +11 -0
- package/dist/components/navigation/Collapsible/Collapsible.module.js.map +1 -0
- package/dist/components/navigation/Collapsible/index.d.ts +2 -0
- package/dist/components/navigation/NavLinks/NavLinks.d.ts +32 -4
- package/dist/components/navigation/NavLinks/NavLinks.js +69 -39
- package/dist/components/navigation/NavLinks/NavLinks.js.map +1 -1
- package/dist/components/navigation/NavLinks/NavLinks.module.js +13 -3
- package/dist/components/navigation/NavLinks/NavLinks.module.js.map +1 -1
- package/dist/components/navigation/NavLinks/NavLinksGroup.d.ts +49 -0
- package/dist/components/navigation/NavLinks/NavLinksGroup.js +185 -0
- package/dist/components/navigation/NavLinks/NavLinksGroup.js.map +1 -0
- package/dist/components/navigation/NavLinks/context.d.ts +28 -0
- package/dist/components/navigation/NavLinks/context.js +13 -0
- package/dist/components/navigation/NavLinks/context.js.map +1 -0
- package/dist/components/navigation/NavLinks/index.d.ts +2 -0
- package/dist/components/navigation/NavLinks/treeKeys.d.ts +8 -0
- package/dist/components/navigation/NavLinks/treeKeys.js +57 -0
- package/dist/components/navigation/NavLinks/treeKeys.js.map +1 -0
- package/dist/components/overlays/CommandPalette/CommandPalette.d.ts +120 -0
- package/dist/components/overlays/CommandPalette/CommandPalette.js +386 -0
- package/dist/components/overlays/CommandPalette/CommandPalette.js.map +1 -0
- package/dist/components/overlays/CommandPalette/CommandPalette.module.js +31 -0
- package/dist/components/overlays/CommandPalette/CommandPalette.module.js.map +1 -0
- package/dist/components/overlays/CommandPalette/index.d.ts +2 -0
- package/dist/components/overlays/CommandPalette/shortcut.d.ts +28 -0
- package/dist/components/overlays/CommandPalette/shortcut.js +104 -0
- package/dist/components/overlays/CommandPalette/shortcut.js.map +1 -0
- package/dist/index.d.ts +42 -4
- package/dist/index.js +124 -100
- package/dist/styles.css +1 -1
- package/dist/themes/fiesta.css +1 -1
- package/dist/themes/flightdeck.css +1 -1
- package/dist/themes/ledger.css +1 -1
- package/dist/themes/monograph.css +1 -1
- package/dist/themes/riso.css +1 -1
- package/package.json +2 -1
- package/skills/custom-theme/SKILL.md +32 -0
- package/skills/custom-theme/references/colour.md +20 -0
- package/skills/custom-theme/references/motion.md +9 -0
- package/skills/custom-theme/references/tokens.md +35 -0
- package/skills/design-rules/SKILL.md +5 -2
- package/skills/setup-and-theming/SKILL.md +1 -1
- package/skills/setup-and-theming/references/paper.md +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ButtonProps } from '../Button/index.js';
|
|
3
|
+
/** What a `CopyButton` render function receives. */
|
|
4
|
+
export interface CopyButtonRenderProps {
|
|
5
|
+
/** Copy `value` now. */
|
|
6
|
+
copy: () => void;
|
|
7
|
+
/** `true` for `timeout` ms after a successful copy. */
|
|
8
|
+
copied: boolean;
|
|
9
|
+
/** Why the last copy failed, for `timeout` ms after it. */
|
|
10
|
+
error: Error | null;
|
|
11
|
+
}
|
|
12
|
+
export interface CopyButtonProps extends Omit<ButtonProps, 'value' | 'children' | 'onCopy' | 'onError' | 'leadingIcon' | 'trailingIcon' | 'asChild'> {
|
|
13
|
+
/** The text to copy, or a function that returns it when the button is pressed. */
|
|
14
|
+
value: string | (() => string);
|
|
15
|
+
/** The button's name, and its tooltip. Say what it copies: "Copy link". Default "Copy". */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Shown for a moment after a copy. Default "Copied". */
|
|
18
|
+
copiedLabel?: string;
|
|
19
|
+
/** Shown for a moment when a copy fails. Default "Couldn’t copy". */
|
|
20
|
+
failedLabel?: string;
|
|
21
|
+
/** Show `label` as text beside the glyph, instead of an icon-only button with a tooltip. */
|
|
22
|
+
showLabel?: boolean;
|
|
23
|
+
/** What screen readers hear after a copy. Default "Copied to clipboard". */
|
|
24
|
+
announcement?: string;
|
|
25
|
+
/** How long the copied state lasts, in ms. Default `1500`. */
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/** Called with the copied text: raise a toast, log an event. */
|
|
28
|
+
onCopy?: (text: string) => void;
|
|
29
|
+
/** Called when the copy fails. */
|
|
30
|
+
onError?: (error: Error) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Your own trigger instead of the button: a function that gets `copy`, `copied` and `error`.
|
|
33
|
+
* The announcement for screen readers is still rendered for you.
|
|
34
|
+
*/
|
|
35
|
+
children?: (state: CopyButtonRenderProps) => ReactNode;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A button that copies text, says so, and swaps its glyph to a check for a moment.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* `CopyButton` copies a link, an ID, a command or a token. By default it's an icon-only
|
|
42
|
+
* {@link IconButton | IconButton} with a tooltip that reads "Copy", then "Copied". `showLabel`
|
|
43
|
+
* makes it a {@link Button | Button} with the words beside the glyph. `value` can be a function,
|
|
44
|
+
* to compute the text at the moment of the press (say, serialising the current state).
|
|
45
|
+
*
|
|
46
|
+
* Screen readers hear "Copied to clipboard" through a polite live region, and the button keeps its
|
|
47
|
+
* name. If the copy fails, the button and the announcement say so, and `onError` gets the reason.
|
|
48
|
+
* On a page without the Clipboard API, such as one served over plain HTTP, it falls back to the
|
|
49
|
+
* older way of copying, so it works wherever copying can.
|
|
50
|
+
*
|
|
51
|
+
* For a trigger of your own, pass a function as `children`, or use {@link useClipboard |
|
|
52
|
+
* useClipboard} directly.
|
|
53
|
+
*
|
|
54
|
+
* @privateRemarks
|
|
55
|
+
* Built on useClipboard, which CodeBlock's copy button uses too, so there's one copy path. The
|
|
56
|
+
* tooltip is held open while `copied` is set, because Radix closes it on the press itself.
|
|
57
|
+
*/
|
|
58
|
+
export declare const CopyButton: import("react").ForwardRefExoticComponent<CopyButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { cx as e } from "../../../utils/cx.js";
|
|
2
|
+
import { CheckIcon as t, CopyIcon as n } from "../../../icons/icons.js";
|
|
3
|
+
import { Button as r } from "../Button/Button.js";
|
|
4
|
+
import { IconButton as i } from "../IconButton/IconButton.js";
|
|
5
|
+
import { Tooltip as a } from "../../overlays/Tooltip/Tooltip.js";
|
|
6
|
+
import { useClipboard as o } from "./useClipboard.js";
|
|
7
|
+
import s from "./CopyButton.module.js";
|
|
8
|
+
import { forwardRef as c, useState as l } from "react";
|
|
9
|
+
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
10
|
+
//#region src/components/actions/CopyButton/CopyButton.tsx
|
|
11
|
+
var p = c(function({ value: c, label: p = "Copy", copiedLabel: m = "Copied", failedLabel: h = "Couldn’t copy", showLabel: g = !1, announcement: _ = "Copied to clipboard", timeout: v = 1500, onCopy: y, onError: b, children: x, onClick: S, className: C, variant: w = "ghost", tone: T = "neutral", size: E, ...D }, O) {
|
|
12
|
+
let { copy: k, copied: A, error: j } = o({
|
|
13
|
+
timeout: v,
|
|
14
|
+
onCopy: y,
|
|
15
|
+
onError: b
|
|
16
|
+
}), [M, N] = l(!1), P = A ? "copied" : j ? "failed" : "idle", F = A ? m : j ? h : p, I = () => {
|
|
17
|
+
k(c);
|
|
18
|
+
}, L = /* @__PURE__ */ d("span", {
|
|
19
|
+
className: s.status,
|
|
20
|
+
role: "status",
|
|
21
|
+
children: A ? _ : j ? h : ""
|
|
22
|
+
});
|
|
23
|
+
if (x) return /* @__PURE__ */ f(u, { children: [x({
|
|
24
|
+
copy: I,
|
|
25
|
+
copied: A,
|
|
26
|
+
error: j
|
|
27
|
+
}), L] });
|
|
28
|
+
let R = (e) => {
|
|
29
|
+
S?.(e), e.defaultPrevented || I();
|
|
30
|
+
}, z = d(A ? t : n, {});
|
|
31
|
+
return /* @__PURE__ */ f(u, { children: [g ? /* @__PURE__ */ d(r, {
|
|
32
|
+
ref: O,
|
|
33
|
+
variant: w,
|
|
34
|
+
tone: T,
|
|
35
|
+
size: E,
|
|
36
|
+
className: e(s.copyButton, C),
|
|
37
|
+
leadingIcon: z,
|
|
38
|
+
"data-state": P,
|
|
39
|
+
onClick: R,
|
|
40
|
+
...D,
|
|
41
|
+
children: F
|
|
42
|
+
}) : /* @__PURE__ */ d(a, {
|
|
43
|
+
content: F,
|
|
44
|
+
open: M || P !== "idle",
|
|
45
|
+
onOpenChange: N,
|
|
46
|
+
children: /* @__PURE__ */ d(i, {
|
|
47
|
+
ref: O,
|
|
48
|
+
variant: w,
|
|
49
|
+
tone: T,
|
|
50
|
+
size: E,
|
|
51
|
+
className: e(s.copyButton, C),
|
|
52
|
+
label: p,
|
|
53
|
+
icon: z,
|
|
54
|
+
"data-state": P,
|
|
55
|
+
onClick: R,
|
|
56
|
+
...D
|
|
57
|
+
})
|
|
58
|
+
}), L] });
|
|
59
|
+
});
|
|
60
|
+
//#endregion
|
|
61
|
+
export { p as CopyButton };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=CopyButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyButton.js","names":["styles","_Fragment","CopyButton_module_default","Fragment$1","CopyButton","forwardRef","rest","useClipboard","hintOpen","setHintOpen","useState","state","copied","error","shown","copiedLabel","failedLabel","label","run","value","status","announcement","children","press","onClick","event","glyph","jsx","CheckIcon","CopyIcon","showLabel","Button","cx","className","Tooltip","IconButton"],"sources":["../../../../src/components/actions/CopyButton/CopyButton.tsx"],"sourcesContent":["import { forwardRef, useState, type ReactNode } from 'react'\nimport { CheckIcon, CopyIcon } from '#icons'\nimport { cx } from '#utils/cx'\nimport { Button, type ButtonProps } from '#components/actions/Button'\nimport { IconButton } from '#components/actions/IconButton'\nimport { Tooltip } from '#components/overlays/Tooltip'\nimport { useClipboard } from './useClipboard'\nimport styles from './CopyButton.module.css'\n\n/** What a `CopyButton` render function receives. */\nexport interface CopyButtonRenderProps {\n /** Copy `value` now. */\n copy: () => void\n /** `true` for `timeout` ms after a successful copy. */\n copied: boolean\n /** Why the last copy failed, for `timeout` ms after it. */\n error: Error | null\n}\n\nexport interface CopyButtonProps extends Omit<\n ButtonProps,\n 'value' | 'children' | 'onCopy' | 'onError' | 'leadingIcon' | 'trailingIcon' | 'asChild'\n> {\n /** The text to copy, or a function that returns it when the button is pressed. */\n value: string | (() => string)\n /** The button's name, and its tooltip. Say what it copies: \"Copy link\". Default \"Copy\". */\n label?: string\n /** Shown for a moment after a copy. Default \"Copied\". */\n copiedLabel?: string\n /** Shown for a moment when a copy fails. Default \"Couldn’t copy\". */\n failedLabel?: string\n /** Show `label` as text beside the glyph, instead of an icon-only button with a tooltip. */\n showLabel?: boolean\n /** What screen readers hear after a copy. Default \"Copied to clipboard\". */\n announcement?: string\n /** How long the copied state lasts, in ms. Default `1500`. */\n timeout?: number\n /** Called with the copied text: raise a toast, log an event. */\n onCopy?: (text: string) => void\n /** Called when the copy fails. */\n onError?: (error: Error) => void\n /**\n * Your own trigger instead of the button: a function that gets `copy`, `copied` and `error`.\n * The announcement for screen readers is still rendered for you.\n */\n children?: (state: CopyButtonRenderProps) => ReactNode\n}\n\n/**\n * A button that copies text, says so, and swaps its glyph to a check for a moment.\n *\n * @remarks\n * `CopyButton` copies a link, an ID, a command or a token. By default it's an icon-only\n * {@link IconButton | IconButton} with a tooltip that reads \"Copy\", then \"Copied\". `showLabel`\n * makes it a {@link Button | Button} with the words beside the glyph. `value` can be a function,\n * to compute the text at the moment of the press (say, serialising the current state).\n *\n * Screen readers hear \"Copied to clipboard\" through a polite live region, and the button keeps its\n * name. If the copy fails, the button and the announcement say so, and `onError` gets the reason.\n * On a page without the Clipboard API, such as one served over plain HTTP, it falls back to the\n * older way of copying, so it works wherever copying can.\n *\n * For a trigger of your own, pass a function as `children`, or use {@link useClipboard |\n * useClipboard} directly.\n *\n * @privateRemarks\n * Built on useClipboard, which CodeBlock's copy button uses too, so there's one copy path. The\n * tooltip is held open while `copied` is set, because Radix closes it on the press itself.\n */\nexport const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>(function CopyButton(\n {\n value,\n label = 'Copy',\n copiedLabel = 'Copied',\n failedLabel = 'Couldn’t copy',\n showLabel = false,\n announcement = 'Copied to clipboard',\n timeout = 1500,\n onCopy,\n onError,\n children,\n onClick,\n className,\n variant = 'ghost',\n tone = 'neutral',\n size,\n ...rest\n },\n ref,\n) {\n const { copy, copied, error } = useClipboard({ timeout, onCopy, onError })\n const [hintOpen, setHintOpen] = useState(false)\n const state = copied ? 'copied' : error ? 'failed' : 'idle'\n const shown = copied ? copiedLabel : error ? failedLabel : label\n const run = () => {\n void copy(value)\n }\n const status = (\n <span className={styles.status} role=\"status\">\n {copied ? announcement : error ? failedLabel : ''}\n </span>\n )\n\n if (children) {\n return (\n <>\n {children({ copy: run, copied, error })}\n {status}\n </>\n )\n }\n\n const press: ButtonProps['onClick'] = (event) => {\n onClick?.(event)\n if (!event.defaultPrevented) run()\n }\n const glyph = copied ? <CheckIcon /> : <CopyIcon />\n\n return (\n <>\n {showLabel ? (\n <Button\n ref={ref}\n variant={variant}\n tone={tone}\n size={size}\n className={cx(styles.copyButton, className)}\n leadingIcon={glyph}\n data-state={state}\n onClick={press}\n {...rest}\n >\n {shown}\n </Button>\n ) : (\n <Tooltip content={shown} open={hintOpen || state !== 'idle'} onOpenChange={setHintOpen}>\n <IconButton\n ref={ref}\n variant={variant}\n tone={tone}\n size={size}\n className={cx(styles.copyButton, className)}\n label={label}\n icon={glyph}\n data-state={state}\n onClick={press}\n {...rest}\n />\n </Tooltip>\n )}\n {status}\n </>\n )\n})\n"],"mappings":";;;;;;;;;;AAqEA,IAAaI,IAAaC,EAA+C,SACvE,EACE,UACA,WAAQ,QACR,iBAAc,UACd,iBAAc,iBACd,eAAY,IACZ,kBAAe,uBACf,aAAU,MACV,WACA,YACA,aACA,YACA,cACA,aAAU,SACV,UAAO,WACP,SACA,GAAGC,KAEL,GACA;CACA,IAAM,EAAE,SAAM,WAAQ,aAAUC,EAAa;EAAE;EAAS;EAAQ;CAAQ,CAAC,GACnE,CAACC,GAAUC,KAAeC,EAAS,EAAK,GACxCC,IAAQC,IAAS,WAAWC,IAAQ,WAAW,QAC/CC,IAAQF,IAASG,IAAcF,IAAQG,IAAcC,GACrDC,UAAY;EAChB,EAAUC,CAAK;CACjB,GACMC,IACJ,kBAAC,QAAD;EAAM,WAAWpB,EAAO;EAAQ,MAAK;EAClC,UAAAY,IAASS,IAAeR,IAAQG,IAAc;CAC3C,CAAA;CAGR,IAAIM,GACF,OACE,kBAAArB,GAAA,EAAA,UAAA,CACGqB,EAAS;EAAE,MAAMJ;EAAK;EAAQ;CAAM,CAAC,GACrCE,CACD,EAAA,CAAA;CAIN,IAAMG,KAAiC,MAAU;EAE/C,AADAC,IAAUC,CAAK,GACVA,EAAM,oBAAkBP,EAAI;CACnC,GACMQ,IAAiBC,EAATf,IAAUgB,IAAgBC,GAAjB,CAAY,CAAe;CAElD,OACE,kBAAA5B,GAAA,EAAA,UAAA,CACG6B,IACC,kBAACC,GAAD;EACO;EACI;EACH;EACA;EACN,WAAWC,EAAGhC,EAAO,YAAYiC,CAAS;EAC1C,aAAaP;EACb,cAAYf;EACZ,SAASY;EACT,GAAIjB;EAEH,UAAAQ;CACK,CAAA,IAER,kBAACoB,GAAD;EAAS,SAASpB;EAAO,MAAMN,KAAYG,MAAU;EAAQ,cAAcF;EACzE,UAAA,kBAAC0B,GAAD;GACO;GACI;GACH;GACA;GACN,WAAWH,EAAGhC,EAAO,YAAYiC,CAAS;GACnC;GACP,MAAMP;GACN,cAAYf;GACZ,SAASY;GACT,GAAIjB;EACL,CAAA;CACM,CAAA,GAEVc,CACD,EAAA,CAAA;AAEN,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/components/actions/CopyButton/CopyButton.module.css
|
|
2
|
+
var e = "kiln-CopyButton__copyButton", t = "kiln-CopyButton__status", n = {
|
|
3
|
+
copyButton: e,
|
|
4
|
+
status: t
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as copyButton, n as default, t as status };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=CopyButton.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyButton.module.js","names":["copyButton","status","CopyButton_module_default"],"sources":["../../../../src/components/actions/CopyButton/CopyButton.module.css"],"sourcesContent":["/*\n * No component tokens: the button is a Button or IconButton, themed through theirs.\n * After a copy the glyph and label of a ghost or outline button take the positive text colour,\n * and a failure the critical. A solid button keeps its ink, which those wouldn't clear.\n */\n.copyButton[data-state='copied']:not([data-variant='solid']) {\n color: var(--tone-positive-text);\n}\n.copyButton[data-state='failed']:not([data-variant='solid']) {\n color: var(--tone-critical-text);\n}\n\n.status {\n position: absolute;\n inline-size: 1px;\n block-size: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n border: 0;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface UseClipboardOptions {
|
|
2
|
+
/** How long `copied` (or `error`) stays set after a copy, in ms. Default `1500`. */
|
|
3
|
+
timeout?: number;
|
|
4
|
+
/** Called with the text once it's on the clipboard: raise a toast, log an event. */
|
|
5
|
+
onCopy?: (text: string) => void;
|
|
6
|
+
/** Called when the copy fails, with the reason. */
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface UseClipboardResult {
|
|
10
|
+
/**
|
|
11
|
+
* Copies `value`, or what `value()` returns at the moment of the call. Resolves to `true` once
|
|
12
|
+
* the text is on the clipboard, or `false` if it couldn't be copied.
|
|
13
|
+
*/
|
|
14
|
+
copy: (value: string | (() => string)) => Promise<boolean>;
|
|
15
|
+
/** `true` for `timeout` ms after a successful copy. */
|
|
16
|
+
copied: boolean;
|
|
17
|
+
/** Why the last copy failed, for `timeout` ms after it. `null` otherwise. */
|
|
18
|
+
error: Error | null;
|
|
19
|
+
/** Clear `copied` and `error` now. */
|
|
20
|
+
reset: () => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Copy text to the clipboard from any trigger, with a `copied` state that clears itself and an
|
|
24
|
+
* `error` when the copy fails.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* `useClipboard` is what {@link CopyButton | CopyButton} is made of: use it when the trigger is
|
|
28
|
+
* your own, like a menu item or a whole row. It uses the Clipboard API, and falls back to the
|
|
29
|
+
* older `execCommand('copy')` where that's missing (a page served over plain HTTP) or refused, so
|
|
30
|
+
* a copy works wherever it can and says so when it can't.
|
|
31
|
+
*
|
|
32
|
+
* Copying is silent to screen readers. If your trigger doesn't say what happened, announce it,
|
|
33
|
+
* the way `CopyButton` does with a polite live region.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useClipboard({ timeout, onCopy, onError, }?: UseClipboardOptions): UseClipboardResult;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useLatest as e } from "../../inputs/internal/useLatest.js";
|
|
2
|
+
import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
|
|
3
|
+
//#region src/components/actions/CopyButton/useClipboard.ts
|
|
4
|
+
function a(e) {
|
|
5
|
+
if (typeof document > "u" || typeof document.execCommand != "function") return !1;
|
|
6
|
+
let t = document.activeElement, n = document.getSelection(), r = n && n.rangeCount > 0 ? n.getRangeAt(0) : null, i = document.createElement("textarea");
|
|
7
|
+
i.value = e, i.setAttribute("readonly", ""), i.setAttribute("aria-hidden", "true"), i.style.position = "fixed", i.style.insetBlockStart = "0", i.style.opacity = "0", i.style.pointerEvents = "none", document.body.append(i), i.select();
|
|
8
|
+
let a;
|
|
9
|
+
try {
|
|
10
|
+
a = document.execCommand("copy");
|
|
11
|
+
} catch {
|
|
12
|
+
a = !1;
|
|
13
|
+
}
|
|
14
|
+
return i.remove(), r && n && (n.removeAllRanges(), n.addRange(r)), t instanceof HTMLElement && t.focus({ preventScroll: !0 }), a;
|
|
15
|
+
}
|
|
16
|
+
async function o(e) {
|
|
17
|
+
let t = typeof navigator > "u" ? void 0 : navigator.clipboard;
|
|
18
|
+
if (t?.writeText) try {
|
|
19
|
+
await t.writeText(e);
|
|
20
|
+
return;
|
|
21
|
+
} catch (t) {
|
|
22
|
+
if (a(e)) return;
|
|
23
|
+
throw t instanceof Error ? t : /* @__PURE__ */ Error("The clipboard refused the text.");
|
|
24
|
+
}
|
|
25
|
+
if (!a(e)) throw Error("This browser can’t copy to the clipboard.");
|
|
26
|
+
}
|
|
27
|
+
function s({ timeout: a = 1500, onCopy: s, onError: c } = {}) {
|
|
28
|
+
let [l, u] = i(!1), [d, f] = i(null), p = r(void 0), m = e({
|
|
29
|
+
onCopy: s,
|
|
30
|
+
onError: c,
|
|
31
|
+
timeout: a
|
|
32
|
+
});
|
|
33
|
+
n(() => () => {
|
|
34
|
+
clearTimeout(p.current);
|
|
35
|
+
}, []);
|
|
36
|
+
let h = t(() => {
|
|
37
|
+
clearTimeout(p.current), u(!1), f(null);
|
|
38
|
+
}, []);
|
|
39
|
+
return {
|
|
40
|
+
copy: t(async (e) => {
|
|
41
|
+
clearTimeout(p.current);
|
|
42
|
+
let { onCopy: t, onError: n, timeout: r } = m.current, i;
|
|
43
|
+
try {
|
|
44
|
+
let n = typeof e == "function" ? e() : e;
|
|
45
|
+
await o(n), u(!0), f(null), t?.(n), i = !0;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
48
|
+
u(!1), f(t), n?.(t), i = !1;
|
|
49
|
+
}
|
|
50
|
+
return p.current = setTimeout(() => {
|
|
51
|
+
u(!1), f(null);
|
|
52
|
+
}, r), i;
|
|
53
|
+
}, [m]),
|
|
54
|
+
copied: l,
|
|
55
|
+
error: d,
|
|
56
|
+
reset: h
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { s as useClipboard };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=useClipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClipboard.js","names":["copyWithTextarea","active","selection","range","area","text","ok","writeClipboard","clipboard","reason","useClipboard","copied","setCopied","useState","error","setError","timer","useRef","callbacks","useLatest","reset","useCallback","done","failed","wait","value","problem"],"sources":["../../../../src/components/actions/CopyButton/useClipboard.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\nimport { useLatest } from '#components/inputs/internal/useLatest'\n\nexport interface UseClipboardOptions {\n /** How long `copied` (or `error`) stays set after a copy, in ms. Default `1500`. */\n timeout?: number\n /** Called with the text once it's on the clipboard: raise a toast, log an event. */\n onCopy?: (text: string) => void\n /** Called when the copy fails, with the reason. */\n onError?: (error: Error) => void\n}\n\nexport interface UseClipboardResult {\n /**\n * Copies `value`, or what `value()` returns at the moment of the call. Resolves to `true` once\n * the text is on the clipboard, or `false` if it couldn't be copied.\n */\n copy: (value: string | (() => string)) => Promise<boolean>\n /** `true` for `timeout` ms after a successful copy. */\n copied: boolean\n /** Why the last copy failed, for `timeout` ms after it. `null` otherwise. */\n error: Error | null\n /** Clear `copied` and `error` now. */\n reset: () => void\n}\n\n/**\n * Copies with a hidden textarea and `execCommand('copy')`: the path for pages without the\n * Clipboard API (served over plain HTTP) or where it's refused. Keeps the reader's focus and\n * selection.\n */\nfunction copyWithTextarea(text: string): boolean {\n // execCommand is deprecated, but it's the only way to copy where the Clipboard API is missing.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- the fallback, see above\n if (typeof document === 'undefined' || typeof document.execCommand !== 'function') return false\n const active = document.activeElement\n const selection = document.getSelection()\n const range = selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : null\n const area = document.createElement('textarea')\n area.value = text\n area.setAttribute('readonly', '')\n area.setAttribute('aria-hidden', 'true')\n area.style.position = 'fixed'\n area.style.insetBlockStart = '0'\n area.style.opacity = '0'\n area.style.pointerEvents = 'none'\n document.body.append(area)\n area.select()\n let ok: boolean\n try {\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- the fallback, see above\n ok = document.execCommand('copy')\n } catch {\n ok = false\n }\n area.remove()\n if (range && selection) {\n selection.removeAllRanges()\n selection.addRange(range)\n }\n if (active instanceof HTMLElement) active.focus({ preventScroll: true })\n return ok\n}\n\n/** Writes `text` to the clipboard, through the Clipboard API where it's available. */\nasync function writeClipboard(text: string): Promise<void> {\n const clipboard = typeof navigator === 'undefined' ? undefined : navigator.clipboard\n // `navigator.clipboard` is missing in insecure contexts and older browsers.\n if (clipboard?.writeText) {\n try {\n await clipboard.writeText(text)\n return\n } catch (reason) {\n if (copyWithTextarea(text)) return\n throw reason instanceof Error ? reason : new Error('The clipboard refused the text.')\n }\n }\n if (!copyWithTextarea(text)) throw new Error('This browser can’t copy to the clipboard.')\n}\n\n/**\n * Copy text to the clipboard from any trigger, with a `copied` state that clears itself and an\n * `error` when the copy fails.\n *\n * @remarks\n * `useClipboard` is what {@link CopyButton | CopyButton} is made of: use it when the trigger is\n * your own, like a menu item or a whole row. It uses the Clipboard API, and falls back to the\n * older `execCommand('copy')` where that's missing (a page served over plain HTTP) or refused, so\n * a copy works wherever it can and says so when it can't.\n *\n * Copying is silent to screen readers. If your trigger doesn't say what happened, announce it,\n * the way `CopyButton` does with a polite live region.\n */\nexport function useClipboard({\n timeout = 1500,\n onCopy,\n onError,\n}: UseClipboardOptions = {}): UseClipboardResult {\n const [copied, setCopied] = useState(false)\n const [error, setError] = useState<Error | null>(null)\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n const callbacks = useLatest({ onCopy, onError, timeout })\n\n useEffect(\n () => () => {\n clearTimeout(timer.current)\n },\n [],\n )\n\n const reset = useCallback(() => {\n clearTimeout(timer.current)\n setCopied(false)\n setError(null)\n }, [])\n\n const copy = useCallback(\n async (value: string | (() => string)) => {\n clearTimeout(timer.current)\n const { onCopy: done, onError: failed, timeout: wait } = callbacks.current\n let ok: boolean\n try {\n const text = typeof value === 'function' ? value() : value\n await writeClipboard(text)\n setCopied(true)\n setError(null)\n done?.(text)\n ok = true\n } catch (reason) {\n const problem = reason instanceof Error ? reason : new Error(String(reason))\n setCopied(false)\n setError(problem)\n failed?.(problem)\n ok = false\n }\n timer.current = setTimeout(() => {\n setCopied(false)\n setError(null)\n }, wait)\n return ok\n },\n [callbacks],\n )\n\n return { copy, copied, error, reset }\n}\n"],"mappings":";;;AA+BA,SAASA,EAAiB,GAAuB;CAG/C,IAAI,OAAO,WAAa,OAAe,OAAO,SAAS,eAAgB,YAAY,OAAO;CAC1F,IAAMC,IAAS,SAAS,eAClBC,IAAY,SAAS,aAAa,GAClCC,IAAQD,KAAaA,EAAU,aAAa,IAAIA,EAAU,WAAW,CAAC,IAAI,MAC1EE,IAAO,SAAS,cAAc,UAAU;CAS9C,AARA,EAAK,QAAQC,GACbD,EAAK,aAAa,YAAY,EAAE,GAChCA,EAAK,aAAa,eAAe,MAAM,GACvC,EAAK,MAAM,WAAW,SACtB,EAAK,MAAM,kBAAkB,KAC7B,EAAK,MAAM,UAAU,KACrB,EAAK,MAAM,gBAAgB,QAC3B,SAAS,KAAK,OAAOA,CAAI,GACzBA,EAAK,OAAO;CACZ,IAAIE;CACJ,IAAI;EAEF,IAAK,SAAS,YAAY,MAAM;CAClC,QAAQ;EACN,IAAK;CACP;CAOA,OANAF,EAAK,OAAO,GACRD,KAASD,MACXA,EAAU,gBAAgB,GAC1BA,EAAU,SAASC,CAAK,IAEtBF,aAAkB,eAAaA,EAAO,MAAM,EAAE,eAAe,GAAK,CAAC,GAChEK;AACT;AAGA,eAAeC,EAAe,GAA6B;CACzD,IAAMC,IAAY,OAAO,YAAc,MAAc,KAAA,IAAY,UAAU;CAE3E,IAAIA,GAAW,WACb,IAAI;EACF,MAAMA,EAAU,UAAUH,CAAI;EAC9B;CACF,SAASI,GAAQ;EACf,IAAIT,EAAiBK,CAAI,GAAG;EAC5B,MAAMI,aAAkB,QAAQA,IAAS,gBAAI,MAAM,iCAAiC;CACtF;CAEF,IAAI,CAACT,EAAiBK,CAAI,GAAG,MAAU,MAAM,2CAA2C;AAC1F;AAeA,SAAgBK,EAAa,EAC3B,aAAU,MACV,WACA,eACuB,CAAC,GAAuB;CAC/C,IAAM,CAACC,GAAQC,KAAaC,EAAS,EAAK,GACpC,CAACC,GAAOC,KAAYF,EAAuB,IAAI,GAC/CG,IAAQC,EAAkD,KAAA,CAAS,GACnEC,IAAYC,EAAU;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAExD,cACc;EACV,aAAaH,EAAM,OAAO;CAC5B,GACA,CAAC,CACH;CAEA,IAAMI,IAAQC,QAAkB;EAG9B,AAFA,aAAaL,EAAM,OAAO,GAC1BJ,EAAU,EAAK,GACfG,EAAS,IAAI;CACf,GAAG,CAAC,CAAC;CA8BL,OAAO;EAAE,MA5BIM,EACX,OAAO,MAAmC;GACxC,aAAaL,EAAM,OAAO;GAC1B,IAAM,EAAE,QAAQM,GAAM,SAASC,GAAQ,SAASC,MAASN,EAAU,SAC/DZ;GACJ,IAAI;IACF,IAAMD,IAAO,OAAOoB,KAAU,aAAaA,EAAM,IAAIA;IAKrD,AAJA,MAAMlB,EAAeF,CAAI,GACzBO,EAAU,EAAI,GACdG,EAAS,IAAI,GACbO,IAAOjB,CAAI,GACX,IAAK;GACP,SAASI,GAAQ;IACf,IAAMiB,IAAUjB,aAAkB,QAAQA,IAAa,MAAM,OAAOA,CAAM,CAAC;IAI3E,AAHAG,EAAU,EAAK,GACfG,EAASW,CAAO,GAChBH,IAASG,CAAO,GAChB,IAAK;GACP;GAKA,OAJA,EAAM,UAAU,iBAAiB;IAE/B,AADAd,EAAU,EAAK,GACfG,EAAS,IAAI;GACf,GAAGS,CAAI,GACAlB;EACT,GACA,CAACY,CAAS,CAGH;EAAM;EAAQ;EAAO;CAAM;AACtC"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
|
|
2
2
|
import { Toggle } from 'radix-ui';
|
|
3
|
+
import { type SwatchColor } from '../../display/Swatch/index.js';
|
|
3
4
|
export type ToggleChipSize = 'sm' | 'md';
|
|
4
5
|
export interface ToggleChipProps extends ComponentPropsWithoutRef<typeof Toggle.Root> {
|
|
5
6
|
size?: ToggleChipSize;
|
|
7
|
+
/**
|
|
8
|
+
* A leading colour swatch, for a filter on something that has a colour: a team, a label, a
|
|
9
|
+
* chart series. A categorical slot (`1` to `8`) or a CSS colour from data.
|
|
10
|
+
*/
|
|
11
|
+
swatch?: SwatchColor;
|
|
6
12
|
/** A leading glyph. Keep it meaningful — one icon per row at most. */
|
|
7
13
|
icon?: ReactNode;
|
|
8
14
|
/** How many items the filter matches. Rendered in tabular figures after the label. */
|
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
import { cx as e } from "../../../utils/cx.js";
|
|
2
|
-
import t from "
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { Swatch as t } from "../../display/Swatch/Swatch.js";
|
|
3
|
+
import n from "./chip.module.js";
|
|
4
|
+
import { forwardRef as r } from "react";
|
|
5
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
6
|
+
import { Toggle as o } from "radix-ui";
|
|
6
7
|
//#region src/components/actions/ToggleChip/ToggleChip.tsx
|
|
7
|
-
var
|
|
8
|
-
return /* @__PURE__ */
|
|
9
|
-
ref:
|
|
10
|
-
type:
|
|
11
|
-
className: e(
|
|
12
|
-
"data-size":
|
|
13
|
-
...
|
|
8
|
+
var s = r(function({ size: r = "md", swatch: s, icon: c, count: l, trailing: u, className: d, children: f, type: p, ...m }, h) {
|
|
9
|
+
return /* @__PURE__ */ a(o.Root, {
|
|
10
|
+
ref: h,
|
|
11
|
+
type: p ?? "button",
|
|
12
|
+
className: e(n.chip, d),
|
|
13
|
+
"data-size": r,
|
|
14
|
+
...m,
|
|
14
15
|
children: [
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
s === void 0 ? null : /* @__PURE__ */ i(t, { color: s }),
|
|
17
|
+
c ? /* @__PURE__ */ i("span", {
|
|
18
|
+
className: n.icon,
|
|
17
19
|
"aria-hidden": "true",
|
|
18
|
-
children:
|
|
20
|
+
children: c
|
|
19
21
|
}) : null,
|
|
20
|
-
/* @__PURE__ */
|
|
21
|
-
className:
|
|
22
|
-
children:
|
|
22
|
+
/* @__PURE__ */ i("span", {
|
|
23
|
+
className: n.label,
|
|
24
|
+
children: f
|
|
23
25
|
}),
|
|
24
|
-
|
|
25
|
-
className:
|
|
26
|
-
children:
|
|
26
|
+
u === void 0 ? null : /* @__PURE__ */ i("span", {
|
|
27
|
+
className: n.trailing,
|
|
28
|
+
children: u
|
|
27
29
|
}),
|
|
28
|
-
|
|
29
|
-
className:
|
|
30
|
-
children:
|
|
30
|
+
l === void 0 ? null : /* @__PURE__ */ i("span", {
|
|
31
|
+
className: n.count,
|
|
32
|
+
children: l
|
|
31
33
|
})
|
|
32
34
|
]
|
|
33
35
|
});
|
|
34
36
|
});
|
|
35
37
|
//#endregion
|
|
36
|
-
export {
|
|
38
|
+
export { s as ToggleChip };
|
|
37
39
|
|
|
38
40
|
//# sourceMappingURL=ToggleChip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToggleChip.js","names":["styles","chip_module_default","ToggleChip","forwardRef","rest","Toggle","type","cx","className","size","icon","trailing","count"],"sources":["../../../../src/components/actions/ToggleChip/ToggleChip.tsx"],"sourcesContent":["import { forwardRef, type ComponentPropsWithoutRef, type ReactNode } from 'react'\nimport { Toggle } from 'radix-ui'\nimport { cx } from '#utils/cx'\nimport styles from './chip.module.css'\n\nexport type ToggleChipSize = 'sm' | 'md'\n\nexport interface ToggleChipProps extends ComponentPropsWithoutRef<typeof Toggle.Root> {\n size?: ToggleChipSize\n /** A leading glyph. Keep it meaningful — one icon per row at most. */\n icon?: ReactNode\n /** How many items the filter matches. Rendered in tabular figures after the label. */\n count?: number\n /**\n * Content after the label, spaced from it: an `AvatarGroup` of who reacted, a small figure.\n * Keep it phrasing content, since the chip is a button.\n */\n trailing?: ReactNode\n}\n\n/**\n * An independent on-off filter that sits in a row with others, with an optional count.\n *\n * @remarks\n * A `ToggleChip` is a pressed or unpressed button, announced as a toggle (`aria-pressed`). Each\n * chip in a row is independent, so a row of them is a set of filters, not a choice of one. For a\n * set of chips that act together (one of, or several of, one field), use {@link ChipGroup |\n * ChipGroup}.\n *\n * @privateRemarks\n * A pressable filter chip — an on/off switch that reads as a word (\"Mine\", \"Overdue\n * only\"). Built on Radix Toggle, so it is a real `<button aria-pressed>`; use\n * `pressed`/`onPressedChange` (controlled) or `defaultPressed`.\n *\n * Pressed chips take the accent's soft fill. Where the theme has a hard press shadow\n * (Fiesta), resting chips stand proud and pressed chips sit flat — literally pushed in.\n */\nexport const ToggleChip = forwardRef<HTMLButtonElement, ToggleChipProps>(function ToggleChip(\n { size = 'md', icon, count, trailing, className, children, type, ...rest },\n ref,\n) {\n return (\n <Toggle.Root\n ref={ref}\n type={type ?? 'button'}\n className={cx(styles.chip, className)}\n data-size={size}\n {...rest}\n >\n {icon ? (\n <span className={styles.icon} aria-hidden=\"true\">\n {icon}\n </span>\n ) : null}\n <span className={styles.label}>{children}</span>\n {trailing !== undefined ? <span className={styles.trailing}>{trailing}</span> : null}\n {count !== undefined ? <span className={styles.count}>{count}</span> : null}\n </Toggle.Root>\n )\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ToggleChip.js","names":["styles","chip_module_default","ToggleChip","forwardRef","rest","Toggle","type","cx","className","size","swatch","Swatch","icon","trailing","count"],"sources":["../../../../src/components/actions/ToggleChip/ToggleChip.tsx"],"sourcesContent":["import { forwardRef, type ComponentPropsWithoutRef, type ReactNode } from 'react'\nimport { Toggle } from 'radix-ui'\nimport { cx } from '#utils/cx'\nimport { Swatch, type SwatchColor } from '#components/display/Swatch'\nimport styles from './chip.module.css'\n\nexport type ToggleChipSize = 'sm' | 'md'\n\nexport interface ToggleChipProps extends ComponentPropsWithoutRef<typeof Toggle.Root> {\n size?: ToggleChipSize\n /**\n * A leading colour swatch, for a filter on something that has a colour: a team, a label, a\n * chart series. A categorical slot (`1` to `8`) or a CSS colour from data.\n */\n swatch?: SwatchColor\n /** A leading glyph. Keep it meaningful — one icon per row at most. */\n icon?: ReactNode\n /** How many items the filter matches. Rendered in tabular figures after the label. */\n count?: number\n /**\n * Content after the label, spaced from it: an `AvatarGroup` of who reacted, a small figure.\n * Keep it phrasing content, since the chip is a button.\n */\n trailing?: ReactNode\n}\n\n/**\n * An independent on-off filter that sits in a row with others, with an optional count.\n *\n * @remarks\n * A `ToggleChip` is a pressed or unpressed button, announced as a toggle (`aria-pressed`). Each\n * chip in a row is independent, so a row of them is a set of filters, not a choice of one. For a\n * set of chips that act together (one of, or several of, one field), use {@link ChipGroup |\n * ChipGroup}.\n *\n * @privateRemarks\n * A pressable filter chip — an on/off switch that reads as a word (\"Mine\", \"Overdue\n * only\"). Built on Radix Toggle, so it is a real `<button aria-pressed>`; use\n * `pressed`/`onPressedChange` (controlled) or `defaultPressed`.\n *\n * Pressed chips take the accent's soft fill. Where the theme has a hard press shadow\n * (Fiesta), resting chips stand proud and pressed chips sit flat — literally pushed in.\n */\nexport const ToggleChip = forwardRef<HTMLButtonElement, ToggleChipProps>(function ToggleChip(\n { size = 'md', swatch, icon, count, trailing, className, children, type, ...rest },\n ref,\n) {\n return (\n <Toggle.Root\n ref={ref}\n type={type ?? 'button'}\n className={cx(styles.chip, className)}\n data-size={size}\n {...rest}\n >\n {swatch !== undefined ? <Swatch color={swatch} /> : null}\n {icon ? (\n <span className={styles.icon} aria-hidden=\"true\">\n {icon}\n </span>\n ) : null}\n <span className={styles.label}>{children}</span>\n {trailing !== undefined ? <span className={styles.trailing}>{trailing}</span> : null}\n {count !== undefined ? <span className={styles.count}>{count}</span> : null}\n </Toggle.Root>\n )\n})\n"],"mappings":";;;;;;;AA2CA,IAAaE,IAAaC,EAA+C,SACvE,EAAE,UAAO,MAAM,WAAQ,SAAM,UAAO,aAAU,cAAW,aAAU,SAAM,GAAGC,KAC5E,GACA;CACA,OACE,kBAACC,EAAO,MAAR;EACO;EACL,MAAMC,KAAQ;EACd,WAAWC,EAAGP,EAAO,MAAMQ,CAAS;EACpC,aAAWC;EACX,GAAIL;EALN,UAAA;GAOGM,MAAW,KAAA,IAAwC,OAA5B,kBAACC,GAAD,EAAQ,OAAOD,EAAS,CAAA;GAC/CE,IACC,kBAAC,QAAD;IAAM,WAAWZ,EAAO;IAAM,eAAY;IACvC,UAAAY;GACG,CAAA,IACJ;GACJ,kBAAC,QAAD;IAAM,WAAWZ,EAAO;IAAQ;GAAe,CAAA;GAC9Ca,MAAa,KAAA,IAAkE,OAAtD,kBAAC,QAAD;IAAM,WAAWb,EAAO;IAAW,UAAAa;GAAe,CAAA;GAC3EC,MAAU,KAAA,IAA4D,OAAhD,kBAAC,QAAD;IAAM,WAAWd,EAAO;IAAQ,UAAAc;GAAY,CAAA;EACxD;;AAEjB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type HTMLAttributes } from 'react';
|
|
2
2
|
import type { Tone } from '../../../utils/tokens.js';
|
|
3
|
+
import { type SwatchColor } from '../Swatch/index.js';
|
|
3
4
|
export type BadgeVariant = 'soft' | 'solid' | 'outline';
|
|
4
5
|
export type BadgeSize = 'sm' | 'md';
|
|
5
6
|
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
@@ -10,6 +11,11 @@ export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
|
10
11
|
size?: BadgeSize;
|
|
11
12
|
/** Leading status dot in the tone colour. Decorative — the label carries the meaning. */
|
|
12
13
|
dot?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A leading colour swatch that says who or what the badge is about: a team, a label, a series.
|
|
16
|
+
* A categorical slot (`1` to `8`) or a CSS colour from data. Takes the place of `dot`.
|
|
17
|
+
*/
|
|
18
|
+
swatch?: SwatchColor;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* A short word or count that says what state something is in. Live, delayed, 3 new.
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { cx as e } from "../../../utils/cx.js";
|
|
2
|
-
import t from "
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
2
|
+
import { Swatch as t } from "../Swatch/Swatch.js";
|
|
3
|
+
import n from "./Badge.module.js";
|
|
4
|
+
import { forwardRef as r } from "react";
|
|
5
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
5
6
|
//#region src/components/display/Badge/Badge.tsx
|
|
6
|
-
var
|
|
7
|
-
return /* @__PURE__ */
|
|
8
|
-
ref:
|
|
9
|
-
className: e(
|
|
10
|
-
"data-tone":
|
|
11
|
-
"data-variant":
|
|
12
|
-
"data-size":
|
|
13
|
-
...
|
|
14
|
-
children: [
|
|
15
|
-
className:
|
|
7
|
+
var o = r(function({ tone: r = "neutral", variant: o = "soft", size: s = "sm", dot: c = !1, swatch: l, className: u, children: d, ...f }, p) {
|
|
8
|
+
return /* @__PURE__ */ a("span", {
|
|
9
|
+
ref: p,
|
|
10
|
+
className: e(n.badge, u),
|
|
11
|
+
"data-tone": r,
|
|
12
|
+
"data-variant": o,
|
|
13
|
+
"data-size": s,
|
|
14
|
+
...f,
|
|
15
|
+
children: [l === void 0 ? c ? /* @__PURE__ */ i("span", {
|
|
16
|
+
className: n.dot,
|
|
16
17
|
"aria-hidden": "true"
|
|
17
|
-
}) : null, l]
|
|
18
|
+
}) : null : /* @__PURE__ */ i(t, { color: l }), d]
|
|
18
19
|
});
|
|
19
20
|
});
|
|
20
21
|
//#endregion
|
|
21
|
-
export {
|
|
22
|
+
export { o as Badge };
|
|
22
23
|
|
|
23
24
|
//# sourceMappingURL=Badge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Badge.js","names":["styles","Badge_module_default","Badge","forwardRef","rest","cx","className","tone","variant","size","dot","children"],"sources":["../../../../src/components/display/Badge/Badge.tsx"],"sourcesContent":["import { forwardRef, type HTMLAttributes } from 'react'\nimport { cx } from '#utils/cx'\nimport type { Tone } from '#utils/tokens'\nimport styles from './Badge.module.css'\n\nexport type BadgeVariant = 'soft' | 'solid' | 'outline'\nexport type BadgeSize = 'sm' | 'md'\n\nexport interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {\n /** Status colour. `neutral` for plain counts and labels. Default `neutral`. */\n tone?: Tone\n /** `soft` (default) for most status; `solid` for the one that must be seen; `outline` for quiet. */\n variant?: BadgeVariant\n size?: BadgeSize\n /** Leading status dot in the tone colour. Decorative — the label carries the meaning. */\n dot?: boolean\n}\n\n/**\n * A short word or count that says what state something is in. Live, delayed, 3 new.\n *\n * @remarks\n * A `Badge` is status: what state a thing is in right now. For categories and metadata (a line, a\n * facility, a topic) use a {@link Tag | Tag}, which is quieter.\n *\n * @privateRemarks\n * A short status or count: \"Live\", \"Over quota\", \"3 new\", \"Overdue\".\n * Metadata and categories are Tags; a Badge says what *state* something is in.\n */\nexport const Badge = forwardRef<HTMLSpanElement, BadgeProps>(function Badge(\n {
|
|
1
|
+
{"version":3,"file":"Badge.js","names":["styles","Badge_module_default","Badge","forwardRef","rest","cx","className","tone","variant","size","swatch","dot","Swatch","children"],"sources":["../../../../src/components/display/Badge/Badge.tsx"],"sourcesContent":["import { forwardRef, type HTMLAttributes } from 'react'\nimport { cx } from '#utils/cx'\nimport type { Tone } from '#utils/tokens'\nimport { Swatch, type SwatchColor } from '#components/display/Swatch'\nimport styles from './Badge.module.css'\n\nexport type BadgeVariant = 'soft' | 'solid' | 'outline'\nexport type BadgeSize = 'sm' | 'md'\n\nexport interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {\n /** Status colour. `neutral` for plain counts and labels. Default `neutral`. */\n tone?: Tone\n /** `soft` (default) for most status; `solid` for the one that must be seen; `outline` for quiet. */\n variant?: BadgeVariant\n size?: BadgeSize\n /** Leading status dot in the tone colour. Decorative — the label carries the meaning. */\n dot?: boolean\n /**\n * A leading colour swatch that says who or what the badge is about: a team, a label, a series.\n * A categorical slot (`1` to `8`) or a CSS colour from data. Takes the place of `dot`.\n */\n swatch?: SwatchColor\n}\n\n/**\n * A short word or count that says what state something is in. Live, delayed, 3 new.\n *\n * @remarks\n * A `Badge` is status: what state a thing is in right now. For categories and metadata (a line, a\n * facility, a topic) use a {@link Tag | Tag}, which is quieter.\n *\n * @privateRemarks\n * A short status or count: \"Live\", \"Over quota\", \"3 new\", \"Overdue\".\n * Metadata and categories are Tags; a Badge says what *state* something is in.\n */\nexport const Badge = forwardRef<HTMLSpanElement, BadgeProps>(function Badge(\n {\n tone = 'neutral',\n variant = 'soft',\n size = 'sm',\n dot = false,\n swatch,\n className,\n children,\n ...rest\n },\n ref,\n) {\n return (\n <span\n ref={ref}\n className={cx(styles.badge, className)}\n data-tone={tone}\n data-variant={variant}\n data-size={size}\n {...rest}\n >\n {swatch !== undefined ? (\n <Swatch color={swatch} />\n ) : dot ? (\n <span className={styles.dot} aria-hidden=\"true\" />\n ) : null}\n {children}\n </span>\n )\n})\n"],"mappings":";;;;;;AAmCA,IAAaE,IAAQC,EAAwC,SAC3D,EACE,UAAO,WACP,aAAU,QACV,UAAO,MACP,SAAM,IACN,WACA,cACA,aACA,GAAGC,KAEL,GACA;CACA,OACE,kBAAC,QAAD;EACO;EACL,WAAWC,EAAGL,EAAO,OAAOM,CAAS;EACrC,aAAWC;EACX,gBAAcC;EACd,aAAWC;EACX,GAAIL;EANN,UAAA,CAQGM,MAAW,KAAA,IAERC,IACF,kBAAC,QAAD;GAAM,WAAWX,EAAO;GAAK,eAAY;EAAQ,CAAA,IAC/C,OAHF,kBAACY,GAAD,EAAQ,OAAOF,EAAS,CAAA,GAIzBG,CACG;;AAEV,CAAC"}
|
|
@@ -1,90 +1,77 @@
|
|
|
1
1
|
import { cx as e } from "../../../utils/cx.js";
|
|
2
2
|
import { CheckIcon as t, CopyIcon as n } from "../../../icons/icons.js";
|
|
3
3
|
import { Button as r } from "../../actions/Button/Button.js";
|
|
4
|
-
import {
|
|
5
|
-
import a from "
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
4
|
+
import { useClipboard as i } from "../../actions/CopyButton/useClipboard.js";
|
|
5
|
+
import { trimTrailingNewlines as a } from "../../../utils/newlines.js";
|
|
6
|
+
import o from "./CodeBlock.module.js";
|
|
7
|
+
import { forwardRef as s, useId as c } from "react";
|
|
8
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
8
9
|
//#region src/components/display/CodeBlock/CodeBlock.tsx
|
|
9
|
-
var
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let N = async () => {
|
|
15
|
-
clearTimeout(E.current);
|
|
16
|
-
try {
|
|
17
|
-
await navigator.clipboard.writeText(O), T("copied");
|
|
18
|
-
} catch {
|
|
19
|
-
T("failed");
|
|
20
|
-
}
|
|
21
|
-
E.current = setTimeout(() => {
|
|
22
|
-
T("idle");
|
|
23
|
-
}, 2e3);
|
|
24
|
-
};
|
|
25
|
-
return /* @__PURE__ */ f("figure", {
|
|
26
|
-
ref: C,
|
|
27
|
-
className: e(a.codeBlock, x),
|
|
10
|
+
var d = s(function({ code: s, language: d, tokens: f, title: p, showLineNumbers: m = !1, highlightLines: h, copyable: g = !0, wrap: _ = !1, copyLabel: v = "Copy code", className: y, ...b }, x) {
|
|
11
|
+
let S = i({ timeout: 2e3 }), C = S.copied ? "copied" : S.error ? "failed" : "idle", w = c(), T = a(s), E = T.split("\n"), D = f?.length === E.length && f.every((e, t) => e.map((e) => e.content).join("") === E[t]) ? f : void 0, O = new Set(h), k = !!p || !!d || g;
|
|
12
|
+
return /* @__PURE__ */ u("figure", {
|
|
13
|
+
ref: x,
|
|
14
|
+
className: e(o.codeBlock, y),
|
|
28
15
|
"data-kiln-component": "",
|
|
29
|
-
"data-wrap":
|
|
30
|
-
"data-line-numbers":
|
|
31
|
-
"aria-labelledby":
|
|
32
|
-
...
|
|
16
|
+
"data-wrap": _ || void 0,
|
|
17
|
+
"data-line-numbers": m || void 0,
|
|
18
|
+
"aria-labelledby": p ? w : void 0,
|
|
19
|
+
...b,
|
|
33
20
|
children: [
|
|
34
|
-
|
|
35
|
-
className:
|
|
21
|
+
k ? /* @__PURE__ */ u("figcaption", {
|
|
22
|
+
className: o.header,
|
|
36
23
|
children: [
|
|
37
|
-
|
|
38
|
-
id:
|
|
39
|
-
className:
|
|
40
|
-
children: h
|
|
41
|
-
}) : null,
|
|
42
|
-
p ? /* @__PURE__ */ d("span", {
|
|
43
|
-
className: a.language,
|
|
24
|
+
p ? /* @__PURE__ */ l("span", {
|
|
25
|
+
id: w,
|
|
26
|
+
className: o.title,
|
|
44
27
|
children: p
|
|
45
28
|
}) : null,
|
|
46
|
-
|
|
29
|
+
d ? /* @__PURE__ */ l("span", {
|
|
30
|
+
className: o.language,
|
|
31
|
+
children: d
|
|
32
|
+
}) : null,
|
|
33
|
+
g ? /* @__PURE__ */ l(r, {
|
|
47
34
|
variant: "ghost",
|
|
48
35
|
tone: "neutral",
|
|
49
36
|
size: "sm",
|
|
50
|
-
className:
|
|
51
|
-
leadingIcon:
|
|
52
|
-
"aria-label":
|
|
37
|
+
className: o.copy,
|
|
38
|
+
leadingIcon: l(C === "copied" ? t : n, {}),
|
|
39
|
+
"aria-label": v,
|
|
53
40
|
onClick: () => {
|
|
54
|
-
|
|
41
|
+
S.copy(T);
|
|
55
42
|
},
|
|
56
|
-
"data-state":
|
|
57
|
-
children:
|
|
43
|
+
"data-state": C,
|
|
44
|
+
children: C === "copied" ? "Copied" : C === "failed" ? "Copy failed" : "Copy"
|
|
58
45
|
}) : null
|
|
59
46
|
]
|
|
60
47
|
}) : null,
|
|
61
|
-
/* @__PURE__ */
|
|
62
|
-
className:
|
|
48
|
+
/* @__PURE__ */ l("pre", {
|
|
49
|
+
className: o.pre,
|
|
63
50
|
tabIndex: 0,
|
|
64
|
-
children: /* @__PURE__ */
|
|
65
|
-
className:
|
|
66
|
-
children:
|
|
67
|
-
className:
|
|
68
|
-
"data-line":
|
|
69
|
-
"data-highlighted":
|
|
70
|
-
children: [
|
|
71
|
-
className:
|
|
51
|
+
children: /* @__PURE__ */ l("code", {
|
|
52
|
+
className: o.code,
|
|
53
|
+
children: E.map((e, t) => /* @__PURE__ */ u("span", {
|
|
54
|
+
className: o.line,
|
|
55
|
+
"data-line": m ? t + 1 : void 0,
|
|
56
|
+
"data-highlighted": O.has(t + 1) || void 0,
|
|
57
|
+
children: [D?.[t] ? D[t].map((e, t) => e.type ? /* @__PURE__ */ l("span", {
|
|
58
|
+
className: o.token,
|
|
72
59
|
"data-token": e.type,
|
|
73
60
|
children: e.content
|
|
74
|
-
}, t) : e.content) : e, t <
|
|
61
|
+
}, t) : e.content) : e, t < E.length - 1 ? "\n" : null]
|
|
75
62
|
}, t))
|
|
76
63
|
})
|
|
77
64
|
}),
|
|
78
|
-
|
|
79
|
-
className:
|
|
65
|
+
g ? /* @__PURE__ */ l("span", {
|
|
66
|
+
className: o.visuallyHidden,
|
|
80
67
|
role: "status",
|
|
81
68
|
"aria-live": "polite",
|
|
82
|
-
children:
|
|
69
|
+
children: C === "copied" ? "Copied to clipboard" : C === "failed" ? "Copy failed" : ""
|
|
83
70
|
}) : null
|
|
84
71
|
]
|
|
85
72
|
});
|
|
86
73
|
});
|
|
87
74
|
//#endregion
|
|
88
|
-
export {
|
|
75
|
+
export { d as CodeBlock };
|
|
89
76
|
|
|
90
77
|
//# sourceMappingURL=CodeBlock.js.map
|