@redis-ui/components 51.20.0 → 51.21.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.
@@ -16,14 +16,14 @@ var SelectOptionContainer = (0, styled_components.default)(require_index.Item).w
16
16
  return $hidden ? styled_components.css`
17
17
  display: none;
18
18
  ` : styled_components.css`
19
- height: ${theme.height};
19
+ min-height: ${theme.height};
20
20
  font-size: ${theme.fontSize};
21
21
  padding: ${theme.padding};
22
22
  gap: ${theme.gap};
23
23
 
24
24
  ${compact && styled_components.css`
25
25
  [data-content-variant='compact'] & {
26
- height: ${compact.option.height};
26
+ min-height: ${compact.option.height};
27
27
  font-size: ${compact.option.fontSize};
28
28
  padding: ${compact.option.padding};
29
29
  gap: ${compact.option.gap};
@@ -14,14 +14,14 @@ var SelectOptionContainer = _styled(Item).withConfig({
14
14
  return $hidden ? css`
15
15
  display: none;
16
16
  ` : css`
17
- height: ${theme.height};
17
+ min-height: ${theme.height};
18
18
  font-size: ${theme.fontSize};
19
19
  padding: ${theme.padding};
20
20
  gap: ${theme.gap};
21
21
 
22
22
  ${compact && css`
23
23
  [data-content-variant='compact'] & {
24
- height: ${compact.option.height};
24
+ min-height: ${compact.option.height};
25
25
  font-size: ${compact.option.fontSize};
26
26
  padding: ${compact.option.padding};
27
27
  gap: ${compact.option.gap};
@@ -7,16 +7,46 @@ let react_jsx_runtime = require("react/jsx-runtime");
7
7
  let react = require("react");
8
8
  //#region src/Select/components/Content/components/OptionList/OptionList.tsx
9
9
  var DEFAULT_ITEM_HEIGHT = 31;
10
+ var getCap = (heights, count) => {
11
+ const first = heights.slice(0, count);
12
+ const measured = first.reduce((sum, height) => sum + height, 0);
13
+ return measured ? measured + measured / first.length * (count - first.length) : DEFAULT_ITEM_HEIGHT * count;
14
+ };
10
15
  var OptionList = ({ optionValueRender = require_defaultValueRender.defaultValueRender, optionComponent: OptionComponent = require_Option.default, maxVisibleItems = 0, virtualized, ...restProps }) => {
11
16
  const [hidden, setHidden] = (0, react.useState)(false);
12
17
  const [viewport, setViewport] = (0, react.useState)(null);
13
18
  const viewPortRef = (0, react.useRef)(null);
14
- const [itemHeight, setItemHeight] = (0, react.useState)(DEFAULT_ITEM_HEIGHT);
15
- (0, react.useLayoutEffect)(() => {
16
- setItemHeight((viewPortRef.current?.querySelector("[data-radix-collection-item]"))?.offsetHeight || DEFAULT_ITEM_HEIGHT);
17
- }, []);
18
19
  const { getValidOptions, hasSelection, hasSearch, isOptionSelected, options, isSingleSelect } = require_Context.useSelectContext();
19
20
  const validOptions = getValidOptions();
21
+ const lastMeasureRef = (0, react.useRef)({
22
+ count: maxVisibleItems,
23
+ heights: []
24
+ });
25
+ const [maxHeight, setMaxHeight] = (0, react.useState)(maxVisibleItems > 0 ? DEFAULT_ITEM_HEIGHT * maxVisibleItems : 0);
26
+ (0, react.useLayoutEffect)(() => {
27
+ if (maxVisibleItems <= 0) {
28
+ setMaxHeight(0);
29
+ return;
30
+ }
31
+ if (virtualized && viewPortRef.current && viewPortRef.current.scrollTop > 0) {
32
+ const { count, heights } = lastMeasureRef.current;
33
+ if ((count !== maxVisibleItems || !maxHeight) && heights.length > 0) {
34
+ lastMeasureRef.current = {
35
+ count: maxVisibleItems,
36
+ heights
37
+ };
38
+ setMaxHeight(getCap(heights, maxVisibleItems));
39
+ }
40
+ return;
41
+ }
42
+ const items = Array.from(viewPortRef.current?.querySelectorAll("[data-radix-collection-item]:not([data-hidden])") ?? []);
43
+ const heights = (virtualized ? items : items.slice(0, maxVisibleItems)).map((item) => item.offsetHeight);
44
+ lastMeasureRef.current = {
45
+ count: maxVisibleItems,
46
+ heights
47
+ };
48
+ setMaxHeight(getCap(heights, maxVisibleItems));
49
+ });
20
50
  if (isSingleSelect && hasSelection && hasSearch && !validOptions.find(isOptionSelected)) {
21
51
  const selectedOption = options.find(isOptionSelected);
22
52
  if (selectedOption) validOptions.push({
@@ -39,7 +69,7 @@ var OptionList = ({ optionValueRender = require_defaultValueRender.defaultValueR
39
69
  viewPortRef.current = el;
40
70
  setViewport(el);
41
71
  },
42
- $maxHeight: itemHeight * (maxVisibleItems > 0 ? Math.max(maxVisibleItems, 1) : 0),
72
+ $maxHeight: maxHeight,
43
73
  $hidden: hidden,
44
74
  children: virtualized ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Virtual.Virtual, {
45
75
  validOptions,
@@ -7,16 +7,46 @@ import { jsx } from "react/jsx-runtime";
7
7
  import { useLayoutEffect, useRef, useState } from "react";
8
8
  //#region src/Select/components/Content/components/OptionList/OptionList.tsx
9
9
  var DEFAULT_ITEM_HEIGHT = 31;
10
+ var getCap = (heights, count) => {
11
+ const first = heights.slice(0, count);
12
+ const measured = first.reduce((sum, height) => sum + height, 0);
13
+ return measured ? measured + measured / first.length * (count - first.length) : DEFAULT_ITEM_HEIGHT * count;
14
+ };
10
15
  var OptionList = ({ optionValueRender = defaultValueRender, optionComponent: OptionComponent = Option, maxVisibleItems = 0, virtualized, ...restProps }) => {
11
16
  const [hidden, setHidden] = useState(false);
12
17
  const [viewport, setViewport] = useState(null);
13
18
  const viewPortRef = useRef(null);
14
- const [itemHeight, setItemHeight] = useState(DEFAULT_ITEM_HEIGHT);
15
- useLayoutEffect(() => {
16
- setItemHeight((viewPortRef.current?.querySelector("[data-radix-collection-item]"))?.offsetHeight || DEFAULT_ITEM_HEIGHT);
17
- }, []);
18
19
  const { getValidOptions, hasSelection, hasSearch, isOptionSelected, options, isSingleSelect } = useSelectContext();
19
20
  const validOptions = getValidOptions();
21
+ const lastMeasureRef = useRef({
22
+ count: maxVisibleItems,
23
+ heights: []
24
+ });
25
+ const [maxHeight, setMaxHeight] = useState(maxVisibleItems > 0 ? DEFAULT_ITEM_HEIGHT * maxVisibleItems : 0);
26
+ useLayoutEffect(() => {
27
+ if (maxVisibleItems <= 0) {
28
+ setMaxHeight(0);
29
+ return;
30
+ }
31
+ if (virtualized && viewPortRef.current && viewPortRef.current.scrollTop > 0) {
32
+ const { count, heights } = lastMeasureRef.current;
33
+ if ((count !== maxVisibleItems || !maxHeight) && heights.length > 0) {
34
+ lastMeasureRef.current = {
35
+ count: maxVisibleItems,
36
+ heights
37
+ };
38
+ setMaxHeight(getCap(heights, maxVisibleItems));
39
+ }
40
+ return;
41
+ }
42
+ const items = Array.from(viewPortRef.current?.querySelectorAll("[data-radix-collection-item]:not([data-hidden])") ?? []);
43
+ const heights = (virtualized ? items : items.slice(0, maxVisibleItems)).map((item) => item.offsetHeight);
44
+ lastMeasureRef.current = {
45
+ count: maxVisibleItems,
46
+ heights
47
+ };
48
+ setMaxHeight(getCap(heights, maxVisibleItems));
49
+ });
20
50
  if (isSingleSelect && hasSelection && hasSearch && !validOptions.find(isOptionSelected)) {
21
51
  const selectedOption = options.find(isOptionSelected);
22
52
  if (selectedOption) validOptions.push({
@@ -39,7 +69,7 @@ var OptionList = ({ optionValueRender = defaultValueRender, optionComponent: Opt
39
69
  viewPortRef.current = el;
40
70
  setViewport(el);
41
71
  },
42
- $maxHeight: itemHeight * (maxVisibleItems > 0 ? Math.max(maxVisibleItems, 1) : 0),
72
+ $maxHeight: maxHeight,
43
73
  $hidden: hidden,
44
74
  children: virtualized ? /* @__PURE__ */ jsx(Virtual, {
45
75
  validOptions,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@redis-ui/components",
3
3
  "license": "UNLICENSED",
4
- "version": "51.20.0",
4
+ "version": "51.21.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "repository": "git@github.com:redislabsdev/redis-ui.git",
@@ -230,6 +230,40 @@ const customValueRender: SelectValueRender = ({ option, isSelected, isOptionValu
230
230
  />
231
231
  ```
232
232
 
233
+ ### MultilineOption
234
+ > Options grow with their content, so a custom `valueRender` can render several lines for an option.
235
+ > Option height is only a minimum, so vertical spacing for multi-line content is up to the renderer.
236
+ > Use `isOptionValue` to render the full content in the list and only the short value in the trigger.
237
+ ```tsx
238
+ import { FlexGroup, Select, SelectValueRender, Typography } from '@redis-ui/components';
239
+
240
+ const valueRender: SelectValueRender = ({ option, isOptionValue }) => {
241
+ if (!isOptionValue) {
242
+ return <Typography.Body ellipsis>{option.label}</Typography.Body>;
243
+ }
244
+
245
+ return (
246
+ <FlexGroup direction="column" align="start" minWidth="0" gap="0" paddingBlock="S">
247
+ <Typography.Body ellipsis>{option.label}</Typography.Body>
248
+ <Typography.Body size="S" color="secondary" ellipsis>
249
+ {option.value}
250
+ </Typography.Body>
251
+ </FlexGroup>
252
+ );
253
+ };
254
+
255
+ <Select
256
+ aria-label="Source RAM store"
257
+ placeholder="Select an Agent Memory store"
258
+ options={[
259
+ { value: 'st_dd4a26784d7f48e4a5eb2699f867ef53', label: 'support-chat-memory' },
260
+ { value: 'st_8629caf634bb47d9ad66afd172b1eeb8', label: 'product-catalog' }
261
+ ]}
262
+ valueRender={valueRender}
263
+ onChange={(value) => console.log(value)}
264
+ />
265
+ ```
266
+
233
267
  ### CustomSearch
234
268
  > If there is additional info for an option, then it is possible to search by that info as well.
235
269
  > Set the comparison handler to the `customCompare` prop to enable custom search.
@@ -637,7 +637,7 @@ function Render() {
637
637
  - `Tooltip.Trigger` can wrap plain text, SVG, or multi-element triggers by setting `withButton`.
638
638
  - `Tooltip.Compose` supports controlled and uncontrolled open state.
639
639
  - `Tooltip.Content.Compose` defaults `placement` to `top`, `sideOffset` to `5`, `portal` to `document.body`, and `interactive` to `false`.
640
- - When the theme sets `tooltip.contentTextColor` (the Redis Ultra themes do), custom content and the `Tooltip.Card` title, body and footer link use that color so they stay readable on the tooltip background. Passing `backgroundColor` opts out, and the content keeps its own colors.
640
+ - When the theme sets `tooltip.contentTextColor` (the Redis Ultra dark theme does), custom content and the `Tooltip.Card` title, body and footer link use that color so they stay readable on the tooltip background. Passing `backgroundColor` opts out, and the content keeps its own colors.
641
641
  - `Tooltip.Card.Header` hides the close button by default.
642
642
  - `Tooltip.Card.Footer` renders nothing when both `link` and `actionButtonHandler` are missing.
643
643
  - For async tooltip content, prefer `Popover` unless the tooltip interaction is required.