@redis-ui/components 51.28.0 → 51.30.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.
@@ -2,6 +2,6 @@ import { ChipProps } from './Chip.types';
2
2
  declare const Chip: (({ text, onClose, closeButtonTitle, ...restProps }: ChipProps) => import("react/jsx-runtime").JSX.Element) & {
3
3
  Compose: ({ size, variant, disabled, tooltip, ...restProps }: import("./components/Compose/Compose.types").RestChipComposeProps & import("./components/Compose/Compose.types").ChipComposeProps) => import("react/jsx-runtime").JSX.Element;
4
4
  Title: ({ size, ...restProps }: import("..").TypographyBodyProps) => import("react/jsx-runtime").JSX.Element;
5
- CloseButton: ({ onClose, icon: Icon, title, ...restProps }: import("./components/CloseButton/CloseButton.types").RestChipCloseButtonProps & import("./components/CloseButton/CloseButton.types").ChipCloseButtonProps) => import("react/jsx-runtime").JSX.Element | null;
5
+ CloseButton: ({ onClose, icon, title, ...restProps }: import("./components/CloseButton/CloseButton.types").RestChipCloseButtonProps & import("./components/CloseButton/CloseButton.types").ChipCloseButtonProps) => import("react/jsx-runtime").JSX.Element | null;
6
6
  };
7
7
  export default Chip;
@@ -1,5 +1,6 @@
1
1
  const require_Chip_context = require("../../Chip.context.cjs");
2
2
  const require_CloseButton_style = require("./CloseButton.style.cjs");
3
+ let _redislabsdev_redis_ui_styles = require("@redis-ui/styles");
3
4
  let react_jsx_runtime = require("react/jsx-runtime");
4
5
  let _redislabsdev_redis_ui_icons = require("@redis-ui/icons");
5
6
  //#region src/Chip/components/CloseButton/CloseButton.tsx
@@ -7,9 +8,15 @@ var sizeMapper = {
7
8
  S: "M",
8
9
  M: "L"
9
10
  };
