@festo-ui/react 7.3.0-dev.464 → 7.3.0-dev.468

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.
Files changed (54) hide show
  1. package/index.css +1 -1
  2. package/lib/components/icons/close-small.d.ts +7 -0
  3. package/lib/components/icons/close-small.js +70 -0
  4. package/lib/forms/checkbox/Checkbox.d.ts +1 -1
  5. package/lib/forms/select/Select.d.ts +15 -9
  6. package/lib/forms/select/Select.js +68 -253
  7. package/lib/forms/select/internal/HiddenInput.d.ts +9 -0
  8. package/lib/forms/select/internal/HiddenInput.js +26 -0
  9. package/lib/forms/select/internal/ListItem.d.ts +18 -0
  10. package/lib/forms/select/internal/ListItem.js +78 -0
  11. package/lib/forms/select/internal/SelectButton.d.ts +13 -0
  12. package/lib/forms/select/internal/SelectButton.js +57 -0
  13. package/lib/forms/select/internal/SelectButtonContent.d.ts +8 -0
  14. package/lib/forms/select/internal/SelectButtonContent.js +39 -0
  15. package/lib/forms/select/internal/SelectCheckbox.d.ts +5 -0
  16. package/lib/forms/select/internal/SelectCheckbox.js +20 -0
  17. package/lib/forms/select/internal/SelectLabel.d.ts +8 -0
  18. package/lib/forms/select/internal/SelectLabel.js +16 -0
  19. package/lib/forms/select/internal/SelectOptionsContainer.d.ts +17 -0
  20. package/lib/forms/select/internal/SelectOptionsContainer.js +104 -0
  21. package/lib/forms/select/internal/SelectScrollContainer.d.ts +9 -0
  22. package/lib/forms/select/internal/SelectScrollContainer.js +22 -0
  23. package/lib/forms/select/internal/SelectWrapper.d.ts +6 -0
  24. package/lib/forms/select/internal/SelectWrapper.js +20 -0
  25. package/lib/forms/select/internal/index.d.ts +6 -0
  26. package/lib/forms/select/internal/index.js +6 -0
  27. package/lib/forms/select/internal/utils.d.ts +7 -0
  28. package/lib/forms/select/internal/utils.js +36 -0
  29. package/lib/forms/select/select-option/SelectOption.d.ts +10 -6
  30. package/lib/forms/select/select-option/SelectOption.js +3 -2
  31. package/lib/forms/text-editor/TextEditor.d.ts +11 -11
  32. package/lib/forms/text-editor/TextEditor.js +3 -3
  33. package/lib/helper/useControlled.d.ts +3 -2
  34. package/lib/helper/useControlled.js +6 -2
  35. package/node/lib/components/icons/close-small.js +75 -0
  36. package/node/lib/forms/select/Select.js +69 -255
  37. package/node/lib/forms/select/internal/HiddenInput.js +32 -0
  38. package/node/lib/forms/select/internal/ListItem.js +87 -0
  39. package/node/lib/forms/select/internal/SelectButton.js +64 -0
  40. package/node/lib/forms/select/internal/SelectButtonContent.js +45 -0
  41. package/node/lib/forms/select/internal/SelectCheckbox.js +26 -0
  42. package/node/lib/forms/select/internal/SelectLabel.js +23 -0
  43. package/node/lib/forms/select/internal/SelectOptionsContainer.js +109 -0
  44. package/node/lib/forms/select/internal/SelectScrollContainer.js +28 -0
  45. package/node/lib/forms/select/internal/SelectWrapper.js +27 -0
  46. package/node/lib/forms/select/internal/index.js +48 -0
  47. package/node/lib/forms/select/internal/utils.js +43 -0
  48. package/node/lib/forms/select/select-option/SelectOption.js +4 -3
  49. package/node/lib/forms/text-editor/TextEditor.js +3 -3
  50. package/node/lib/helper/useControlled.js +6 -2
  51. package/package.json +1 -1
  52. package/lib/forms/select/list-item/ListItem.d.ts +0 -6
  53. package/lib/forms/select/list-item/ListItem.js +0 -24
  54. package/node/lib/forms/select/list-item/ListItem.js +0 -33
