@semcore/select 16.1.12 → 17.0.0-prerelease.18

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/lib/es6/Select.js CHANGED
@@ -1,12 +1,4 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
1
  import _extends from "@babel/runtime/helpers/extends";
3
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
5
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
6
- import _createClass from "@babel/runtime/helpers/createClass";
7
- import _callSuper from "@babel/runtime/helpers/callSuper";
8
- import _superPropGet from "@babel/runtime/helpers/superPropGet";
9
- import _inherits from "@babel/runtime/helpers/inherits";
10
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
3
  import { sstyled as _sstyled } from "@semcore/core";
12
4
  import { assignProps as _assignProps6 } from "@semcore/core";
@@ -15,8 +7,7 @@ import { assignProps as _assignProps4 } from "@semcore/core";
15
7
  import { assignProps as _assignProps3 } from "@semcore/core";
16
8
  import { assignProps as _assignProps2 } from "@semcore/core";
17
9
  import { assignProps as _assignProps } from "@semcore/core";
18
- var _excluded = ["Children", "options", "multiselect", "value", "uid", "forcedAdvancedMode"];
19
- import { hideScrollBarsFromScreenReadersContext } from '@semcore/base-components';
10
+ import { hideScrollBarsFromScreenReadersContext, useBox, isInputTriggerTag } from '@semcore/base-components';
20
11
  import { ButtonTrigger } from '@semcore/base-trigger';
21
12
  import { createComponent, Root, sstyled, lastInteraction } from '@semcore/core';
22
13
  import addonTextChildren from '@semcore/core/lib/utils/addonTextChildren';
@@ -27,23 +18,22 @@ import logger from '@semcore/core/lib/utils/logger';
27
18
  import Divider from '@semcore/divider';
28
19
  import Dropdown, { AbstractDropdown, enhance, selectedIndexContext } from '@semcore/dropdown';
29
20
  import DropdownMenu from '@semcore/dropdown-menu';
30
- import { useBox } from '@semcore/flex-box';
31
- import { isInputTriggerTag } from '@semcore/popper';
21
+ import { Text } from '@semcore/typography';
32
22
  import cn from 'classnames';
33
23
  import React from 'react';
34
24
  import { selectContext } from './context';
35
25
  import InputSearch from './InputSearch';
36
26
  /*!__reshadow-styles__:"./style/select.shadow.css"*/
