@rescui/dropdown-menu 0.7.0 → 0.8.1

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.
@@ -6,6 +6,7 @@ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
6
6
  import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
7
7
  import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
8
8
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
9
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
9
10
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
10
11
  var _excluded = ["maxVisibleItems", "size", "children", "iconPlacement", "itemTag", "tag", "theme", "mode", "activateFirstItemOnOpen", "wrapItemsWithLi"],
11
12
  _excluded2 = ["maxHeight", "leastMaxHeight"];
@@ -14,10 +15,11 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
14
15
 
15
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
16
17
 
17
- import React from 'react';
18
+ import React, { useState } from 'react';
18
19
  import { useTheme, getInverseTheme } from '@rescui/ui-contexts';
19
20
  import { Dropdown } from '@rescui/dropdown';
20
21
  import { Menu } from '@rescui/menu';
22
+ import { HeightObserver } from './height-observer.js';
21
23
  import styles from './index.p.module.css.js';
22
24
  var ITEM_HEIGHT_BY_SIZE = {
23
25
  s: 32,
@@ -47,9 +49,18 @@ var DropdownMenu = function DropdownMenu(_ref) {
47
49
  wrapItemsWithLi = _ref.wrapItemsWithLi,
48
50
  restProps = _objectWithoutProperties(_ref, _excluded);
49
51
 
50
- var itemHeight = ITEM_HEIGHT_BY_SIZE[size]; // half of item added to show that there is more items even if scroll bar hidden
52
+ var itemHeight = ITEM_HEIGHT_BY_SIZE[size];
51
53
 
52
- var maxHeight = (Math.ceil(maxVisibleItems) + 0.5) * itemHeight;
54
+ var _useState = useState(0),
55
+ _useState2 = _slicedToArray(_useState, 2),
56
+ height = _useState2[0],
57
+ setHeight = _useState2[1]; // a little buffer of 10% here
58
+
59
+
60
+ var isMoreThanPlusOne = height > (Math.ceil(maxVisibleItems) + 1.1) * itemHeight; // half of item added to show that there is more items even if scroll bar hidden
61
+ // in case there are only 1 more item than maxVisibleItems, show it without truncating
62
+
63
+ var maxHeight = (Math.ceil(maxVisibleItems) + (isMoreThanPlusOne ? 0.5 : 1.5)) * itemHeight;
53
64
 
54
65
  var cleanMaxHeight = restProps.maxHeight,
55
66
  leastMaxHeight = restProps.leastMaxHeight,
@@ -64,7 +75,9 @@ var DropdownMenu = function DropdownMenu(_ref) {
64
75
  leastMaxHeight: itemHeight,
65
76
  maxHeight: maxHeight,
66
77
  className: SIZE_TO_CLASS[size]
67
- }), /*#__PURE__*/React.createElement(Menu, {
78
+ }), /*#__PURE__*/React.createElement(HeightObserver, {
79
+ onHeightUpdate: setHeight
80
+ }, /*#__PURE__*/React.createElement(Menu, {
68
81
  size: size,
69
82
  iconPlacement: iconPlacement,
70
83
  itemTag: itemTag,
@@ -77,7 +90,7 @@ var DropdownMenu = function DropdownMenu(_ref) {
77
90
  returnFocusOnUnmount: true,
78
91
  activateFirstItem: activateFirstItemOnOpen,
79
92
  wrapItemsWithLi: wrapItemsWithLi
80
- }, children));
93
+ }, children)));
81
94
  };
82
95
 
83
96
  export { DropdownMenu, DropdownMenu as default };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export declare type HeightObserverProps = {
3
+ children?: React.ReactNode;
4
+ onHeightUpdate?: (newHeight: number) => void;
5
+ };
6
+ export declare const HeightObserver: React.FC<HeightObserverProps>;
@@ -0,0 +1,16 @@
1
+ import React, { useRef } from 'react';
2
+ import { useResizeObserver } from '@rescui/use-resize-observer';
3
+
4
+ var HeightObserver = function HeightObserver(_ref) {
5
+ var children = _ref.children,
6
+ onHeightUpdate = _ref.onHeightUpdate;
7
+ var ref = useRef(null);
8
+ useResizeObserver(ref, function (entry) {
9
+ return onHeightUpdate(entry.target.offsetHeight);
10
+ });
11
+ return /*#__PURE__*/React.createElement("div", {
12
+ ref: ref
13
+ }, children);
14
+ };
15
+
16
+ export { HeightObserver };
package/lib/index.css CHANGED
@@ -1,15 +1,15 @@
1
- ._sizeS_1b6ux3g_8{
1
+ ._sizeS_1cepn01_8{
2
2
  min-width:316px;
3
3
  max-width:389px;
4
4
  }
5
5
 
6
- ._sizeL_1b6ux3g_13,
7
- ._sizeM_1b6ux3g_14{
6
+ ._sizeL_1cepn01_13,
7
+ ._sizeM_1cepn01_14{
8
8
  min-width:316px;
9
9
  max-width:494px;
10
10
  }
11
11
 
12
- ._menu_1b6ux3g_19{
12
+ ._menu_1cepn01_19{
13
13
  margin:0;
14
14
  padding:0;
15
15
  list-style:none;
@@ -1,7 +1,7 @@
1
1
  var styles = {
2
- "sizeS": "_sizeS_1b6ux3g_8",
3
- "sizeL": "_sizeL_1b6ux3g_13",
4
- "sizeM": "_sizeM_1b6ux3g_14",
5
- "menu": "_menu_1b6ux3g_19"
2
+ "sizeS": "_sizeS_1cepn01_8",
3
+ "sizeL": "_sizeL_1cepn01_13",
4
+ "sizeM": "_sizeM_1cepn01_14",
5
+ "menu": "_menu_1cepn01_19"
6
6
  };
7
7
  export { styles as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/dropdown-menu",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -15,8 +15,9 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@babel/runtime-corejs3": "^7.11.0",
18
- "@rescui/dropdown": "^0.6.0",
19
- "@rescui/menu": "^0.9.4",
18
+ "@rescui/dropdown": "^0.6.1",
19
+ "@rescui/menu": "^0.9.5",
20
+ "@rescui/use-resize-observer": "^0.1.6",
20
21
  "classnames": "^2.2.6",
21
22
  "core-js": "^3.9.1"
22
23
  },
@@ -28,11 +29,11 @@
28
29
  "devDependencies": {
29
30
  "@rescui/colors": "^0.1.9",
30
31
  "@rescui/scripts": "^0.2.2",
31
- "@rescui/typography": "^0.11.0",
32
+ "@rescui/typography": "^0.12.0",
32
33
  "@rescui/visual-regression": "^0.1.0"
33
34
  },
34
35
  "scripts": {
35
36
  "build": "rescui-scripts build"
36
37
  },
37
- "gitHead": "2a57f292fde136628c5ed31a9da9149fd41d404f"
38
+ "gitHead": "5b8028f2a39036c58de3bfcba424df687b540f55"
38
39
  }