@@ -3,299 +3,113 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.Select = void 0;
7
- var _classnames = _interopRequireDefault(require("classnames"));
8
- var _react = _interopRequireWildcard(require("react"));
6
+ exports.default = void 0;
7
+ var _react = require("react");
9
8
  var _reactDom = _interopRequireDefault(require("react-dom"));
10
- var _reactPopper = require("react-popper");
11
9
  var _useControlled = _interopRequireDefault(require("../../helper/useControlled.js"));
10
+ var _index = require("./internal/index.js");
12
11
  var _useForkRef = _interopRequireDefault(require("../../helper/useForkRef.js"));
13
- var _ListItem = _interopRequireDefault(require("./list-item/ListItem.js"));
14
- var _utils = _interopRequireDefault(require("./utils.js"));
12
+ var _utils = _interopRequireDefault(require("./internal/utils.js"));
15
13
  var _jsxRuntime = require("react/jsx-runtime");
16
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- const Select = exports.Select = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
15
+ function SelectComponent(_ref, ref) {
20
16
  let {
21
17
  defaultValue = '',
22
- value,
18
+ open,
19
+ defaultOpen = false,
20
+ value: controlled,
23
21
  label,
24
22
  options,
25
23
  onChange,
26
24
  required = false,
27
25
  config,
28
26
  disabled,
29
- className,
30
27
  name,
31
28
  id,
32
29
  children,
33
30
  hint,
34
31
  error,
32
+ onOpenChange,
33
+ renderLabelContent,
35
34
  ...props
36
35
  } = _ref;
37
- const [optionsWrapper, setOptionsWrapper] = (0, _react.useState)({
38
- isFocused: false,
39
- action: ''
36
+ const [value, setValue] = (0, _useControlled.default)({
37
+ controlled,
38
+ default: defaultValue,
39
+ onChange
40
40
  });
41
- const [innerValue, setInnerValue] = (0, _useControlled.default)({
42
- controlled: value,
43
- default: defaultValue
41
+ const [focused, setFocused] = (0, _useControlled.default)({
42
+ controlled: open,
43
+ default: defaultOpen,
44
+ onChange: onOpenChange
44
45
  });
46
+ const buttonEl = (0, _react.useRef)(null);
47
+ const usedOptions = options ?? (0, _utils.default)(children).childrenList.map(child => child.props.option);
45
48
  const innerRef = (0, _react.useRef)(null);
46
49
  const combinedRef = (0, _useForkRef.default)(ref, innerRef);
47
- const buttonEl = (0, _react.useRef)(null);
48
- const childrenList = [];
49
- const [popperElement, setPopperElement] = (0, _react.useState)(null);
50
- const {
51
- styles,
52
- attributes
53
- } = (0, _reactPopper.usePopper)(innerRef.current, popperElement, {
54
- placement: 'bottom-start',
55
- modifiers: [{
56
- name: 'offset',
57
- options: {
58
- offset: [0, 3]
59
- }
60
- }, {
61
- name: 'flip',
62
- options: {
63
- fallbackPlacements: ['bottom-start', 'top-start']
64
- }
65
- }]
66
- });
67
- _react.default.Children.forEach(children, element => {
68
- if ( /*#__PURE__*/_react.default.isValidElement(element)) {
69
- childrenList.push({
70
- ...element,
71
- props: {
72
- ...element.props,
73
- className: 'fwe-select-option-content'
74
- }
75
- });
76
- }
77
- });
78
- const usedOptions = options ?? childrenList.map(child => child.props.option);
79
- const listItemRef = (0, _react.useRef)(Array.from({
80
- length: usedOptions.length
81
- }, () => /*#__PURE__*/_react.default.createRef()));
82
- const getSelectedOptionLabel = (0, _react.useCallback)(() => usedOptions.find(option => option.data === innerValue)?.label, [usedOptions, innerValue]);
83
- const scroll = config?.scroll;
84
- function handleButtonFocus(blur) {
85
- if (buttonEl && buttonEl.current) {
86
- if (blur) {
87
- buttonEl.current.blur();
88
- } else {
89
- buttonEl.current.focus();
90
- }
91
- }
92
- }
93
- const focusNextElement = (0, _react.useCallback)(nextIndex => {
94
- if (listItemRef && listItemRef.current) {
95
- const nextItem = listItemRef.current[nextIndex].current;
96
- if (nextItem !== null) {
97
- nextItem.focus();
98
- }
99
- }
100
- }, []);
101
- const handleKeyAction = (0, _react.useCallback)(index => {
102
- if (index >= 0) {
103
- focusNextElement(index);
104
- }
105
- }, [focusNextElement]);
106
- (0, _react.useEffect)(() => {
107
- if (optionsWrapper.isFocused) {
108
- if (optionsWrapper.action === 'key') {
109
- const index = usedOptions.findIndex(option => option.label === getSelectedOptionLabel());
110
- handleKeyAction(index);
111
- } else if (optionsWrapper.action === 'click') {
112
- handleButtonFocus(true);
113
- }
114
- }
115
- }, [optionsWrapper, usedOptions, innerValue, getSelectedOptionLabel, handleKeyAction]);
116
- const handleOptionChange = newOption => {
117
- setInnerValue(newOption.data);
118
- if (onChange) {
119
- onChange(newOption.data);
120
- }
121
- setOptionsWrapper(prevOptionsWrapper => ({
122
- ...prevOptionsWrapper,
123
- isFocused: false
124
- }));
125
- if (buttonEl && buttonEl.current) {
126
- buttonEl.current.focus();
127
- }
50
+ const multiple = Array.isArray(value);
51
+ const refocusButton = () => {
52
+ setFocused(false);
53
+ buttonEl?.current?.focus();
128
54
  };
129
- const handleListKeyDown = (e, option, index) => {
130
- const arrowKeys = ['ArrowDown', 'ArrowUp'];
131
- const validKeys = ['Enter', ' '];
132
- if (arrowKeys.concat(validKeys).includes(e.key)) {
133
- e.preventDefault();
134
- }
135
- if (e.key === 'ArrowDown') {
136
- focusNextElement((index + 1) % usedOptions.length);
137
- }
138
- if (e.key === 'ArrowUp') {
139
- const nextIndex = (index - 1 + usedOptions.length) % usedOptions.length;
140
- focusNextElement(nextIndex);
141
- }
142
- if (validKeys.includes(e.key)) {
143
- handleOptionChange(option);
144
- }
145
- if (e.key === 'Escape') {
146
- setOptionsWrapper(prevOptionsWrapper => ({
147
- ...prevOptionsWrapper,
148
- isFocused: false
149
- }));
150
- handleButtonFocus();
151
- }
152
- };
153
- const handleKeyPress = event => {
154
- const validKeys = ['Enter', ' ', 'ArrowUp', 'ArrowDown'];
155
- if (validKeys.includes(event.key)) {
156
- event.preventDefault();
157
- if (!disabled) {
158
- setOptionsWrapper(prevOptionsWrapper => ({
159
- action: 'key',
160
- isFocused: !prevOptionsWrapper.isFocused
161
- }));
162
- }
55
+ const handleOptionChange = newOption => {
56
+ let newValue = newOption.data;
57
+ if (value instanceof Array) {
58
+ newValue = value.includes(newValue) ? value.filter(item => item !== newValue) : [...value, newValue];
163
59
  }
164
- };
165
- const handleClick = e => {
166
- e.stopPropagation();
167
- if (!disabled) {
168
- setOptionsWrapper(prevOptionsWrapper => ({
169
- action: '',
170
- isFocused: !prevOptionsWrapper.isFocused
171
- }));
60
+ setValue(newValue);
61
+ if (!multiple) {
62
+ refocusButton();
172
63
  }
173
64
  };
174
- const handleChange = event => {
175
- const child = usedOptions.find(childItem => childItem.data === event.target.value);
176
- if (child === undefined) {
177
- return;
178
- }
179
- setInnerValue(child.data);
180
- if (onChange) {
181
- onChange(child.data);
65
+ const removeChip = chipLabel => {
66
+ const chipOption = usedOptions.find(option => option.label === chipLabel);
67
+ if (chipOption) {
68
+ handleOptionChange(chipOption);
182
69
  }
183
70
  };
184
- const selectedOptionLabel = getSelectedOptionLabel();
185
- const selectClassName = (0, _classnames.default)('fwe-select', {
186
- 'fwe-focus': optionsWrapper.isFocused
187
- }, {
188
- 'fwe-empty': selectedOptionLabel === undefined && !optionsWrapper.isFocused
189
- }, {
190
- 'fwe-required': required
191
- }, {
192
- 'fwe-disabled': disabled
193
- }, {
194
- 'fwe-invalid': error
195
- });
196
- function getCssProperies() {
197
- if (config?.contentWidth) {
198
- return {
199
- ...styles.popper,
200
- minWidth: `${innerRef.current?.clientWidth}px`,
201
- width: config?.contentWidth
202
- };
203
- }
204
- return {
205
- ...styles.popper,
206
- minWidth: `${innerRef.current?.clientWidth}px`
207
- };
208
- }
209
- function renderOptions() {
210
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
211
- children: [options && options.map((option, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItem.default, {
212
- ref: listItemRef.current[i],
213
- "aria-selected": option.label === selectedOptionLabel,
214
- onClick: () => handleOptionChange(option),
215
- empty: !option.label,
216
- onKeyDown: e => handleListKeyDown(e, option, i),
217
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
218
- className: "fwe-select-option-content",
219
- "data-testid": "fwe-select-option-content",
220
- children: option.label
221
- })
222
- }, option.data)), childrenList.map((child, i) => {
223
- const {
224
- option,
225
- ...propsWithoutOption
226
- } = child.props;
227
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItem.default, {
228
- ref: listItemRef.current[i],
229
- "aria-selected": option.label === selectedOptionLabel,
230
- onClick: () => handleOptionChange(option),
231
- empty: !option.label,
232
- onKeyDown: e => handleListKeyDown(e, option, i),
233
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
234
- ...propsWithoutOption
235
- })
236
- }, option.data);
237
- })]
238
- });
239
- }
240
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
71
+ const selectedLabel = multiple ? usedOptions.filter(option => value.includes(option.data))?.map(option => option.label) : usedOptions.find(option => option.data === value)?.label;
72
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Wrapper, {
73
+ disabled: disabled,
241
74
  ref: combinedRef,
242
- className: (0, _classnames.default)('fwe-select-wrapper', {
243
- 'fwe-disabled': disabled
244
- }, className),
245
75
  ...props,
246
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
247
- className: "fr-select-input",
248
- "aria-hidden": true,
249
- tabIndex: -1,
250
- value: innerValue,
251
- onChange: e => handleChange(e)
252
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
253
- role: "button",
254
- tabIndex: 0,
255
- className: selectClassName,
256
- onClick: e => handleClick(e),
76
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.HiddenInput, {
77
+ onChange: handleOptionChange,
78
+ options: usedOptions,
79
+ value: value
80
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.SelectButton, {
257
81
  ref: buttonEl,
258
- onKeyDown: handleKeyPress,
259
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
260
- className: "fwe-select-content",
261
- children: selectedOptionLabel
262
- })
263
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
264
- className: (0, _classnames.default)('fwe-select-label', {
265
- 'fwe-sr-only': config?.hideLabel
266
- }),
267
- htmlFor: id,
268
- children: label || ''
82
+ onToggle: () => setFocused(prev => !prev),
83
+ error: error,
84
+ disabled: disabled,
85
+ focused: focused,
86
+ required: required,
87
+ onChipClick: removeChip,
88
+ label: selectedLabel,
89
+ renderLabelContent: renderLabelContent
90
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.SelectLabel, {
91
+ hideLabel: config?.hideLabel,
92
+ label: label,
93
+ id: id
269
94
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
270
95
  className: "fwe-select-underline"
271
96
  }), hint && !error && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
272
97
  className: "fwe-select-description",
273
98
  children: hint
274
- }), error && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
99
+ }), error && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
275
100
  className: "fwe-select-invalid",
