@synerise/ds-operators 0.12.1 → 0.13.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.13.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-operators@0.12.2...@synerise/ds-operators@0.13.0) (2024-09-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * **tabs:** add tooltip prop ([798cd81](https://github.com/Synerise/synerise-design/commit/798cd819be1b2bd55883302da4cb1290278d1919))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.12.2](https://github.com/Synerise/synerise-design/compare/@synerise/ds-operators@0.12.1...@synerise/ds-operators@0.12.2) (2024-09-11)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **factors:** make all dropdowns same fixed height ([40e86d1](https://github.com/Synerise/synerise-design/commit/40e86d183dddb925c2b75c499615c1455b93b7c4))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.12.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-operators@0.12.0...@synerise/ds-operators@0.12.1) (2024-09-03)
7
29
 
8
30
  **Note:** Version bump only for package @synerise/ds-operators
@@ -36,6 +36,11 @@ export type OperatorsProps = {
36
36
  getPopupContainerOverride?: (trigger: HTMLElement | null) => HTMLElement;
37
37
  readOnly?: boolean;
38
38
  errorText?: ReactNode;
39
+ dropdownDimensionsConfig?: {
40
+ defaultHeight?: number;
41
+ lowerHeight?: number;
42
+ threshold?: number;
43
+ };
39
44
  };
40
45
  export type OperatorsDropdownProps = {
41
46
  setDropdownVisible: (show: boolean) => void;
@@ -44,4 +49,5 @@ export type OperatorsDropdownProps = {
44
49
  items: OperatorsItem[];
45
50
  texts: OperatorTexts;
46
51
  value: OperatorsItem | undefined;
52
+ outerHeight?: number;
47
53
  };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { OperatorsProps } from './Operator.types';
3
- declare const Operators: React.FC<OperatorsProps>;
3
+ declare const Operators: ({ value, onChange, groups, items, texts, opened, getPopupContainerOverride, onActivate, onDeactivate, readOnly, errorText, dropdownDimensionsConfig, }: OperatorsProps) => React.JSX.Element;
4
4
  export default Operators;
package/dist/Operators.js CHANGED
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import * as React from 'react';
7
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
8
8
  import { useIntl } from 'react-intl';
9
9
  import Button from '@synerise/ds-button';
10
10
  import { getPopupContainer } from '@synerise/ds-utils';
@@ -13,6 +13,7 @@ import Dropdown from '@synerise/ds-dropdown';
13
13
  import Tooltip from '@synerise/ds-tooltip';
14
14
  import OperatorsDropdown from './OperatorsDropdown/OperatorsDropdown';
15
15
  import * as S from './Operators.style';
16
+ import { DROPDOWN_HEIGHT, DROPDOWN_HEIGHT_BELOW_THRESHOLD, DROPDOWN_HEIGHT_THRESHOLD } from './constants';
16
17
 
17
18
  var Operators = function Operators(_ref) {
18
19
  var value = _ref.value,
@@ -26,16 +27,27 @@ var Operators = function Operators(_ref) {
26
27
  onDeactivate = _ref.onDeactivate,
27
28
  _ref$readOnly = _ref.readOnly,
28
29
  readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
29
- errorText = _ref.errorText;
30
+ errorText = _ref.errorText,
31
+ dropdownDimensionsConfig = _ref.dropdownDimensionsConfig;
32
+
33
+ var dimensionsConfig = _objectSpread({
34
+ defaultHeight: DROPDOWN_HEIGHT,
35
+ lowerHeight: DROPDOWN_HEIGHT_BELOW_THRESHOLD,
36
+ threshold: DROPDOWN_HEIGHT_THRESHOLD
37
+ }, dropdownDimensionsConfig);
30
38
 
31
39
  var _useIntl = useIntl(),
32
40
  formatMessage = _useIntl.formatMessage;
33
41
 
34
- var _React$useState = React.useState(false),
35
- dropdownVisible = _React$useState[0],
36
- setDropdownVisible = _React$useState[1];
42
+ var _useState = useState(false),
43
+ dropdownVisible = _useState[0],
44
+ setDropdownVisible = _useState[1];
45
+
46
+ var _useState2 = useState(dimensionsConfig.defaultHeight),
47
+ outerHeight = _useState2[0],
48
+ setOuterHeight = _useState2[1];
37
49
 
38
- var text = React.useMemo(function () {
50
+ var text = useMemo(function () {
39
51
  return _objectSpread({
40
52
  buttonLabel: formatMessage({
41
53
  id: 'DS.OPERATORS.BUTTON_LABEL',
@@ -51,25 +63,25 @@ var Operators = function Operators(_ref) {
51
63
  })
52
64
  }, texts);
53
65
  }, [texts, formatMessage]);
54
- var handleChange = React.useCallback(function (val) {
66
+ var handleChange = useCallback(function (val) {
55
67
  onChange(val);
56
68
  }, [onChange]);
57
- React.useEffect(function () {
69
+ useEffect(function () {
58
70
  setDropdownVisible(Boolean(opened));
59
71
 
60
72
  if (opened) {
61
73
  onActivate && onActivate();
62
74
  }
63
75
  }, [onActivate, opened]);
64
- var handleClick = React.useCallback(function () {
76
+ var handleClick = useCallback(function () {
65
77
  onActivate && onActivate();
66
78
  setDropdownVisible(true);
67
79
  }, [onActivate]);
68
- var onDropdownVisibilityChange = React.useCallback(function (newValue) {
80
+ var onDropdownVisibilityChange = useCallback(function (newValue) {
69
81
  newValue && onActivate && onActivate();
70
82
  !newValue && onDeactivate && onDeactivate();
71
83
  }, [onActivate, onDeactivate]);
72
- var triggerMode = React.useMemo(function () {
84
+ var triggerMode = useMemo(function () {
73
85
  if (value) {
74
86
  return readOnly ? 'icon-label' : 'two-icons';
75
87
  }
@@ -91,6 +103,17 @@ var Operators = function Operators(_ref) {
91
103
  }), /*#__PURE__*/React.createElement(S.Value, null, value ? value.name : text.buttonLabel), !readOnly && /*#__PURE__*/React.createElement(Icon, {
92
104
  component: /*#__PURE__*/React.createElement(AngleDownS, null)
93
105
  })));
106
+ useEffect(function () {
107
+ var checkViewportHeight = function checkViewportHeight() {
108
+ return setOuterHeight(window.innerHeight < dimensionsConfig.threshold ? dimensionsConfig.lowerHeight : dimensionsConfig.defaultHeight);
109
+ };
110
+
111
+ checkViewportHeight();
112
+ window.addEventListener('resize', checkViewportHeight);
113
+ return function () {
114
+ window.removeEventListener('resize', checkViewportHeight);
115
+ };
116
+ }, [dimensionsConfig.defaultHeight, dimensionsConfig.lowerHeight, dimensionsConfig.threshold]);
94
117
  var content = readOnly ? dropdownTrigger : /*#__PURE__*/React.createElement(Dropdown, {
95
118
  visible: dropdownVisible,
96
119
  onVisibleChange: onDropdownVisibilityChange,
@@ -101,7 +124,8 @@ var Operators = function Operators(_ref) {
101
124
  setSelected: handleChange,
102
125
  groups: groups,
103
126
  items: items,
104
- texts: text
127
+ texts: text,
128
+ outerHeight: outerHeight
105
129
  })
106
130
  }, dropdownTrigger);
107
131
  return content;
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { OperatorsDropdownProps } from '../Operator.types';
3
- declare const OperatorsDropdown: ({ texts, setSelected, groups, items, setDropdownVisible, value, }: OperatorsDropdownProps) => React.JSX.Element;
3
+ declare const OperatorsDropdown: ({ texts, setSelected, groups, items, setDropdownVisible, value, outerHeight, }: OperatorsDropdownProps) => React.JSX.Element;
4
4
  export default OperatorsDropdown;
@@ -10,8 +10,8 @@ import { theme } from '@synerise/ds-core';
10
10
  import OperatorsDropdownItem from './OperatorsDropdownItem';
11
11
  import OperatorsDropdownGroupName from './OperatorsDropdownGroupName';
12
12
  import * as S from '../Operators.style';
13
- import { calculateGroupHeight, groupByGroupName } from '../utils';
14
- import { NO_GROUP_NAME, SCROLLABLE_HEIGHT, TABS_HEIGHT, PADDING, DEFAULT_TAB_INDEX } from '../constants';
13
+ import { groupByGroupName } from '../utils';
14
+ import { NO_GROUP_NAME, DROPDOWN_HEIGHT, TABS_HEIGHT, PADDING, DEFAULT_TAB_INDEX, SEARCH_HEIGHT } from '../constants';
15
15
 
16
16
  var OperatorsDropdown = function OperatorsDropdown(_ref) {
17
17
  var texts = _ref.texts,
@@ -19,7 +19,9 @@ var OperatorsDropdown = function OperatorsDropdown(_ref) {
19
19
  groups = _ref.groups,
20
20
  items = _ref.items,
21
21
  setDropdownVisible = _ref.setDropdownVisible,
22
- value = _ref.value;
22
+ value = _ref.value,
23
+ _ref$outerHeight = _ref.outerHeight,
24
+ outerHeight = _ref$outerHeight === void 0 ? DROPDOWN_HEIGHT : _ref$outerHeight;
23
25
  var overlayRef = useRef(null);
24
26
 
25
27
  var _useState = useState(''),
@@ -102,12 +104,6 @@ var OperatorsDropdown = function OperatorsDropdown(_ref) {
102
104
  });
103
105
  });
104
106
  }, [items, searchQuery, setDropdownVisible, setSelected, value, classNames]);
105
- var maxHeight = useMemo(function () {
106
- return (groups == null ? void 0 : groups.reduce(function (currentMax, group) {
107
- var groupHeight = calculateGroupHeight(group, items);
108
- return Math.max(currentMax, groupHeight);
109
- }, 0)) + 2 * PADDING;
110
- }, [items, groups]);
111
107
  var currentItems = useMemo(function () {
112
108
  if (searchQuery) {
113
109
  return filteredItems;
@@ -147,17 +143,15 @@ var OperatorsDropdown = function OperatorsDropdown(_ref) {
147
143
  var getTabs = useMemo(function () {
148
144
  return (groups == null ? void 0 : groups.map(function (group) {
149
145
  return {
150
- icon: group.icon
146
+ icon: group.icon,
147
+ tooltip: group.tooltip
151
148
  };
152
149
  })) || [];
153
150
  }, [groups]);
154
151
  var hasTabs = getTabs.length > 1;
155
- var lockedTabContentHeight;
156
-
157
- if (hasTabs && maxHeight > 0) {
158
- lockedTabContentHeight = Math.min(maxHeight, SCROLLABLE_HEIGHT) + (searchQuery ? TABS_HEIGHT : 0);
159
- }
160
-
152
+ var dropdownContentHeight = useMemo(function () {
153
+ return outerHeight - (!searchQuery && hasTabs ? TABS_HEIGHT : 0) - SEARCH_HEIGHT;
154
+ }, [hasTabs, searchQuery, outerHeight]);
161
155
  return /*#__PURE__*/React.createElement(Dropdown.Wrapper, {
162
156
  "data-testid": "ds-operators-dropdown-wrapper",
163
157
  style: {
@@ -194,10 +188,10 @@ var OperatorsDropdown = function OperatorsDropdown(_ref) {
194
188
  setActiveGroup(undefined);
195
189
  }
196
190
  })), /*#__PURE__*/React.createElement(S.ItemsList, {
197
- contentHeight: lockedTabContentHeight
191
+ contentHeight: dropdownContentHeight
198
192
  }, /*#__PURE__*/React.createElement(Scrollbar, {
199
193
  absolute: true,
200
- maxHeight: lockedTabContentHeight,
194
+ maxHeight: dropdownContentHeight,
201
195
  style: {
202
196
  padding: PADDING
203
197
  }
@@ -1,6 +1,8 @@
1
1
  export declare const NO_GROUP_NAME = "NO_GROUP_NAME";
2
- export declare const SCROLLABLE_HEIGHT = 304;
3
- export declare const ITEM_HEIGHT = 32;
2
+ export declare const DROPDOWN_HEIGHT = 420;
3
+ export declare const DROPDOWN_HEIGHT_BELOW_THRESHOLD = 350;
4
+ export declare const DROPDOWN_HEIGHT_THRESHOLD = 900;
5
+ export declare const SEARCH_HEIGHT = 53;
4
6
  export declare const TABS_HEIGHT = 50;
5
7
  export declare const PADDING = 8;
6
8
  export declare const DEFAULT_TAB_INDEX = 0;
package/dist/constants.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export var NO_GROUP_NAME = 'NO_GROUP_NAME';
2
- export var SCROLLABLE_HEIGHT = 304;
3
- export var ITEM_HEIGHT = 32;
2
+ export var DROPDOWN_HEIGHT = 420;
3
+ export var DROPDOWN_HEIGHT_BELOW_THRESHOLD = 350;
4
+ export var DROPDOWN_HEIGHT_THRESHOLD = 900;
5
+ export var SEARCH_HEIGHT = 53;
4
6
  export var TABS_HEIGHT = 50;
5
7
  export var PADDING = 8;
6
8
  export var DEFAULT_TAB_INDEX = 0;
@@ -1,2 +1 @@
1
- export * from './calculateGroupHeight';
2
1
  export * from './groupByGroupName';
@@ -1,2 +1 @@
1
- export * from './calculateGroupHeight';
2
1
  export * from './groupByGroupName';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-operators",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "description": "Operators UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,15 +33,15 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-button": "^0.21.8",
37
- "@synerise/ds-dropdown": "^0.18.12",
38
- "@synerise/ds-icon": "^0.65.3",
39
- "@synerise/ds-list-item": "^0.4.8",
40
- "@synerise/ds-result": "^0.7.2",
41
- "@synerise/ds-scrollbar": "^0.11.8",
42
- "@synerise/ds-tabs": "^0.15.5",
43
- "@synerise/ds-tooltip": "^0.14.38",
44
- "@synerise/ds-utils": "^0.29.0",
36
+ "@synerise/ds-button": "^0.21.10",
37
+ "@synerise/ds-dropdown": "^0.18.14",
38
+ "@synerise/ds-icon": "^0.65.5",
39
+ "@synerise/ds-list-item": "^0.4.10",
40
+ "@synerise/ds-result": "^0.7.4",
41
+ "@synerise/ds-scrollbar": "^0.11.10",
42
+ "@synerise/ds-tabs": "^0.16.0",
43
+ "@synerise/ds-tooltip": "^0.14.40",
44
+ "@synerise/ds-utils": "^0.29.2",
45
45
  "react-intl": "3.12.0",
46
46
  "uuid": "^8.3.2"
47
47
  },
@@ -50,5 +50,5 @@
50
50
  "react": ">=16.9.0 <= 17.0.2",
51
51
  "styled-components": "5.0.1"
52
52
  },
53
- "gitHead": "6fe94d574f25c5267c7593dec9399527f441b23a"
53
+ "gitHead": "6f3231e4a9e0720ffee61b748488cecd590da6e6"
54
54
  }
@@ -1,2 +0,0 @@
1
- import { OperatorsGroup, OperatorsItem } from '../Operator.types';
2
- export declare const calculateGroupHeight: (group: OperatorsGroup, allItems: OperatorsItem[]) => number;
@@ -1,16 +0,0 @@
1
- import { ITEM_HEIGHT } from '../constants';
2
- export var calculateGroupHeight = function calculateGroupHeight(group, allItems) {
3
- if (group.subGroups) {
4
- var _group$subGroups;
5
-
6
- return ((_group$subGroups = group.subGroups) == null ? void 0 : _group$subGroups.length) * ITEM_HEIGHT;
7
- }
8
-
9
- var groupItems = allItems.filter(function (item) {
10
- return item.groupId === group.id;
11
- });
12
- var groupNames = new Set(groupItems.map(function (item) {
13
- return item.groupName;
14
- }).filter(Boolean));
15
- return (groupItems.length + groupNames.size) * ITEM_HEIGHT;
16
- };
@@ -1 +0,0 @@
1
- export {};