10
- var CloseButton = ({ onClose, icon: Icon = _redislabsdev_redis_ui_icons.ToastCancelIcon, title = "Remove", ...restProps }) => {
11
+ var glyphIcons = {
12
+ circle: _redislabsdev_redis_ui_icons.ToastCancelIcon,
13
+ cross: _redislabsdev_redis_ui_icons.CancelSlimIcon
14
+ };
15
+ var CloseButton = ({ onClose, icon, title = "Remove", ...restProps }) => {
11
16
  const { size, variant, disabled } = require_Chip_context.useChipContext();
17
+ const { glyph = "circle", size: sizeStyle } = (0, _redislabsdev_redis_ui_styles.useTheme)().components.chip.closeButton;
12
18
  if (!onClose || disabled) return null;
19
+ const Icon = icon ?? glyphIcons[glyph];
13
20
  const handleRemoveChip = (e) => {
14
21
  e.stopPropagation();
15
22
  onClose();
@@ -24,6 +31,7 @@ var CloseButton = ({ onClose, icon: Icon = _redislabsdev_redis_ui_icons.ToastCan
24
31
  ...restProps,
25
32
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
26
33
  size: sizeMapper[size],
34
+ customSize: sizeStyle[size].iconSize,
27
35
  "aria-hidden": true
28
36
  })
29
37
  });
@@ -1,2 +1,2 @@
1
1
  import { ChipCloseButtonProps, RestChipCloseButtonProps } from './CloseButton.types';
2
- export declare const CloseButton: ({ onClose, icon: Icon, title, ...restProps }: RestChipCloseButtonProps & ChipCloseButtonProps) => import("react/jsx-runtime").JSX.Element | null;
2
+ export declare const CloseButton: ({ onClose, icon, title, ...restProps }: RestChipCloseButtonProps & ChipCloseButtonProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,15 +1,22 @@
1
1
  import { useChipContext } from "../../Chip.context.js";
2
2
  import { CloseButton as CloseButton$1 } from "./CloseButton.style.js";
3
+ import { useTheme } from "@redis-ui/styles";
3
4
  import { jsx } from "react/jsx-runtime";
4
- import { ToastCancelIcon } from "@redis-ui/icons";
5
+ import { CancelSlimIcon, ToastCancelIcon } from "@redis-ui/icons";
5
6
  //#region src/Chip/components/CloseButton/CloseButton.tsx
6
7
  var sizeMapper = {
7
8
  S: "M",
8
9
  M: "L"
9
10
  };
10
- var CloseButton = ({ onClose, icon: Icon = ToastCancelIcon, title = "Remove", ...restProps }) => {
11
+ var glyphIcons = {
12
+ circle: ToastCancelIcon,
13
+ cross: CancelSlimIcon
14
+ };
15
+ var CloseButton = ({ onClose, icon, title = "Remove", ...restProps }) => {
11
16
  const { size, variant, disabled } = useChipContext();
17
+ const { glyph = "circle", size: sizeStyle } = useTheme().components.chip.closeButton;
12
18
  if (!onClose || disabled) return null;
19
+ const Icon = icon ?? glyphIcons[glyph];
13
20
  const handleRemoveChip = (e) => {
14
21
  e.stopPropagation();
15
22
  onClose();
@@ -24,6 +31,7 @@ var CloseButton = ({ onClose, icon: Icon = ToastCancelIcon, title = "Remove", ..
24
31
  ...restProps,
25
32
  children: /* @__PURE__ */ jsx(Icon, {
26
33
  size: sizeMapper[size],
34
+ customSize: sizeStyle[size].iconSize,
27
35
  "aria-hidden": true
28
36
  })
29
37
  });
@@ -8,13 +8,23 @@ var CloseButton = styled_components.default.button.withConfig({
8
8
  componentId: "RedisUI__sc-1pnn9du-0"
9
9
  })([
10
10
  "",
11
- ";flex:none;border:none;cursor:pointer;background-color:transparent;display:flex;align-items:center;justify-content:center;padding:0;&:hover{background-color:transparent;}",
11
+ ";flex:none;border:none;cursor:pointer;background-color:transparent;display:flex;align-items:center;justify-content:center;padding:0;",
12
12
  ";"
13
13
  ], ({ $size, $variant }) => {
14
14
  const style = (0, _redislabsdev_redis_ui_styles.useTheme)().components.chip.closeButton;
15
+ const { color, hoverColor, hoverBgColor } = style.variant[$variant];
16
+ const { size, borderRadius, margin } = style.size[$size];
15
17
  return styled_components.css`
16
- color: ${style.variant[$variant].color};
17
- border-radius: ${style.size[$size].borderRadius};
18
+ color: ${color};
19
+ width: ${size};
20
+ height: ${size};
21
+ border-radius: ${borderRadius};
22
+ ${margin && `margin: ${margin};`}
23
+
24
+ &:hover {
25
+ background-color: ${hoverBgColor || "transparent"};
26
+ ${hoverColor && `color: ${hoverColor};`}
27
+ }
18
28
  `;
19
29
  }, (0, _redislabsdev_redis_ui_styles.getFocusStyle)("0px"));
20
30
  //#endregion
@@ -6,13 +6,23 @@ var CloseButton = _styled.button.withConfig({
6
6
  componentId: "RedisUI__sc-1pnn9du-0"
7
7
  })([
8
8
  "",
9
- ";flex:none;border:none;cursor:pointer;background-color:transparent;display:flex;align-items:center;justify-content:center;padding:0;&:hover{background-color:transparent;}",
9
+ ";flex:none;border:none;cursor:pointer;background-color:transparent;display:flex;align-items:center;justify-content:center;padding:0;",
10
10
  ";"
11
11
  ], ({ $size, $variant }) => {
12
12
  const style = useTheme().components.chip.closeButton;
13
+ const { color, hoverColor, hoverBgColor } = style.variant[$variant];
14
+ const { size, borderRadius, margin } = style.size[$size];
13
15
  return css`
14
- color: ${style.variant[$variant].color};
15
- border-radius: ${style.size[$size].borderRadius};
16
+ color: ${color};
17
+ width: ${size};
18
+ height: ${size};
19
+ border-radius: ${borderRadius};
20
+ ${margin && `margin: ${margin};`}
21
+
22
+ &:hover {
23
+ background-color: ${hoverBgColor || "transparent"};
24
+ ${hoverColor && `color: ${hoverColor};`}
25
+ }
16
26
  `;
17
27
  }, getFocusStyle("0px"));
18
28
  //#endregion
@@ -1,11 +1,15 @@
1
- const require_Typography = require("../../../Typography/Typography.cjs");
2
1
  const require_Chip_context = require("../../Chip.context.cjs");
2
+ const require_Title_style = require("./Title.style.cjs");
3
+ let _redislabsdev_redis_ui_styles = require("@redis-ui/styles");
3
4
  let react_jsx_runtime = require("react/jsx-runtime");
4
5
  //#region src/Chip/components/Title/Title.tsx
5
6
  var Title = ({ size, ...restProps }) => {
6
7
  const context = require_Chip_context.useChipContext();
7
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Typography.default.Body, {
8
+ const { fontFamily, sizes } = (0, _redislabsdev_redis_ui_styles.useTheme)().components.chip;
9
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Title_style.Title, {
8
10
  size: size ?? context.size,
11
+ $fontSize: size ? void 0 : sizes[context.size].fontSize,
12
+ $fontFamily: fontFamily,
9
13
  ellipsis: true,
10
14
  tooltipOnEllipsis: true,
11
15
  ...restProps
@@ -1,11 +1,15 @@
1
- import Typography from "../../../Typography/Typography.js";
2
1
  import { useChipContext } from "../../Chip.context.js";
2
+ import { Title as Title$1 } from "./Title.style.js";
3
+ import { useTheme } from "@redis-ui/styles";
3
4
  import { jsx } from "react/jsx-runtime";
4
5
  //#region src/Chip/components/Title/Title.tsx
5
6
  var Title = ({ size, ...restProps }) => {
6
7
  const context = useChipContext();
7
- return /* @__PURE__ */ jsx(Typography.Body, {
8
+ const { fontFamily, sizes } = useTheme().components.chip;
9
+ return /* @__PURE__ */ jsx(Title$1, {
8
10
  size: size ?? context.size,
11
+ $fontSize: size ? void 0 : sizes[context.size].fontSize,
12
+ $fontFamily: fontFamily,
9
13
  ellipsis: true,
10
14
  tooltipOnEllipsis: true,
11
15
  ...restProps
@@ -0,0 +1,15 @@
1
+ const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
2
+ const require_Typography = require("../../../Typography/Typography.cjs");
3
+ let styled_components = require("styled-components");
4
+ styled_components = require_runtime.__toESM(styled_components, 1);
5
+ //#region src/Chip/components/Title/Title.style.ts
6
+ var Title = (0, styled_components.default)(require_Typography.default.Body).withConfig({
7
+ displayName: "Titlestyle__Title",
8
+ componentId: "RedisUI__sc-77iu4i-0"
9
+ })([
10
+ "",
11
+ " ",
12
+ ""
13
+ ], ({ $fontSize }) => $fontSize && `font-size: ${$fontSize};`, ({ $fontFamily }) => $fontFamily && `font-family: ${$fontFamily};`);
14
+ //#endregion
15
+ exports.Title = Title;
@@ -0,0 +1,4 @@
1
+ export declare const Title: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../..").TypographyBodyProps & import("react").RefAttributes<HTMLElement>>, any, {
2
+ $fontSize?: string;
3
+ $fontFamily?: string;
4
+ }, never>;
@@ -0,0 +1,13 @@
1
+ import Typography from "../../../Typography/Typography.js";
2
+ import _styled from "styled-components";
3
+ //#region src/Chip/components/Title/Title.style.ts
4
+ var Title = _styled(Typography.Body).withConfig({
5
+ displayName: "Titlestyle__Title",
6
+ componentId: "RedisUI__sc-77iu4i-0"
7
+ })([
8
+ "",
9
+ " ",
10
+ ""
11
+ ], ({ $fontSize }) => $fontSize && `font-size: ${$fontSize};`, ({ $fontFamily }) => $fontFamily && `font-family: ${$fontFamily};`);
12
+ //#endregion
13
+ export { Title };
@@ -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.30.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "repository": "git@github.com:redislabsdev/redis-ui.git",
@@ -147,7 +147,7 @@ const handleClose = () => {};
147
147
  ## Notes
148
148
 
149
149
  - `Chip.Compose` accepts either a simple tooltip string or full tooltip content props and wraps the chip in `Tooltip` only when `tooltip` is provided.
150
- - `Chip.CloseButton` defaults to the `ToastCancelIcon` icon and a `Remove` title.
150
+ - `Chip.CloseButton` defaults to a `Remove` title and to the icon the theme picks: `ToastCancelIcon` in `themes`, `CancelSlimIcon` in `themesNext`. Pass `icon` to override it.
151
151
  - `Chip.Title` uses `Typography.Body` internally and enables ellipsis tooltips automatically.
152
152
  - `flat` chips should not receive `onClose`; that variant is intentionally non-closable.
153
153
  - When a closable chip is disabled, the close button is hidden.
@@ -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