276
- children: [" ", error, " "]
277
- }), optionsWrapper.isFocused ? /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
278
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
279
- "aria-hidden": true,
280
- className: "fr-backdrop",
281
- onClick: () => setOptionsWrapper({
282
- action: '',
283
- isFocused: false
284
- })
285
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
286
- ref: setPopperElement,
287
- style: getCssProperies(),
288
- ...attributes.popper,
289
- className: "fwe-select-options-container",
290
- children: scroll?.enabled ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
291
- className: "fr-select-scroll",
292
- style: {
293
- height: (0, _utils.default)(config, usedOptions.length)
294
- },
295
- children: renderOptions()
296
- }) : renderOptions()
297
- })]
298
- }), document.body) : null]
101
+ children: error
102
+ }), focused && /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.OptionsContainer, {
103
+ multiple: multiple,
104
+ ref: innerRef,
105
+ config: config,
106
+ onClose: refocusButton,
107
+ onOptionChange: handleOptionChange,
108
+ options: options,
109
+ label: selectedLabel,
110
+ children: children
111
+ }), document.body)]
299
112
  });
300
- });
113
+ }
114
+ const Select = /*#__PURE__*/(0, _react.forwardRef)(SelectComponent);
301
115
  var _default = exports.default = Select;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = HiddenInput;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ function HiddenInput(_ref) {
9
+ let {
10
+ value,
11
+ onChange,
12
+ options
13
+ } = _ref;
14
+ function handleChange(event) {
15
+ const child = options.find(_ref2 => {
16
+ let {
17
+ data
18
+ } = _ref2;
19
+ return data === event.target.value;
20
+ });
21
+ if (child !== undefined) {
22
+ onChange(child);
23
+ }
24
+ }
25
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
26
+ className: "fr-select-input",
27
+ "aria-hidden": true,
28
+ tabIndex: -1,
29
+ value: value,
30
+ onChange: handleChange
31
+ });
32
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _SelectCheckbox = _interopRequireDefault(require("./SelectCheckbox.js"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ function ListItemComponent(_ref, ref) {
15
+ let {
16
+ children,
17
+ className,
18
+ empty,
19
+ options,
20
+ onClose,
21
+ onOptionChange,
22
+ index,
23
+ selectedLabel,
24
+ item,
25
+ withCheckbox,
26
+ onFocusChange,
27
+ ...restProps
28
+ } = _ref;
29
+ const isChild = /*#__PURE__*/_react.default.isValidElement(item);
30
+ const option = isChild ? item.props.option : item;
31
+ const propsWithoutOption = isChild ? {
32
+ ...item.props,
33
+ option: undefined
34
+ } : {};
35
+ const checked = Array.isArray(selectedLabel) ? selectedLabel.includes(option.label) : selectedLabel === option.label;
36
+ function handleKeyDown(e) {
37
+ const arrowKeys = ['ArrowDown', 'ArrowUp'];
38
+ const validKeys = ['Enter', ' '];
39
+ if (arrowKeys.concat(validKeys).includes(e.key)) {
40
+ e.preventDefault();
41
+ }
42
+ if (e.key === 'ArrowDown') {
43
+ onFocusChange((index + 1) % options.length);
44
+ }
45
+ if (e.key === 'ArrowUp') {
46
+ const nextIndex = (index - 1 + options.length) % options.length;
47
+ onFocusChange(nextIndex);
48
+ }
49
+ if (['Enter', ' '].includes(e.key)) {
50
+ if (option.disabled) {
51
+ return;
52
+ }
53
+ onOptionChange(option);
54
+ }
55
+ if (e.key === 'Escape') {
56
+ onClose();
57
+ }
58
+ }
59
+ const itemRef = typeof ref !== 'function' ? ref?.current?.[index] : undefined;
60
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
61
+ onClick: () => onOptionChange(option),
62
+ ref: itemRef,
63
+ role: "option",
64
+ onKeyDown: handleKeyDown,
65
+ "aria-selected": checked,
66
+ className: (0, _classnames.default)('fwe-select-option', {
67
+ 'fwe-empty': !option.label
68
+ }, className),
69
+ tabIndex: 0,
70
+ ...restProps,
71
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectCheckbox.default, {
72
+ disabled: option.disabled,
73
+ onClick: e => e.stopPropagation(),
74
+ checked: checked,
75
+ withCheckbox: withCheckbox,
76
+ children: isChild ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
77
+ ...propsWithoutOption
78
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
79
+ className: "fwe-select-option-content",
80
+ "data-testid": "fwe-select-option-content",
81
+ children: option.label
82
+ })
83
+ })
84
+ });
85
+ }
86
+ const ListItem = /*#__PURE__*/(0, _react.forwardRef)(ListItemComponent);
87
+ var _default = exports.default = ListItem;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _classnames = _interopRequireDefault(require("classnames"));
8
+ var _react = require("react");
9
+ var _SelectButtonContent = _interopRequireDefault(require("./SelectButtonContent.js"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const SelectButton = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
13
+ let {
14
+ onToggle,
15
+ disabled,
16
+ label,
17
+ focused,
18
+ required,
19
+ error,
20
+ onChipClick,
21
+ renderLabelContent
22
+ } = _ref;
23
+ const empty = label === undefined && !focused;
24
+ function handleKeyDown(e) {
25
+ if (disabled) {
26
+ return;
27
+ }
28
+ const validKeys = ['Enter', ' ', 'ArrowUp', 'ArrowDown'];
29
+ if (validKeys.includes(e.key)) {
30
+ e.preventDefault();
31
+ onToggle();
32
+ }
33
+ }
34
+ function handleClick(e) {
35
+ if (disabled) {
36
+ return;
37
+ }
38
+ e.stopPropagation();
39
+ onToggle();
40
+ }
41
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
42
+ role: "button",
43
+ tabIndex: 0,
44
+ className: (0, _classnames.default)('fwe-select', {
45
+ 'fwe-focus': focused,
46
+ 'fwe-empty': empty,
47
+ 'fwe-required': required,
48
+ 'fwe-disabled': disabled,
49
+ 'fwe-invalid': error
50
+ }),
51
+ onClick: handleClick,
52
+ ref: ref,
53
+ onKeyDown: handleKeyDown,
54
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
55
+ className: "fwe-select-content",
56
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectButtonContent.default, {
57
+ onClick: onChipClick,
58
+ label: label,
59
+ renderLabelContent: renderLabelContent
60
+ })
61
+ })
62
+ });
63
+ });
64
+ var _default = exports.default = SelectButton;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = SelectButtonContent;
7
+ var _closeSmall = _interopRequireDefault(require("../../../components/icons/close-small.js"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
11
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
12
+
13
+ function SelectButtonContent(_ref) {
14
+ let {
15
+ label,
16
+ renderLabelContent,
17
+ onClick
18
+ } = _ref;
19
+ const handleChipClick = chipLabel => e => {
20
+ e.stopPropagation();
21
+ onClick(chipLabel);
22
+ };
23
+ if (renderLabelContent) {
24
+ return renderLabelContent(label);
25
+ }
26
+ if (Array.isArray(label)) {
27
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
28
+ className: "fwe-chip-container",
29
+ children: label.map(v => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
30
+ className: "fwe-chip chip-text-truncate fwe-pr-4",
31
+ title: v,
32
+ children: [v, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
33
+ className: "chip-removable",
34
+ onClick: handleChipClick(v),
35
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_closeSmall.default, {
36
+ size: 16
37
+ })
38
+ })]
39
+ }, v))
40
+ });
41
+ }
42
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
43
+ children: label
44
+ });
45
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = SelectCheckbox;
7
+ var _Checkbox = _interopRequireDefault(require("../../checkbox/Checkbox.js"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function SelectCheckbox(_ref) {
11
+ let {
12
+ children,
13
+ withCheckbox,
14
+ ...props
15
+ } = _ref;
16
+ if (withCheckbox) {
17
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.default, {
18
+ tabIndex: -1,
19
+ ...props,
20
+ children: children
21
+ });
22
+ }
23
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
24
+ children: children
25
+ });
26
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = SelectLabel;
7
+ var _classnames = _interopRequireDefault(require("classnames"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function SelectLabel(_ref) {
11
+ let {
12
+ hideLabel,
13
+ label,
14
+ id
15
+ } = _ref;
16
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
17
+ className: (0, _classnames.default)('fwe-select-label', {
18
+ 'fwe-sr-only': hideLabel
19
+ }),
20
+ htmlFor: id,
21
+ children: label || ''
22
+ });
23
+ }