@rescui/dropdown-menu 0.11.15-RUI-293-Update-menu-component-7a032357e.20 → 0.11.15-RUI-293-Update-menu-component-hover-icon-d8a5b0551.33

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.
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import React, { useRef, useState } from 'react';
2
+ import React, { useState } from 'react';
3
3
  import { useThemeWithUndefined } from '@rescui/ui-contexts';
4
4
  import { Dropdown } from '@rescui/dropdown';
5
5
  import { Menu } from '@rescui/menu';
@@ -33,19 +33,19 @@ const DropdownMenu = _ref => {
33
33
  className,
34
34
  ...restProps
35
35
  } = _ref;
36
- const menuWrapperRef = useRef(null);
36
+ const [menuWrapperEl, setMenuWrapperEl] = useState(null);
37
37
  const [height, setHeight] = useState(0);
38
38
  let itemHeightFromCss = null;
39
39
  let contrastPrimaryFromCss = null;
40
40
 
41
- if (menuWrapperRef.current) {
41
+ if (menuWrapperEl) {
42
42
  // In theory this part of the code might cause issues with SSR.
43
- // But in this specific context, because of checking ref "menuWrapperRef",
43
+ // But in this specific context, because of checking state ref "menuWrapperEl",
44
44
  // we are sure that the value will still be "null" on the first render.
45
45
  // Therefore, the first render on the client will be the same as on the server.
46
46
  // Also, there will be no layout shifts on the following renders because
47
47
  // it's a dropdown-content and in most cases it opens only on-demand
48
- const menuWrapperStyles = getComputedStyle(menuWrapperRef.current);
48
+ const menuWrapperStyles = getComputedStyle(menuWrapperEl);
49
49
  itemHeightFromCss = parseInt(menuWrapperStyles.getPropertyValue('--_rs-dropdown-menu-item-height'), 10) || null;
50
50
  contrastPrimaryFromCss = parseInt(menuWrapperStyles.getPropertyValue('--rs-dropdown-menu-contrast-primary'), 10) || null;
51
51
  }
@@ -71,7 +71,8 @@ const DropdownMenu = _ref => {
71
71
  maxHeight: maxHeight,
72
72
  className: cn(SIZE_TO_CLASS[size], styles.dropdownMenu, className)
73
73
  }, /*#__PURE__*/React.createElement(MenuWrapper, {
74
- ref: menuWrapperRef,
74
+ el: menuWrapperEl,
75
+ setEl: setMenuWrapperEl,
75
76
  onHeightUpdate: setHeight
76
77
  }, /*#__PURE__*/React.createElement(Menu, {
77
78
  size: size,
@@ -1,8 +1,8 @@
1
1
  var styles = {
2
- "sizeS": "_sizeS_sr3m6n_8",
3
- "sizeM": "_sizeM_sr3m6n_11",
4
- "sizeL": "_sizeL_sr3m6n_14",
5
- "dropdownMenu": "_dropdownMenu_sr3m6n_18",
6
- "menu": "_menu_sr3m6n_23"
2
+ "sizeS": "_sizeS_1e1gnep_8",
3
+ "sizeM": "_sizeM_1e1gnep_11",
4
+ "sizeL": "_sizeL_1e1gnep_14",
5
+ "dropdownMenu": "_dropdownMenu_1e1gnep_18",
6
+ "menu": "_menu_1e1gnep_23"
7
7
  };
8
8
  export { styles as default };
package/lib/index.css CHANGED
@@ -1,29 +1,29 @@
1
- ._sizeS_sr3m6n_8{
1
+ ._sizeS_1e1gnep_8{
2
2
  --_rs-dropdown-menu-min-width:316px;
3
3
  --_rs-dropdown-menu-max-width:389px;
4
4
  }
5
- ._sizeS_sr3m6n_8 [data-rs-internal='dropdown-menu__menu-wrapper']{
5
+ ._sizeS_1e1gnep_8 [data-rs-internal='dropdown-menu__menu-wrapper']{
6
6
  --_rs-dropdown-menu-item-height:32px;
7
7
  }
8
- ._sizeM_sr3m6n_11{
8
+ ._sizeM_1e1gnep_11{
9
9
  --_rs-dropdown-menu-min-width:316px;
10
10
  --_rs-dropdown-menu-max-width:494px;
11
11
  }
12
- ._sizeM_sr3m6n_11 [data-rs-internal='dropdown-menu__menu-wrapper']{
12
+ ._sizeM_1e1gnep_11 [data-rs-internal='dropdown-menu__menu-wrapper']{
13
13
  --_rs-dropdown-menu-item-height:40px;
14
14
  }
15
- ._sizeL_sr3m6n_14{
15
+ ._sizeL_1e1gnep_14{
16
16
  --_rs-dropdown-menu-min-width:316px;
17
17
  --_rs-dropdown-menu-max-width:494px;
18
18
  }
19
- ._sizeL_sr3m6n_14 [data-rs-internal='dropdown-menu__menu-wrapper']{
19
+ ._sizeL_1e1gnep_14 [data-rs-internal='dropdown-menu__menu-wrapper']{
20
20
  --_rs-dropdown-menu-item-height:52px;
21
21
  }
22
- ._dropdownMenu_sr3m6n_18{
22
+ ._dropdownMenu_1e1gnep_18{
23
23
  min-width:var(--_rs-dropdown-menu-min-width);
24
24
  max-width:var(--_rs-dropdown-menu-max-width);
25
25
  }
26
- ._menu_sr3m6n_23{
26
+ ._menu_1e1gnep_23{
27
27
  margin:0;
28
28
  padding:0;
29
29
 
@@ -2,5 +2,10 @@ import React from 'react';
2
2
  export type MenuWrapperProps = {
3
3
  children?: React.ReactNode;
4
4
  onHeightUpdate?: (newHeight: number) => void;
5
+ el: HTMLDivElement | null;
6
+ setEl: (el: HTMLDivElement | null) => void;
7
+ };
8
+ export declare const MenuWrapper: {
9
+ ({ children, onHeightUpdate, setEl, el }: MenuWrapperProps): React.JSX.Element;
10
+ displayName: string;
5
11
  };
6
- export declare const MenuWrapper: React.ForwardRefExoticComponent<MenuWrapperProps & React.RefAttributes<HTMLDivElement>>;
@@ -1,15 +1,19 @@
1
1
  import React from 'react';
2
2
  import { useResizeObserver } from '@rescui/use-resize-observer';
3
- const MenuWrapper = /*#__PURE__*/React.forwardRef((_ref, ref) => {
3
+
4
+ const MenuWrapper = _ref => {
4
5
  let {
5
6
  children,
6
- onHeightUpdate
7
+ onHeightUpdate,
8
+ setEl,
9
+ el
7
10
  } = _ref;
8
- useResizeObserver(ref, entry => onHeightUpdate(entry.target.offsetHeight));
11
+ useResizeObserver(el, entry => onHeightUpdate(entry.target.offsetHeight));
9
12
  return /*#__PURE__*/React.createElement("div", {
10
- ref: ref,
13
+ ref: setEl,
11
14
  "data-rs-internal": 'dropdown-menu__menu-wrapper'
12
15
  }, children);
13
- });
16
+ };
17
+
14
18
  MenuWrapper.displayName = 'MenuWrapper';
15
19
  export { MenuWrapper };
@@ -6,6 +6,8 @@ DropdownMenu is a special type of Dropdown component with predefined dimensions
6
6
 
7
7
  ### Features showcase
8
8
 
9
+ Do not combine `iconPlacement="right"` with `selected` prop.
10
+
9
11
  #### Basic example
10
12
 
11
13
  ```tsx
@@ -284,6 +286,50 @@ const Demo = () => {
284
286
  render(<Demo />);
285
287
  ```
286
288
 
289
+ #### With hover icon
290
+
291
+ ```tsx
292
+ import { useState } from 'react';
293
+ import { DropdownMenu, MenuItem } from '@rescui/dropdown-menu';
294
+ import { Button } from '@rescui/button';
295
+ import {
296
+ LeftOutlineIcon,
297
+ DownloadOutlineIcon,
298
+ CloseOutlineIcon
299
+ } from '@rescui/icons';
300
+
301
+ const Demo = () => {
302
+ const [isOpen, setIsOpen] = useState(false);
303
+
304
+ const toggleIsOpen = () => setIsOpen(s => !s);
305
+
306
+ return (
307
+ <DropdownMenu
308
+ isOpen={isOpen}
309
+ onRequestClose={() => setIsOpen(false)}
310
+ trigger={<Button onClick={toggleIsOpen}>With hover icons</Button>}
311
+ size="l"
312
+ >
313
+ <MenuItem hoverIcon={<DownloadOutlineIcon />}>Some text 1</MenuItem>
314
+ <MenuItem hoverIcon={<CloseOutlineIcon />} selected>
315
+ Some text 2
316
+ </MenuItem>
317
+ <MenuItem hoverIcon={<DownloadOutlineIcon />}>Some text 3</MenuItem>
318
+ <MenuItem
319
+ icon={<LeftOutlineIcon />}
320
+ iconPlacement="right"
321
+ hoverIcon={<CloseOutlineIcon />}
322
+ >
323
+ Some text 4
324
+ </MenuItem>
325
+ <MenuItem hoverIcon={<DownloadOutlineIcon />}>Some text 5</MenuItem>
326
+ </DropdownMenu>
327
+ );
328
+ };
329
+
330
+ render(<Demo />);
331
+ ```
332
+
287
333
  #### Contrast primary color
288
334
 
289
335
  If your primary color background requires dark text color, use `--rs-dropdown-menu-contrast-primary` CSS variable.
@@ -352,24 +398,24 @@ render(<Demo />);
352
398
 
353
399
  ##### Demo
354
400
 
355
- Instead of separate classes, it may be a single class with `@media` queries inside:
401
+ Use the controls to see the effect at different viewport widths.
356
402
 
357
403
  ```tsx
358
404
  import { useState } from 'react';
359
405
  import { DropdownMenu, MenuItem } from '@rescui/dropdown-menu';
360
406
  import { Button } from '@rescui/button';
361
407
 
362
- const MyDropdownMenu = ({ className }) => {
408
+ const MyDropdownMenu = () => {
363
409
  const [isOpen, setIsOpen] = useState(false);
364
410
 
365
411
  const toggleIsOpen = () => setIsOpen(s => !s);
366
412
  return (
367
- <div style={{ padding: 12, backgroundColor: 'var(--rs-color-black-t5)' }}>
413
+ <div style={{ height: 350 }}>
368
414
  <DropdownMenu
369
415
  isOpen={isOpen}
370
416
  onRequestClose={() => setIsOpen(false)}
371
417
  trigger={<Button onClick={toggleIsOpen}>Open Menu</Button>}
372
- className={className}
418
+ className="my-dropdown-menu"
373
419
  >
374
420
  <MenuItem>Some text 1</MenuItem>
375
421
  <MenuItem>Some text 2</MenuItem>
@@ -384,34 +430,19 @@ const MyDropdownMenu = ({ className }) => {
384
430
  );
385
431
  };
386
432
 
387
- render(
388
- <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
389
- <div>
390
- <p>Default:</p>
391
- <MyDropdownMenu />
392
- </div>
393
- <div>
394
- <p>Var1:</p>
395
- <MyDropdownMenu className={`my-dropdown-menu-var-1`} />
396
- </div>
397
- <div>
398
- <p>Var1 & Var2 combined:</p>
399
- <MyDropdownMenu
400
- className={`my-dropdown-menu-var-1 my-dropdown-menu-var-2`}
401
- />
402
- </div>
403
- </div>
404
- );
433
+ render(<MyDropdownMenu />);
405
434
  ```
406
435
 
407
436
  ```postcss
408
437
  @import '@rescui/dropdown-menu/lib/public-api.p.css';
409
438
 
410
- .my-dropdown-menu-var-1 {
411
- @mixin rs-dropdown-menu-size-l;
412
- }
413
- .my-dropdown-menu-var-2 {
414
- @mixin rs-dropdown-menu-size-s;
439
+ .my-dropdown-menu {
440
+ @media (max-width: 640px) {
441
+ @mixin rs-dropdown-menu-size-l;
442
+ }
443
+ @media (max-width: 500px) {
444
+ @mixin rs-dropdown-menu-size-s;
445
+ }
415
446
  }
416
447
  ```
417
448
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/dropdown-menu",
3
- "version": "0.11.15-RUI-293-Update-menu-component-7a032357e.20+7a032357e",
3
+ "version": "0.11.15-RUI-293-Update-menu-component-hover-icon-d8a5b0551.33+d8a5b0551",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime-corejs3": "^7.26.0",
20
- "@rescui/dropdown": "0.10.1-RUI-293-Update-menu-component-7a032357e.20+7a032357e",
21
- "@rescui/menu": "0.13.6-RUI-293-Update-menu-component-7a032357e.20+7a032357e",
22
- "@rescui/use-resize-observer": "0.3.1-RUI-293-Update-menu-component-7a032357e.167+7a032357e",
20
+ "@rescui/dropdown": "0.10.1-RUI-293-Update-menu-component-hover-icon-d8a5b0551.33+d8a5b0551",
21
+ "@rescui/menu": "0.13.6-RUI-293-Update-menu-component-hover-icon-d8a5b0551.33+d8a5b0551",
22
+ "@rescui/use-resize-observer": "0.3.1-RUI-293-Update-menu-component-hover-icon-d8a5b0551.180+d8a5b0551",
23
23
  "classnames": "^2.2.6"
24
24
  },
25
25
  "peerDependencies": {
@@ -28,10 +28,10 @@
28
28
  "react": ">=16.8.0 <20"
29
29
  },
30
30
  "devDependencies": {
31
- "@rescui/colors": "0.3.1-RUI-293-Update-menu-component-7a032357e.55+7a032357e",
32
- "@rescui/icons": "1.7.7-RUI-293-Update-menu-component-7a032357e.20+7a032357e",
31
+ "@rescui/colors": "0.3.1-RUI-293-Update-menu-component-hover-icon-d8a5b0551.68+d8a5b0551",
32
+ "@rescui/icons": "1.7.7-RUI-293-Update-menu-component-hover-icon-d8a5b0551.33+d8a5b0551",
33
33
  "@rescui/scripts": "0.5.2",
34
- "@rescui/typography": "0.27.1-RUI-293-Update-menu-component-7a032357e.20+7a032357e",
34
+ "@rescui/typography": "0.27.1-RUI-293-Update-menu-component-hover-icon-d8a5b0551.33+d8a5b0551",
35
35
  "@rescui/visual-regression": "0.1.4"
36
36
  },
37
37
  "scripts": {
@@ -39,5 +39,5 @@
39
39
  "build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
40
40
  },
41
41
  "nx": {},
42
- "gitHead": "7a032357e8f31abbf69e18aa6b7ef2d75e40f42e"
42
+ "gitHead": "d8a5b055167d8b1ea55c32621655b8e0acc98a1a"
43
43
  }