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