@redis-ui/components 51.28.0 → 51.29.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.
@@ -24,7 +24,7 @@ var useIsScrollable = ({ code, overflow, maxHeight, language }) => {
24
24
  ]);
25
25
  return [ref, isScrollable];
26
26
  };
27
- var CodeBlock = (0, react.forwardRef)(({ code, language, copyLabel, overflow = "scroll", maxHeight, size = "M", "aria-label": ariaLabel = "Code", ...restProps }, ref) => {
27
+ var CodeBlock = (0, react.forwardRef)(({ code, language, copyLabel, onCopy, onCopyError, overflow = "scroll", maxHeight, size = "M", "aria-label": ariaLabel = "Code", ...restProps }, ref) => {
28
28
  const [preRef, isScrollable] = useIsScrollable({
29
29
  code,
30
30
  overflow,
@@ -58,7 +58,9 @@ var CodeBlock = (0, react.forwardRef)(({ code, language, copyLabel, overflow = "
58
58
  $size: size,
59
59
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopyToClipboardButton.default, {
60
60
  textToCopy: code,
61
- "aria-label": copyLabel
61
+ "aria-label": copyLabel,
62
+ onCopy,
63
+ onCopyError
62
64
  })
63
65
  })]
64
66
  });
@@ -24,7 +24,7 @@ var useIsScrollable = ({ code, overflow, maxHeight, language }) => {
24
24
  ]);
25
25
  return [ref, isScrollable];
26
26
  };
27
- var CodeBlock = forwardRef(({ code, language, copyLabel, overflow = "scroll", maxHeight, size = "M", "aria-label": ariaLabel = "Code", ...restProps }, ref) => {
27
+ var CodeBlock = forwardRef(({ code, language, copyLabel, onCopy, onCopyError, overflow = "scroll", maxHeight, size = "M", "aria-label": ariaLabel = "Code", ...restProps }, ref) => {
28
28
  const [preRef, isScrollable] = useIsScrollable({
29
29
  code,
30
30
  overflow,
@@ -58,7 +58,9 @@ var CodeBlock = forwardRef(({ code, language, copyLabel, overflow = "scroll", ma
58
58
  $size: size,
59
59
  children: /* @__PURE__ */ jsx(CopyToClipboardButton, {
60
60
  textToCopy: code,
61
- "aria-label": copyLabel
61
+ "aria-label": copyLabel,
62
+ onCopy,
63
+ onCopyError
62
64
  })
63
65
  })]
64
66
  });
@@ -11,11 +11,15 @@ export type OwnCodeBlockProps = {
11
11
  language?: CodeBlockLanguage;
12
12
  /** Shows a copy button and is used as its accessible name */
13
13
  copyLabel?: string;
14
+ /** Called with the code after the copy button copies it */
15
+ onCopy?: (text: string) => void;
16
+ /** Called when the copy button fails to copy */
17
+ onCopyError?: (error: unknown) => void;
14
18
  /** How long lines behave: scroll horizontally, wrap, or truncate with an ellipsis */
15
19
  overflow?: CodeBlockOverflow;
16
20
  /** Scrolls vertically past this height */
17
21
  maxHeight?: string;
18
22
  size?: CodeBlockSize;
19
23
  };
20
- export type RestCodeBlockProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
24
+ export type RestCodeBlockProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onCopy'>;
21
25
  export type CodeBlockProps = OwnCodeBlockProps & RestCodeBlockProps;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@redis-ui/components",
3
3
  "license": "UNLICENSED",
4
- "version": "51.28.0",
4
+ "version": "51.29.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "repository": "git@github.com:redislabsdev/redis-ui.git",
@@ -13,10 +13,12 @@ import { CodeBlock } from '@redis-ui/components';
13
13
  | code | `string` | *required* | Text rendered in the block and copied by the copy button |
14
14
  | language | `'bash' \| 'json' \| 'python' \| 'typescript'` | - | Highlights the code's syntax. Without it, the code is plain text |
15
15
  | copyLabel | `string` | - | Shows a copy button and is used as its accessible name |
16
+ | onCopy | `(text: string) => void` | - | Called with the code after the copy button writes it to the clipboard, e.g. to show a toast |
17
+ | onCopyError | `(error: unknown) => void` | - | Called when the clipboard write fails |
16
18
  | overflow | `'scroll' \| 'wrap' \| 'ellipsis'` | `'scroll'` | How long lines behave: scroll horizontally, wrap (use for commands and prompts), or truncate with an ellipsis |
17
19
  | maxHeight | `string` | - | Scrolls vertically past this height (any CSS length, e.g. `'19rem'`) |
18
20
  | size | `'M' \| 'S'` | `'M'` | Text size. `S` is the compact size |
19
- | native div props | `Omit<HTMLAttributes<HTMLDivElement>, 'children'>` | - | Passed to the root element. `aria-label` names the block when it scrolls (defaults to `Code`) |
21
+ | native div props | `Omit<HTMLAttributes<HTMLDivElement>, 'children' \| 'onCopy'>` | - | Passed to the root element. `aria-label` names the block when it scrolls (defaults to `Code`) |
20
22
 
21
23
  ## Examples
22
24
 
@@ -41,6 +43,7 @@ import { CodeBlock } from '@redis-ui/components';
41
43
  ```tsx
42
44
  <CodeBlock code={installCommand} copyLabel="Copy install command" />
43
45
  <CodeBlock code={lensSnippet} copyLabel="Copy code" />
46
+ <CodeBlock code={lensSnippet} copyLabel="Copy code" onCopy={() => showToast('Code copied')} />
44
47
  ```
45
48
 
46
49
  ### WrappedCommand