37
- var style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SOptionCheckbox_1hlru_gg_{margin-top:var(--intergalactic-spacing-05x, 2px);margin-right:var(--intergalactic-spacing-2x, 8px);margin-bottom:auto;position:relative;flex-shrink:0;width:16px;height:16px}.___SOptionCheckbox_1hlru_gg_::before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:var(--intergalactic-bg-primary-neutral, #ffffff);border:1px solid;border-radius:var(--intergalactic-addon-rounded, 4px);border-color:var(--intergalactic-border-primary, #c4c7cf)}.___SOptionCheckbox_1hlru_gg_::after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:0 var(--intergalactic-spacing-05x, 2px);background-repeat:no-repeat;background-position:center center}.___SOptionCheckbox_1hlru_gg_.__selected_1hlru_gg_::after{background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNyIgdmlld0JveD0iMCAwIDEwIDciIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik04LjI1IDFMNCA1LjI1TDEuNzUgMyIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==)}.___SOptionCheckbox_1hlru_gg_._size_l_1hlru_gg_{width:20px;height:20px}.___SOptionCheckbox_1hlru_gg_._size_l_1hlru_gg_.__selected_1hlru_gg_::after{background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEyIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xMSAxLjVMNC43NSA3Ljc1TDEgNCIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==)}.___SOptionCheckbox_1hlru_gg_.__indeterminate_1hlru_gg_:before,.___SOptionCheckbox_1hlru_gg_.__selected_1hlru_gg_:before{background-color:var(--intergalactic-control-primary-info, #008ff8);border-color:var(--intergalactic-control-primary-info, #008ff8)}.___SOptionCheckbox_1hlru_gg_.__theme_1hlru_gg_:before{border-color:var(--theme_1hlru)}.___SOptionCheckbox_1hlru_gg_.__theme_1hlru_gg_.__indeterminate_1hlru_gg_:before,.___SOptionCheckbox_1hlru_gg_.__theme_1hlru_gg_.__selected_1hlru_gg_:before{background-color:var(--theme_1hlru);border-color:var(--theme_1hlru)}.___SOptionCheckbox_1hlru_gg_.__selected_1hlru_gg_{background-color:var(--intergalactic-dropdown-menu-item-selected, rgba(196, 229, 254, 0.7))}@media (hover:hover){.___SOptionCheckbox_1hlru_gg_.__selected_1hlru_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-selected-hover, #c4e5fe)}}.___SOptionCheckbox_1hlru_gg_.__indeterminate_1hlru_gg_:after{background-color:#fff;background-image:none;margin:auto;border-radius:1px}.___SOptionCheckbox_1hlru_gg_.__indeterminate_1hlru_gg_._size_l_1hlru_gg_:after{width:12px;height:2px}.___SOptionCheckbox_1hlru_gg_.__indeterminate_1hlru_gg_._size_m_1hlru_gg_:after{width:8px;height:2px}", /*__inner_css_end__*/"1hlru_gg_"),
27
+ const style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SOptionCheckbox_ggett_gg_{margin-top:var(--intergalactic-spacing-05x, 2px);margin-right:var(--intergalactic-spacing-2x, 8px);margin-bottom:auto;position:relative;flex-shrink:0;width:16px;height:16px}.___SOptionCheckbox_ggett_gg_::before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:var(--intergalactic-bg-primary-neutral, #ffffff);border:1px solid;border-radius:var(--intergalactic-addon-rounded, 4px);border-color:var(--intergalactic-border-primary, #c4c7cf)}.___SOptionCheckbox_ggett_gg_::after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:0 var(--intergalactic-spacing-05x, 2px);background-repeat:no-repeat;background-position:center center}.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_::after{background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNyIgdmlld0JveD0iMCAwIDEwIDciIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik04LjI1IDFMNCA1LjI1TDEuNzUgMyIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==)}.___SOptionCheckbox_ggett_gg_._size_l_ggett_gg_{width:20px;height:20px}.___SOptionCheckbox_ggett_gg_._size_l_ggett_gg_.__selected_ggett_gg_::after{background-image:url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEyIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xMSAxLjVMNC43NSA3Ljc1TDEgNCIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==)}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_:before,.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_:before{background-color:var(--intergalactic-control-primary-info, #008ff8);border-color:var(--intergalactic-control-primary-info, #008ff8)}.___SOptionCheckbox_ggett_gg_.__theme_ggett_gg_:before{border-color:var(--theme_ggett)}.___SOptionCheckbox_ggett_gg_.__theme_ggett_gg_.__indeterminate_ggett_gg_:before,.___SOptionCheckbox_ggett_gg_.__theme_ggett_gg_.__selected_ggett_gg_:before{background-color:var(--theme_ggett);border-color:var(--theme_ggett)}.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_{background-color:var(--intergalactic-dropdown-menu-item-selected, rgba(196, 229, 254, 0.7))}@media (hover:hover){.___SOptionCheckbox_ggett_gg_.__selected_ggett_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-selected-hover, #c4e5fe)}}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_:after{background-color:#fff;background-image:none;margin:auto;border-radius:1px}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_._size_l_ggett_gg_:after{width:12px;height:2px}.___SOptionCheckbox_ggett_gg_.__indeterminate_ggett_gg_._size_m_ggett_gg_:after{width:8px;height:2px}", /*__inner_css_end__*/"ggett_gg_"),
38
28
  /*__reshadow_css_end__*/
39
29
  {
40
- "__SOptionCheckbox": "___SOptionCheckbox_1hlru_gg_",
41
- "_selected": "__selected_1hlru_gg_",
42
- "_size_l": "_size_l_1hlru_gg_",
43
- "_indeterminate": "__indeterminate_1hlru_gg_",
44
- "_theme": "__theme_1hlru_gg_",
45
- "--theme": "--theme_1hlru",
46
- "_size_m": "_size_m_1hlru_gg_"
30
+ "__SOptionCheckbox": "___SOptionCheckbox_ggett_gg_",
31
+ "_selected": "__selected_ggett_gg_",
32
+ "_size_l": "_size_l_ggett_gg_",
33
+ "_indeterminate": "__indeterminate_ggett_gg_",
34
+ "_theme": "__theme_ggett_gg_",
35
+ "--theme": "--theme_ggett",
36
+ "_size_m": "_size_m_ggett_gg_"
47
37
  });
48
38
  import { localizedMessages } from './translations/__intergalactic-dynamic-locales';
49
39
  function isSelectedOption(value, valueOption) {
@@ -55,297 +45,271 @@ function isEmptyValue(value) {
55
45
  function getEmptyValue(multiselect) {
56
46
  return multiselect ? [] : null;
57
47
  }
58
- var ListBoxContextProvider = function ListBoxContextProvider(_ref9) {
59
- var children = _ref9.children;
60
- return /*#__PURE__*/React.createElement(hideScrollBarsFromScreenReadersContext.Provider, {
61
- value: true
62
- }, children);
63
- };
64
- var RootSelect = /*#__PURE__*/function (_AbstractDropdown) {
65
- function RootSelect() {
66
- var _this;
67
- _classCallCheck(this, RootSelect);
68
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
69
- args[_key] = arguments[_key];
70
- }
71
- _this = _callSuper(this, RootSelect, [].concat(args));
72
- _defineProperty(_this, "role", 'listbox');
73
- _defineProperty(_this, "bindHandlerOptionClick", function (optionValue, index) {
74
- return function (e) {
75
- var newValue = optionValue;
76
- var _this$asProps = _this.asProps,
77
- value = _this$asProps.value,
78
- multiselect = _this$asProps.multiselect;
79
- if (Array.isArray(value)) {
80
- if (value.includes(optionValue)) {
81
- newValue = value.filter(function (v) {
82
- return v !== optionValue;
83
- });
84
- } else {
85
- newValue = value.concat(optionValue);
86
- }
48
+ const ListBoxContextProvider = ({
49
+ children
50
+ }) => /*#__PURE__*/React.createElement(hideScrollBarsFromScreenReadersContext.Provider, {
51
+ value: true
52
+ }, children);
53
+ class RootSelect extends AbstractDropdown {
54
+ constructor(...args) {
55
+ super(...args);
56
+ _defineProperty(this, "role", 'listbox');
57
+ _defineProperty(this, "bindHandlerOptionClick", (optionValue, index) => e => {
58
+ let newValue = optionValue;
59
+ const {
60
+ value,
61
+ multiselect
62
+ } = this.asProps;
63
+ if (Array.isArray(value)) {
64
+ if (value.includes(optionValue)) {
65
+ newValue = value.filter(v => v !== optionValue);
66
+ } else {
67
+ newValue = value.concat(optionValue);
87
68
  }
88
- _this.handlers.highlightedIndex(index);
89
- _this.handlers.value(newValue, e);
90
- if (!multiselect) {
91
- _this.handlers.visible(false);
92
- e.preventDefault();
93
- }
94
- };
69
+ }
70
+ this.handlers.highlightedIndex(index);
71
+ this.handlers.value(newValue, e);
72
+ if (!multiselect) {
73
+ this.handlers.visible(false);
74
+ e.preventDefault();
75
+ }
95
76
  });
96
- _defineProperty(_this, "handlerClear", function (e) {
97
- var value = _this.asProps.value;
98
- var emptyValue = getEmptyValue(Array.isArray(value));
99
- _this.handlers.value(emptyValue, e);
100
- _this.handlers.visible(false);
77
+ _defineProperty(this, "handlerClear", e => {
78
+ const {
79
+ value
80
+ } = this.asProps;
81
+ const emptyValue = getEmptyValue(Array.isArray(value));
82
+ this.handlers.value(emptyValue, e);
83
+ this.handlers.visible(false);
101
84
  });
102
- return _this;
103
85
  }
104
- _inherits(RootSelect, _AbstractDropdown);
105
- return _createClass(RootSelect, [{
106
- key: "itemRef",
107
- value: function itemRef(props, index, node) {
108
- _superPropGet(RootSelect, "itemRef", this, 3)([props, index, node]);
109
- var highlightedIndex = this.asProps.highlightedIndex;
110
- var isHighlighted = index === highlightedIndex;
111
- if (isHighlighted) {
112
- this.scrollToNode(node);
113
- }
86
+ itemRef(props, index, node) {
87
+ super.itemRef(props, index, node);
88
+ const {
89
+ highlightedIndex
90
+ } = this.asProps;
91
+ const isHighlighted = index === highlightedIndex;
92
+ if (isHighlighted) {
93
+ this.scrollToNode(node);
114
94
  }
115
- }, {
116
- key: "uncontrolledProps",
117
- value: function uncontrolledProps() {
118
- var _this2 = this;
119
- return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "uncontrolledProps", this, 3)([])), {}, {
120
- visible: [null, function (visible) {
121
- if (visible === true) {
122
- var hasInputSearch = isAdvanceMode(_this2.asProps.Children, [Select.InputSearch.displayName, InputSearch.displayName], true);
123
- var defaultIndex = hasInputSearch || lastInteraction.isMouse() ? null : _this2.props.defaultHighlightedIndex;
124
- _this2.handlers.highlightedIndex(defaultIndex);
125
- setTimeout(function () {
126
- var _this2$menuRef$curren, _this2$menuRef$curren2;
127
- var options = (_this2$menuRef$curren = _this2.menuRef.current) === null || _this2$menuRef$curren === void 0 ? void 0 : _this2$menuRef$curren.querySelectorAll('[role="option"]');
128
- var selected = (_this2$menuRef$curren2 = _this2.menuRef.current) === null || _this2$menuRef$curren2 === void 0 ? void 0 : _this2$menuRef$curren2.querySelector('[aria-selected="true"]');
129
- if (selected && options) {
130
- _this2.scrollToNode(selected);
131
- for (var i = 0; i < options.length; i++) {
132
- if (options[i] === selected) {
133
- _this2.handlers.highlightedIndex(i);
134
- break;
135
- }
95
+ }
96
+ uncontrolledProps() {
97
+ return {
98
+ ...super.uncontrolledProps(),
99
+ visible: [null, visible => {
100
+ if (visible === true) {
101
+ const hasInputSearch = isAdvanceMode(this.asProps.Children, [Select.InputSearch.displayName, InputSearch.displayName], true);
102
+ const defaultIndex = hasInputSearch || lastInteraction.isMouse() ? null : this.props.defaultHighlightedIndex;
103
+ this.handlers.highlightedIndex(defaultIndex);
104
+ setTimeout(() => {
105
+ const options = this.menuRef.current?.querySelectorAll('[role="option"]');
106
+ const selected = this.menuRef.current?.querySelector('[aria-selected="true"]');
107
+ if (selected && options) {
108
+ this.scrollToNode(selected);
109
+ for (let i = 0; i < options.length; i++) {
110
+ if (options[i] === selected) {
111
+ this.handlers.highlightedIndex(i);
112
+ break;
136
113
  }
137
114
  }
138
- // for some reason, Google Chrome optimizes this timeout with 0 value with previous render (when we set aria-selected)
139
- // and that's why its skip scrollToNodes. We selected the appropriate timeout manually.
140
- }, 30);
141
- }
142
- }],
143
- value: null
144
- });
145
- }
146
- }, {
147
- key: "getTriggerProps",
148
- value: function getTriggerProps() {
149
- var _this3 = this;
150
- var _this$asProps2 = this.asProps,
151
- disabled = _this$asProps2.disabled,
152
- visible = _this$asProps2.visible,
153
- state = _this$asProps2.state,
154
- placeholder = _this$asProps2.placeholder,
155
- value = _this$asProps2.value,
156
- options = _this$asProps2.options,
157
- forwardRef = _this$asProps2.forwardRef,
158
- name = _this$asProps2.name,
159
- multiselect = _this$asProps2.multiselect,
160
- getI18nText = _this$asProps2.getI18nText,
161
- highlightedIndex = _this$asProps2.highlightedIndex,
162
- uid = _this$asProps2.uid,
163
- Children = _this$asProps2.Children,
164
- hasChildren = _this$asProps2.children;
165
- var isMenu = isAdvanceMode(Children, [Select.Menu.displayName], true) || !hasChildren;
166
- var ariaControls = isMenu ? "igc-".concat(uid, "-list") : "igc-".concat(uid, "-popper");
167
- return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getTriggerProps", this, 3)([])), {}, {
168
- 'onKeyDown': callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handleOpenKeyDown.bind(this), this.handleArrowKeyDown.bind(this)),
169
- 'aria-controls': visible ? ariaControls : undefined,
170
- 'aria-haspopup': isMenu ? 'listbox' : 'dialog',
171
- 'aria-disabled': disabled ? 'true' : 'false',
172
- 'aria-activedescendant': visible && highlightedIndex !== null && this.itemRefs[highlightedIndex] ? "igc-".concat(uid, "-option-").concat(highlightedIndex) : undefined,
173
- 'empty': isEmptyValue(value),
174
- value: value,
175
- name: name,
176
- '$hiddenRef': forwardRef,
177
- multiselect: multiselect,
178
- state: state,
179
- placeholder: placeholder,
180
- disabled: disabled,
181
- 'active': visible,
182
- 'onClear': this.handlerClear,
183
- 'children': this.renderChildrenTrigger(value, options),
184
- getI18nText: getI18nText,
185
- 'onBlur': function onBlur() {
186
- // if popper is opened and we moved from the trigger in select - it means we moved on some controls in popper and should hide highlighted for the option
187
- if (_this3.asProps.visible) {
188
- _this3.prevHighlightedIndex = _this3.asProps.highlightedIndex;
189
- _this3.handlers.highlightedIndex(null);
190
- }
191
- },
192
- 'onFocus': function onFocus() {
193
- // if popper is opened and we moved to the trigger in select - it means we moved from some controls in popper and should highlight the last highlighted option
194
- if (_this3.asProps.visible) {
195
- var index = _this3.prevHighlightedIndex;
196
- _this3.handlers.highlightedIndex(index);
197
- }
115
+ }
116
+ // for some reason, Google Chrome optimizes this timeout with 0 value with previous render (when we set aria-selected)
117
+ // and that's why its skip scrollToNodes. We selected the appropriate timeout manually.
118
+ }, 30);
119
+ }
120
+ }],
121
+ value: null
122
+ };
123
+ }
124
+ getTriggerProps() {
125
+ const {
126
+ disabled,
127
+ visible,
128
+ state,
129
+ placeholder,
130
+ value,
131
+ options,
132
+ forwardRef,
133
+ name,
134
+ multiselect,
135
+ getI18nText,
136
+ highlightedIndex,
137
+ uid,
138
+ Children,
139
+ children: hasChildren
140
+ } = this.asProps;
141
+ const isMenu = isAdvanceMode(Children, [Select.Menu.displayName], true) || !hasChildren;
142
+ const ariaControls = isMenu ? `igc-${uid}-list` : `igc-${uid}-popper`;
143
+ return {
144
+ ...super.getTriggerProps(),
145
+ 'onKeyDown': callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handleOpenKeyDown.bind(this), this.handleArrowKeyDown.bind(this)),
146
+ 'aria-controls': visible ? ariaControls : undefined,
147
+ 'aria-haspopup': isMenu ? 'listbox' : 'dialog',
148
+ 'aria-disabled': disabled ? 'true' : 'false',
149
+ 'aria-activedescendant': visible && highlightedIndex !== null && this.itemRefs[highlightedIndex] ? `igc-${uid}-option-${highlightedIndex}` : undefined,
150
+ 'empty': isEmptyValue(value),
151
+ value,
152
+ name,
153
+ '$hiddenRef': forwardRef,
154
+ multiselect,
155
+ state,
156
+ placeholder,
157
+ disabled,
158
+ 'active': visible,
159
+ 'onClear': this.handlerClear,
160
+ 'children': this.renderChildrenTrigger(value, options),
161
+ getI18nText,
162
+ 'onBlur': () => {
163
+ // if popper is opened and we moved from the trigger in select - it means we moved on some controls in popper and should hide highlighted for the option
164
+ if (this.asProps.visible) {
165
+ this.prevHighlightedIndex = this.asProps.highlightedIndex;
166
+ this.handlers.highlightedIndex(null);
167
+ }
168
+ },
169
+ 'onFocus': () => {
170
+ // if popper is opened and we moved to the trigger in select - it means we moved from some controls in popper and should highlight the last highlighted option
171
+ if (this.asProps.visible) {
172
+ const index = this.prevHighlightedIndex;
173
+ this.handlers.highlightedIndex(index);
198
174
  }
199
- });
200
- }
201
- }, {
202
- key: "getListProps",
203
- value: function getListProps() {
204
- var multiselect = this.asProps.multiselect;
205
- return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getListProps", this, 3)([])), {}, {
206
- 'aria-multiselectable': multiselect ? 'true' : undefined
207
- });
208
- }
209
- }, {
210
- key: "getPopperProps",
211
- value: function getPopperProps() {
212
- return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getPopperProps", this, 3)([])), {}, {
213
- onKeyDown: callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handlePreventPopperKeyDown.bind(this), this.handleArrowKeyDown.bind(this))
214
- });
215
- }
216
- }, {
217
- key: "getOptionProps",
218
- value: function getOptionProps(props, index) {
219
- var _props$selected,
220
- _this4 = this;
221
- var _this$asProps3 = this.asProps,
222
- value = _this$asProps3.value,
223
- highlightedIndex = _this$asProps3.highlightedIndex,
224
- _this$asProps3$size = _this$asProps3.size,
225
- size = _this$asProps3$size === void 0 ? 'm' : _this$asProps3$size;
226
- var highlighted = index === highlightedIndex && lastInteraction.isKeyboard() && !props.disabled;
227
- var selected = (_props$selected = props.selected) !== null && _props$selected !== void 0 ? _props$selected : isSelectedOption(value, props.value);
228
- return _objectSpread(_objectSpread({}, _superPropGet(RootSelect, "getItemProps", this, 3)([props, index])), {}, {
229
- highlighted: highlighted,
230
- selected: selected,
231
- 'aria-selected': selected ? 'true' : 'false',
232
- 'aria-disabled': props.disabled ? 'true' : 'false',
233
- 'role': 'option',
234
- 'onClick': this.bindHandlerOptionClick(props.value, index),
235
- 'ref': function ref(node) {
236
- return _this4.itemRef(props, index, node);
237
- },
238
- size: size
239
- });
240
- }
241
- }, {
242
- key: "getOptionCheckboxProps",
243
- value: function getOptionCheckboxProps() {
244
- var _this$asProps4 = this.asProps,
245
- size = _this$asProps4.size,
246
- resolveColor = _this$asProps4.resolveColor;
247
- return {
248
- size: size,
249
- resolveColor: resolveColor
250
- };
251
- }
252
- }, {
253
- key: "getDividerProps",
254
- value: function getDividerProps() {
255
- return {
256
- 'my': 1,
257
- 'aria-disabled': 'true'
258
- };
259
- }
260
- }, {
261
- key: "renderChildrenTrigger",
262
- value: function renderChildrenTrigger(value, options) {
263
- if (options) {
264
- return [].concat(value).reduce(function (acc, value) {
265
- var selectedOption = options.find(function (o) {
266
- return isSelectedOption(value, o.value);
267
- });
268
- if (!selectedOption) return acc;
269
- if (acc.length) acc.push(', ');
270
- acc.push(selectedOption.label || selectedOption.value);
271
- return acc;
272
- }, []);
273
175
  }
274
- return Array.isArray(value) ? value.reduce(function (acc, value) {
176
+ };
177
+ }
178
+ getListProps() {
179
+ const {
180
+ multiselect
181
+ } = this.asProps;
182
+ return {
183
+ ...super.getListProps(),
184
+ 'aria-multiselectable': multiselect ? 'true' : undefined
185
+ };
186
+ }
187
+ getPopperProps() {
188
+ return {
189
+ ...super.getPopperProps(),
190
+ onKeyDown: callAllEventHandlers(this.handlePreventCommonKeyDown.bind(this), this.handlePreventPopperKeyDown.bind(this), this.handleArrowKeyDown.bind(this))
191
+ };
192
+ }
193
+ getOptionProps(props, index) {
194
+ const {
195
+ value,
196
+ highlightedIndex,
197
+ size = 'm'
198
+ } = this.asProps;
199
+ const highlighted = index === highlightedIndex && lastInteraction.isKeyboard() && !props.disabled;
200
+ const selected = props.selected ?? isSelectedOption(value, props.value);
201
+ return {
202
+ ...super.getItemProps(props, index),
203
+ highlighted,
204
+ selected,
205
+ 'aria-selected': selected ? 'true' : 'false',
206
+ 'aria-disabled': props.disabled ? 'true' : 'false',
207
+ 'role': 'option',
208
+ 'onClick': this.bindHandlerOptionClick(props.value, index),
209
+ 'ref': node => this.itemRef(props, index, node),
210
+ size
211
+ };
212
+ }
213
+ getOptionCheckboxProps() {
214
+ const {
215
+ size,
216
+ resolveColor
217
+ } = this.asProps;
218
+ return {
219
+ size,
220
+ resolveColor
221
+ };
222
+ }
223
+ getDividerProps() {
224
+ return {
225
+ 'my': 1,
226
+ 'aria-disabled': 'true'
227
+ };
228
+ }
229
+ renderChildrenTrigger(value, options) {
230
+ if (options) {
231
+ return [].concat(value).reduce((acc, value) => {
232
+ const selectedOption = options.find(o => isSelectedOption(value, o.value));
233
+ if (!selectedOption) return acc;
275
234
  if (acc.length) acc.push(', ');
276
- acc.push(value);
235
+ acc.push(selectedOption.label || selectedOption.value);
277
236
  return acc;
278
- }, []) : value;
237
+ }, []);
279
238
  }
280
- }, {
281
- key: "render",
282
- value: function render() {
283
- var _ref2 = this.asProps;
284
- var _this$asProps5 = this.asProps,
285
- Children = _this$asProps5.Children,
286
- options = _this$asProps5.options,
287
- multiselect = _this$asProps5.multiselect,
288
- _value = _this$asProps5.value,
289
- uid = _this$asProps5.uid,
290
- forcedAdvancedMode = _this$asProps5.forcedAdvancedMode,
291
- other = _objectWithoutProperties(_this$asProps5, _excluded);
292
- var advancedMode = forcedAdvancedMode || findComponent(Children, [Select.Trigger.displayName, Select.Popper.displayName]);
293
- logger.warn(options && advancedMode, 'Don\'t use at the same time \'options\' property and \'<Select.Trigger/>/<Select.Popper/>\'', other['data-ui-name'] || Select.displayName);
294
- this.itemProps = [];
295
- if (options) {
296
- var _ref = this.asProps;
297
- return /*#__PURE__*/React.createElement(DropdownMenu, _assignProps({}, _ref), /*#__PURE__*/React.createElement(Select.Trigger, other), /*#__PURE__*/React.createElement(Select.Menu, null, options.map(function (option, index) {
298
- return /*#__PURE__*/React.createElement(Select.Option, _extends({
299
- key: option.value,
300
- id: "igc-".concat(uid, "-option-").concat(index)
301
- }, option), multiselect && /*#__PURE__*/React.createElement(Select.Option.Checkbox, null), option.children);
302
- })));
303
- }
304
- return /*#__PURE__*/React.createElement(DropdownMenu, _assignProps2({}, _ref2), /*#__PURE__*/React.createElement(Children, null));
239
+ return Array.isArray(value) ? value.reduce((acc, value) => {
240
+ if (acc.length) acc.push(', ');
241
+ acc.push(value);
242
+ return acc;
243
+ }, []) : value;
244
+ }
245
+ render() {
246
+ var _ref2 = this.asProps;
247
+ const {
248
+ Children,
249
+ options,
250
+ multiselect,
251
+ value: _value,
252
+ uid,
253
+ forcedAdvancedMode,
254
+ ...other
255
+ } = this.asProps;
256
+ const advancedMode = forcedAdvancedMode || findComponent(Children, [Select.Trigger.displayName, Select.Popper.displayName]);
257
+ logger.warn(options && advancedMode, 'Don\'t use at the same time \'options\' property and \'<Select.Trigger/>/<Select.Popper/>\'', other['data-ui-name'] || Select.displayName);
258
+ this.itemProps = [];
259
+ if (options) {
260
+ var _ref = this.asProps;
261
+ return /*#__PURE__*/React.createElement(DropdownMenu, _assignProps({}, _ref), /*#__PURE__*/React.createElement(Select.Trigger, other), /*#__PURE__*/React.createElement(Select.Menu, null, options.map((option, index) => {
262
+ return /*#__PURE__*/React.createElement(Select.Option, _extends({
263
+ key: option.value,
264
+ id: `igc-${uid}-option-${index}`
265
+ }, option), multiselect && /*#__PURE__*/React.createElement(Select.Option.Checkbox, null), option.children);
266
+ })));
305
267
  }
306
- }]);
307
- }(AbstractDropdown);
268
+ return /*#__PURE__*/React.createElement(DropdownMenu, _assignProps2({}, _ref2), /*#__PURE__*/React.createElement(Children, null));
269
+ }
270
+ }
308
271
  _defineProperty(RootSelect, "displayName", 'Select');
309
272
  _defineProperty(RootSelect, "style", style);
310
273
  _defineProperty(RootSelect, "enhance", Object.values(enhance).concat([resolveColorEnhance()]));
311
- _defineProperty(RootSelect, "defaultProps", function (props) {
312
- var _props$highlightedInd, _props$selectedIndex, _props$interaction, _props$timeout;
313
- var hasInputSearch = props.children && isAdvanceMode(props.children, [Select.InputSearch.displayName, InputSearch.displayName], true);
314
- var defaultIndex = hasInputSearch ? null : 0;
274
+ _defineProperty(RootSelect, "defaultProps", props => {
275
+ const hasInputSearch = props.children && isAdvanceMode(props.children, [Select.InputSearch.displayName, InputSearch.displayName], true);
276
+ const defaultIndex = hasInputSearch ? null : 0;
315
277
  return {
316
278
  placeholder: props.multiselect ? 'Select options' : 'Select option',
317
279
  size: 'm',
318
280
  defaultValue: getEmptyValue(props.multiselect),
319
281
  defaultVisible: false,
320
- defaultHighlightedIndex: (_props$highlightedInd = props.highlightedIndex) !== null && _props$highlightedInd !== void 0 ? _props$highlightedInd : defaultIndex,
321
- defaultSelectedIndex: (_props$selectedIndex = props.selectedIndex) !== null && _props$selectedIndex !== void 0 ? _props$selectedIndex : defaultIndex,
282
+ defaultHighlightedIndex: props.highlightedIndex ?? defaultIndex,
283
+ defaultSelectedIndex: props.selectedIndex ?? defaultIndex,
322
284
  scrollToSelected: true,
323
285
  i18n: localizedMessages,
324
286
  locale: 'en',
325
- interaction: (_props$interaction = props.interaction) !== null && _props$interaction !== void 0 ? _props$interaction : 'click',
287
+ interaction: props.interaction ?? 'click',
326
288
  inlineActions: false,
327
- timeout: (_props$timeout = props.timeout) !== null && _props$timeout !== void 0 ? _props$timeout : 0
289
+ timeout: props.timeout ?? 0
328
290
  };
329
291
  });
330
- function Trigger(_ref0) {
292
+ function Trigger({
293
+ Children,
294
+ name,
295
+ value,
296
+ styles,
297
+ $hiddenRef,
298
+ tag: Tag = ButtonTrigger,
299
+ getI18nText
300
+ }) {
331
301
  var _ref3 = arguments[0],
332
302
  _ref7;
333
- var Children = _ref0.Children,
334
- name = _ref0.name,
335
- value = _ref0.value,
336
- styles = _ref0.styles,
337
- $hiddenRef = _ref0.$hiddenRef,
338
- _ref0$tag = _ref0.tag,
339
- Tag = _ref0$tag === void 0 ? ButtonTrigger : _ref0$tag,
340
- getI18nText = _ref0.getI18nText;
341
- var hasInputTrigger = isInputTriggerTag(Tag);
342
- var SSelectTrigger = Dropdown.Trigger;
343
- return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectTrigger, _ref7.cn("SSelectTrigger", _objectSpread({}, _assignProps3({
344
- "tag": Tag,
345
- "placeholder": getI18nText('selectPlaceholder'),
346
- "role": 'combobox',
347
- "aria-autocomplete": hasInputTrigger && 'list' || undefined
348
- }, _ref3))), addonTextChildren(Children, Tag.Text || Tag.Value || ButtonTrigger.Text, Tag.Addon || ButtonTrigger.Addon, true), name && /*#__PURE__*/React.createElement("input", _ref7.cn("input", {
303
+ const hasInputTrigger = isInputTriggerTag(Tag);
304
+ const SSelectTrigger = Dropdown.Trigger;
305
+ return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectTrigger, _ref7.cn("SSelectTrigger", {
306
+ ..._assignProps3({
307
+ "tag": Tag,
308
+ "placeholder": getI18nText('selectPlaceholder'),
309
+ "role": 'combobox',
310
+ "aria-autocomplete": hasInputTrigger && 'list' || undefined
311
+ }, _ref3)
312
+ }), addonTextChildren(Children, Tag.Text || Tag.Value || ButtonTrigger.Text, Tag.Addon || ButtonTrigger.Addon, true), name && /*#__PURE__*/React.createElement("input", _ref7.cn("input", {
349
313
  "type": 'hidden',
350
314
  "defaultValue": value,
351
315
  "name": name,
@@ -354,77 +318,114 @@ function Trigger(_ref0) {
354
318
  }
355
319
  function Menu(props) {
356
320
  var _ref4 = arguments[0];
357
- var visible = props.visible,
358
- disablePortal = props.disablePortal,
359
- ignorePortalsStacking = props.ignorePortalsStacking,
360
- disableEnforceFocus = props.disableEnforceFocus,
361
- interaction = props.interaction,
362
- autoFocus = props.autoFocus,
363
- animationsDisabled = props.animationsDisabled;
364
- var popperProps = {
365
- visible: visible,
366
- disablePortal: disablePortal,
367
- ignorePortalsStacking: ignorePortalsStacking,
368
- disableEnforceFocus: disableEnforceFocus,
369
- interaction: interaction,
370
- autoFocus: autoFocus,
371
- animationsDisabled: animationsDisabled
321
+ const {
322
+ visible,
323
+ disablePortal,
324
+ ignorePortalsStacking,
325
+ disableEnforceFocus,
326
+ interaction,
327
+ autoFocus,
328
+ animationsDisabled
329
+ } = props;
330
+ const popperProps = {
331
+ visible,
332
+ disablePortal,
333
+ ignorePortalsStacking,
334
+ disableEnforceFocus,
335
+ interaction,
336
+ autoFocus,
337
+ animationsDisabled
372
338
  };
373
339
  return /*#__PURE__*/React.createElement(ListBoxContextProvider, null, /*#__PURE__*/React.createElement(Select.Popper, _extends({}, popperProps, {
374
340
  role: null
375
341
  }), /*#__PURE__*/React.createElement(Select.List, _assignProps4({}, _ref4))));
376
342
  }
377
- var optionPropsContext = /*#__PURE__*/React.createContext({});
343
+ const optionPropsContext = /*#__PURE__*/React.createContext({});
378
344
  function Option(props) {
379
345
  var _ref5 = arguments[0],
380
346
  _ref8;
381
- var SSelectOption = Dropdown.Item;
382
- var styles = props.styles,
383
- Children = props.Children;
384
- var hasCheckbox = isAdvanceMode(Children, [Select.Option.Checkbox.displayName]);
385
- var hasContent = isAdvanceMode(Children, [Select.Option.Content.displayName]);
386
- return _ref8 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectOption, _ref8.cn("SSelectOption", _objectSpread({}, _assignProps5({}, _ref5))), /*#__PURE__*/React.createElement(optionPropsContext.Provider, {
387
- value: props
347
+ const SSelectOption = Dropdown.Item;
348
+ const {
349
+ styles,
350
+ Children,
351
+ highlighted
352
+ } = props;
353
+ const itemRef = React.useRef(null);
354
+ const hasCheckbox = isAdvanceMode(Children, [Select.Option.Checkbox.displayName]);
355
+ const hasContent = isAdvanceMode(Children, [Select.Option.Content.displayName]);
356
+ const optionPropsContextValue = {
357
+ ...props,
358
+ itemRef,
359
+ highlighted
360
+ };
361
+ return _ref8 = sstyled(styles), /*#__PURE__*/React.createElement(SSelectOption, _ref8.cn("SSelectOption", {
362
+ ..._assignProps5({
363
+ "ref": itemRef
364
+ }, _ref5)
365
+ }), /*#__PURE__*/React.createElement(optionPropsContext.Provider, {
366
+ value: optionPropsContextValue
388
367
  }, hasCheckbox && !hasContent ? /*#__PURE__*/React.createElement(Select.Option.Content, null, /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {}))) : /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {}))));
389
368
  }
390
369
  function Checkbox(providedProps) {
391
- var optionProps = React.useContext(optionPropsContext);
392
- var props = React.useMemo(function () {
393
- return _objectSpread({
394
- selected: optionProps === null || optionProps === void 0 ? void 0 : optionProps.selected,
395
- disabled: optionProps === null || optionProps === void 0 ? void 0 : optionProps.disabled,
396
- size: optionProps === null || optionProps === void 0 ? void 0 : optionProps.size
397
- }, providedProps || {});
398
- }, [providedProps, optionProps]);
399
- var _useBox = useBox(props, props.forwardRef),
400
- _useBox2 = _slicedToArray(_useBox, 2),
401
- SOptionCheckbox = _useBox2[0],
402
- componentProps = _useBox2[1];
403
- var size = props.size,
404
- theme = props.theme,
405
- selected = props.selected,
406
- resolveColor = props.resolveColor,
407
- indeterminate = props.indeterminate;
408
- var styles = sstyled(props.styles);
409
- var _styles$cn = styles.cn('SOptionCheckbox', {
410
- size: size,
411
- 'use:theme': resolveColor(theme),
412
- indeterminate: indeterminate,
413
- selected: selected
414
- }),
415
- className = _styles$cn.className,
416
- style = _styles$cn.style;
370
+ const optionProps = React.useContext(optionPropsContext);
371
+ const props = React.useMemo(() => ({
372
+ selected: optionProps?.selected,
373
+ disabled: optionProps?.disabled,
374
+ size: optionProps?.size,
375
+ ...(providedProps || {})
376
+ }), [providedProps, optionProps]);
377
+ const [SOptionCheckbox, componentProps] = useBox(props, props.forwardRef);
378
+ const {
379
+ size,
380
+ theme,
381
+ selected,
382
+ resolveColor,
383
+ indeterminate
384
+ } = props;
385
+ const styles = sstyled(props.styles);
386
+ const {
387
+ className,
388
+ style
389
+ } = styles.cn('SOptionCheckbox', {
390
+ size,
391
+ 'use:theme': resolveColor(theme),
392
+ indeterminate,
393
+ selected
394
+ });
417
395
  return /*#__PURE__*/React.createElement(SOptionCheckbox, _extends({}, componentProps, {
418
396
  className: cn(className, componentProps.className) || undefined,
419
- style: _objectSpread(_objectSpread({}, style), componentProps.style),
397
+ style: {
398
+ ...style,
399
+ ...componentProps.style
400
+ },
420
401
  tabIndex: -1
421
402
  }));
422
403
  }
423
- var InputSearchWrapper = function InputSearchWrapper() {
404
+ function OptionText(providedProps) {
405
+ var _ref9;
406
+ const optionProps = React.useContext(optionPropsContext);
407
+ const selectedIndex = React.useContext(selectedIndexContext);
408
+ const props = React.useMemo(() => ({
409
+ key: optionProps?.id,
410
+ selected: optionProps?.selected,
411
+ disabled: optionProps?.disabled,
412
+ size: optionProps?.size,
413
+ hintProps: optionProps?.hintProps ?? {},
414
+ ...(providedProps || {})
415
+ }), [providedProps, optionProps]);
416
+ if (optionProps.itemRef) {
417
+ props.hintProps.triggerRef = optionProps.itemRef;
418
+ }
419
+ props.hintProps.visible = selectedIndex === optionProps.index;
420
+ return _ref9 = sstyled(props.styles), /*#__PURE__*/React.createElement(Text, _ref9.cn("Text", {
421
+ ...props
422
+ }));
423
+ }
424
+ const InputSearchWrapper = function () {
424
425
  var _ref6 = arguments[0];
425
426
  return /*#__PURE__*/React.createElement(InputSearch, _assignProps6({}, _ref6));
426
427
  };
427
- var Select = createComponent(RootSelect, {
428
+ const Select = createComponent(RootSelect, {
428
429
  Trigger: [Trigger, {
429
430
  Addon: ButtonTrigger.Addon,
430
431
  Text: ButtonTrigger.Text
@@ -435,22 +436,19 @@ var Select = createComponent(RootSelect, {
435
436
  Option: [Option, {
436
437
  Addon: DropdownMenu.Item.Addon,
437
438
  Content: DropdownMenu.Item.Content,
439
+ Text: OptionText,
438
440
  Hint: DropdownMenu.Item.Hint,
439
- Checkbox: Checkbox
441
+ Checkbox
440
442
  }],
441
443
  Group: Dropdown.Group,
442
- OptionTitle: DropdownMenu.ItemTitle,
443
- OptionHint: DropdownMenu.ItemHint,
444
- Divider: Divider,
444
+ Divider,
445
445
  InputSearch: [InputSearchWrapper, InputSearch._______childrenComponents],
446
446
  Input: [InputSearchWrapper, InputSearch._______childrenComponents]
447
447
  }, {
448
448
  parent: DropdownMenu,
449
449
  context: selectContext
450
450
  });
451
- export var wrapSelect = function wrapSelect(wrapper) {
452
- return wrapper;
453
- };
451
+ export const wrapSelect = wrapper => wrapper;
454
452
  Select.selectedIndexContext = selectedIndexContext;
455
453
  export default Select;
456
454
  //# sourceMappingURL=Select.js.map