@rescui/select 0.14.4-RUI-286-Fix-tooltip-stacking-f4145b01.1 → 0.15.1-RUI-280-Update-select-component-026338d06.52
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/_virtual/index.css.js +12 -12
- package/lib/common-prop-types.d.ts +9 -14
- package/lib/common-prop-types.js +4 -3
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +8 -0
- package/lib/hooks/use-css-context-transfer.d.ts +14 -0
- package/lib/hooks/use-css-context-transfer.js +40 -0
- package/lib/hooks/use-label-focus.d.ts +11 -0
- package/lib/hooks/use-label-focus.js +28 -0
- package/lib/hooks/use-multi-option-serialization.d.ts +10 -0
- package/lib/hooks/use-multi-option-serialization.js +82 -0
- package/lib/hooks/use-option-serialization.d.ts +10 -0
- package/lib/hooks/use-option-serialization.js +59 -0
- package/lib/index.css +1700 -705
- package/lib/index.d.ts +4 -6
- package/lib/index.js +3 -3
- package/lib/multiselect.d.ts +29 -0
- package/lib/multiselect.js +239 -0
- package/lib/native-select.d.ts +4 -0
- package/lib/native-select.js +182 -0
- package/lib/parts/foldable.js +5 -7
- package/lib/parts/form-trigger-wrapper.d.ts +21 -3
- package/lib/parts/form-trigger-wrapper.js +30 -40
- package/lib/parts/icons.d.ts +17 -0
- package/lib/parts/icons.js +75 -0
- package/lib/parts/list-box.d.ts +19 -0
- package/lib/parts/list-box.js +146 -0
- package/lib/parts/multi-trigger.d.ts +11 -0
- package/lib/parts/multi-trigger.js +62 -0
- package/lib/parts/native-select-options-with-groups.d.ts +8 -0
- package/lib/parts/native-select-options-with-groups.js +76 -0
- package/lib/parts/native-select-trigger.d.ts +18 -0
- package/lib/parts/native-select-trigger.js +54 -0
- package/lib/parts/popover.d.ts +12 -0
- package/lib/parts/popover.js +62 -0
- package/lib/parts/popup-content.d.ts +19 -0
- package/lib/parts/popup-content.js +76 -0
- package/lib/public-api.p.css +401 -1022
- package/lib/public-api.pcss +401 -1022
- package/lib/select-basic.d.ts +3 -0
- package/lib/select-basic.js +143 -0
- package/lib/select-searchable.d.ts +3 -0
- package/lib/select-searchable.js +168 -0
- package/lib/select.d.ts +27 -86
- package/lib/select.js +58 -352
- package/lib/styles/common.p.module.css.js +27 -0
- package/lib/styles/form-trigger.p.module.css.js +15 -0
- package/lib/styles/list-box.p.module.css.js +16 -0
- package/lib/styles/native-select-trigger.p.module.css.js +17 -0
- package/lib/styles/native-select.p.module.css.js +9 -0
- package/lib/styles/popover.p.module.css.js +10 -0
- package/lib/types.d.ts +167 -4
- package/lib/utils/calculate-max-height-by-items.d.ts +13 -0
- package/lib/utils/calculate-max-height-by-items.js +22 -0
- package/lib/utils/convert-options.d.ts +3 -0
- package/lib/utils/convert-options.js +52 -0
- package/lib/utils/convert-placement.d.ts +3 -0
- package/lib/utils/convert-placement.js +22 -0
- package/lib/utils/css-vars-utils.d.ts +3 -0
- package/lib/utils/css-vars-utils.js +20 -0
- package/lib/utils/get-empty-message.d.ts +6 -0
- package/lib/utils/get-empty-message.js +32 -0
- package/lib/utils/get-option-value.d.ts +2 -0
- package/lib/utils/get-option-value.js +11 -0
- package/lib/utils/get-real-items-cnt.d.ts +2 -0
- package/lib/utils/get-real-items-cnt.js +21 -0
- package/lib/utils/get-text-from-nodes.d.ts +2 -0
- package/lib/utils/get-text-from-nodes.js +28 -0
- package/lib/utils/is-option-a-group.d.ts +2 -0
- package/lib/utils/is-option-a-group.js +5 -0
- package/lib/utils/throttle.d.ts +1 -0
- package/package.json +12 -8
- package/lib/_virtual/warning.js +0 -106
- package/lib/key-codes.d.ts +0 -7
- package/lib/key-codes.js +0 -8
- package/lib/parts/common-select.p.module.css.js +0 -15
- package/lib/parts/form-trigger.p.module.css.js +0 -13
- package/lib/parts/multiselect.d.ts +0 -81
- package/lib/parts/multiselect.js +0 -441
- package/lib/parts/native-select.d.ts +0 -30
- package/lib/parts/native-select.js +0 -244
- package/lib/parts/native-select.p.module.css.js +0 -9
- package/lib/parts/throttle.d.ts +0 -1
- package/lib/parts/trigger.d.ts +0 -37
- package/lib/parts/trigger.js +0 -255
- package/lib/parts/trigger.p.module.css.js +0 -31
- package/lib/utils.d.ts +0 -22
- package/lib/utils.js +0 -201
- /package/lib/{parts → hooks}/use-observable-force-rerender.d.ts +0 -0
- /package/lib/{parts → hooks}/use-observable-force-rerender.js +0 -0
- /package/lib/{parts → utils}/throttle.js +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export type { NativeSelectProps } from './
|
|
5
|
-
export { default as Multiselect } from './parts/multiselect';
|
|
6
|
-
export type { MultiselectProps } from './parts/multiselect';
|
|
1
|
+
export { Select } from './select';
|
|
2
|
+
export { Multiselect } from './multiselect';
|
|
3
|
+
export { NativeSelect } from './native-select';
|
|
4
|
+
export type { SelectProps, MultiselectProps, NativeSelectProps, SelectOption, Key } from './types';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import './index.css';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { Select } from './select.js';
|
|
3
|
+
export { Multiselect } from './multiselect.js';
|
|
4
|
+
export { NativeSelect } from './native-select.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import type { MultiselectProps, NoOptionsMessage, SelectOption, SelectOptionOrGroup } from './types';
|
|
4
|
+
export declare function Multiselect({ options, value, onChange, error, note, size, mode, theme: themeFromProps, placement, isSingleLine, boldLabel, reserveErrorLine, maxVisibleItems, isClearable, isLoading, isDisabled, ...props }: MultiselectProps): JSX.Element;
|
|
5
|
+
export declare namespace Multiselect {
|
|
6
|
+
var propTypes: {
|
|
7
|
+
className: PropTypes.Requireable<string>;
|
|
8
|
+
style: PropTypes.Requireable<object>;
|
|
9
|
+
options: React.Validator<SelectOptionOrGroup[]>;
|
|
10
|
+
value: React.Validator<SelectOption[]>;
|
|
11
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
12
|
+
size: PropTypes.Requireable<string>;
|
|
13
|
+
mode: PropTypes.Requireable<string>;
|
|
14
|
+
theme: PropTypes.Requireable<string>;
|
|
15
|
+
placeholder: PropTypes.Requireable<string>;
|
|
16
|
+
isSingleLine: PropTypes.Requireable<boolean>;
|
|
17
|
+
isClearable: PropTypes.Requireable<boolean>;
|
|
18
|
+
isDisabled: PropTypes.Requireable<boolean>;
|
|
19
|
+
isLoading: PropTypes.Requireable<boolean>;
|
|
20
|
+
error: React.Validator<React.ReactNode>;
|
|
21
|
+
label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
22
|
+
note: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
23
|
+
id: PropTypes.Requireable<string>;
|
|
24
|
+
noOptionsMessage: React.Validator<NoOptionsMessage>;
|
|
25
|
+
placement: PropTypes.Requireable<string>;
|
|
26
|
+
name: PropTypes.Requireable<string>;
|
|
27
|
+
boldLabel: PropTypes.Requireable<boolean>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useRef } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { useSelectState } from 'react-stately';
|
|
6
|
+
import { useSelect, useButton, useFocusRing, mergeProps, HiddenSelect } from 'react-aria';
|
|
7
|
+
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
8
|
+
import { ErrorMessage } from '@rescui/form-field';
|
|
9
|
+
import { optionType, optionsGroupType, noOptionsMessageType } from './common-prop-types.js';
|
|
10
|
+
import { PopupContent } from './parts/popup-content.js';
|
|
11
|
+
import { Icons } from './parts/icons.js';
|
|
12
|
+
import { FormTriggerWrapper } from './parts/form-trigger-wrapper.js';
|
|
13
|
+
import { MultiTrigger } from './parts/multi-trigger.js';
|
|
14
|
+
import { useLabelFocus } from './hooks/use-label-focus.js';
|
|
15
|
+
import { useMultiOptionSerialization } from './hooks/use-multi-option-serialization.js';
|
|
16
|
+
import { getEmptyMessage } from './utils/get-empty-message.js';
|
|
17
|
+
import { convertOptions } from './utils/convert-options.js';
|
|
18
|
+
import { convertPlacement } from './utils/convert-placement.js';
|
|
19
|
+
import { getOptionValue } from './utils/get-option-value.js';
|
|
20
|
+
import styles from './styles/common.p.module.css.js';
|
|
21
|
+
const THEME_STYLES = {
|
|
22
|
+
light: styles.themeLight,
|
|
23
|
+
dark: styles.themeDark
|
|
24
|
+
};
|
|
25
|
+
const SIZE_STYLES = {
|
|
26
|
+
s: styles.sizeS,
|
|
27
|
+
m: styles.sizeM,
|
|
28
|
+
l: styles.sizeL
|
|
29
|
+
};
|
|
30
|
+
const MODE_STYLES = {
|
|
31
|
+
classic: styles.classic,
|
|
32
|
+
rock: styles.rock
|
|
33
|
+
}; // eslint-disable-next-line complexity
|
|
34
|
+
|
|
35
|
+
function MultiselectInner(_ref) {
|
|
36
|
+
let {
|
|
37
|
+
id,
|
|
38
|
+
size,
|
|
39
|
+
mode,
|
|
40
|
+
theme,
|
|
41
|
+
style,
|
|
42
|
+
className,
|
|
43
|
+
isClearable,
|
|
44
|
+
isLoading,
|
|
45
|
+
placement,
|
|
46
|
+
boldLabel,
|
|
47
|
+
reserveErrorLine,
|
|
48
|
+
noOptionsMessage,
|
|
49
|
+
maxVisibleItems,
|
|
50
|
+
isSingleLine,
|
|
51
|
+
...ariaProps
|
|
52
|
+
} = _ref;
|
|
53
|
+
// Create state with multiple selection mode
|
|
54
|
+
const state = useSelectState({ ...ariaProps,
|
|
55
|
+
selectionMode: 'multiple',
|
|
56
|
+
allowsEmptyCollection: true
|
|
57
|
+
});
|
|
58
|
+
const hasValue = state.selectedItems.length > 0; // Get props for child elements from useSelect
|
|
59
|
+
|
|
60
|
+
const triggerRef = useRef(null);
|
|
61
|
+
const {
|
|
62
|
+
labelProps,
|
|
63
|
+
triggerProps,
|
|
64
|
+
valueProps,
|
|
65
|
+
menuProps: listBoxProps,
|
|
66
|
+
hiddenSelectProps,
|
|
67
|
+
errorMessageProps,
|
|
68
|
+
descriptionProps
|
|
69
|
+
} = useSelect({ ...ariaProps,
|
|
70
|
+
selectionMode: 'multiple',
|
|
71
|
+
onKeyDown: e => {
|
|
72
|
+
if (hasValue) {
|
|
73
|
+
if (e.key === 'Backspace') {
|
|
74
|
+
state.setValue([...state.selectedItems].map(item => item.key).slice(0, -1));
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (e.key === 'Delete') {
|
|
79
|
+
state.setValue([]);
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, state, triggerRef);
|
|
85
|
+
const {
|
|
86
|
+
buttonProps
|
|
87
|
+
} = useButton({ ...triggerProps,
|
|
88
|
+
elementType: 'div'
|
|
89
|
+
}, triggerRef);
|
|
90
|
+
const isDisabled = ariaProps.isDisabled;
|
|
91
|
+
const isOpen = state.isOpen;
|
|
92
|
+
const {
|
|
93
|
+
isFocusVisible,
|
|
94
|
+
focusProps
|
|
95
|
+
} = useFocusRing({
|
|
96
|
+
within: true
|
|
97
|
+
});
|
|
98
|
+
const {
|
|
99
|
+
isFocusedByLabel,
|
|
100
|
+
labelClickProps,
|
|
101
|
+
triggerFocusProps: labelFocusForTriggerProps
|
|
102
|
+
} = useLabelFocus(triggerRef);
|
|
103
|
+
const emptyListMessage = getEmptyMessage({
|
|
104
|
+
isLoading,
|
|
105
|
+
isNothingFound: false,
|
|
106
|
+
noOptionsMessage
|
|
107
|
+
});
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: cn(className, styles.root, THEME_STYLES[theme], SIZE_STYLES[size], MODE_STYLES[mode], isDisabled ? styles.disabled : styles.enabled, Boolean(ariaProps.errorMessage) && styles.error),
|
|
110
|
+
id: id,
|
|
111
|
+
style: style,
|
|
112
|
+
"data-test": "multiselect"
|
|
113
|
+
}, /*#__PURE__*/React.createElement(FormTriggerWrapper, {
|
|
114
|
+
theme: theme,
|
|
115
|
+
size: size,
|
|
116
|
+
disabled: isDisabled,
|
|
117
|
+
label: ariaProps.label,
|
|
118
|
+
labelProps: mergeProps(labelClickProps, labelProps),
|
|
119
|
+
boldLabel: boldLabel,
|
|
120
|
+
error: ariaProps.errorMessage,
|
|
121
|
+
reserveErrorLine: reserveErrorLine,
|
|
122
|
+
errorMessageProps: errorMessageProps,
|
|
123
|
+
note: ariaProps.description,
|
|
124
|
+
descriptionProps: descriptionProps
|
|
125
|
+
}, /*#__PURE__*/React.createElement(HiddenSelect, { ...hiddenSelectProps
|
|
126
|
+
}), /*#__PURE__*/React.createElement("div", { ...mergeProps(buttonProps, focusProps, labelFocusForTriggerProps),
|
|
127
|
+
ref: triggerRef,
|
|
128
|
+
className: cn(styles.trigger, !isSingleLine && styles.canBeMultiline),
|
|
129
|
+
"data-open": isOpen,
|
|
130
|
+
"data-focus-visible": isFocusVisible,
|
|
131
|
+
"data-label-focused": isFocusedByLabel,
|
|
132
|
+
"data-test": "multiselect__trigger"
|
|
133
|
+
}, /*#__PURE__*/React.createElement(MultiTrigger, {
|
|
134
|
+
state: state,
|
|
135
|
+
valueProps: valueProps,
|
|
136
|
+
isSingleLine: isSingleLine,
|
|
137
|
+
isDisabled: isDisabled,
|
|
138
|
+
placeholder: ariaProps.placeholder,
|
|
139
|
+
triggerRef: triggerRef
|
|
140
|
+
}), /*#__PURE__*/React.createElement(Icons, {
|
|
141
|
+
isLoading: isLoading,
|
|
142
|
+
canHaveClearIcon: isClearable && !isDisabled && hasValue,
|
|
143
|
+
onClear: () => {
|
|
144
|
+
var _triggerRef$current;
|
|
145
|
+
|
|
146
|
+
state.setValue([]);
|
|
147
|
+
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus();
|
|
148
|
+
},
|
|
149
|
+
triggerId: triggerProps.id
|
|
150
|
+
})), /*#__PURE__*/React.createElement(PopupContent, {
|
|
151
|
+
theme: theme,
|
|
152
|
+
state: state,
|
|
153
|
+
triggerRef: triggerRef,
|
|
154
|
+
placement: placement,
|
|
155
|
+
size: size,
|
|
156
|
+
mode: mode,
|
|
157
|
+
listBoxProps: listBoxProps,
|
|
158
|
+
emptyListMessage: emptyListMessage,
|
|
159
|
+
maxVisibleItems: maxVisibleItems,
|
|
160
|
+
selectionMode: "multiple"
|
|
161
|
+
})));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function Multiselect(_ref2) {
|
|
165
|
+
let {
|
|
166
|
+
options = [],
|
|
167
|
+
value,
|
|
168
|
+
onChange,
|
|
169
|
+
error,
|
|
170
|
+
note,
|
|
171
|
+
size = 'm',
|
|
172
|
+
mode = 'classic',
|
|
173
|
+
theme: themeFromProps,
|
|
174
|
+
placement = 'bottom',
|
|
175
|
+
isSingleLine = false,
|
|
176
|
+
boldLabel = true,
|
|
177
|
+
reserveErrorLine = false,
|
|
178
|
+
maxVisibleItems = 5,
|
|
179
|
+
isClearable = false,
|
|
180
|
+
isLoading = false,
|
|
181
|
+
isDisabled = false,
|
|
182
|
+
...props
|
|
183
|
+
} = _ref2;
|
|
184
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
185
|
+
const {
|
|
186
|
+
selectedKeys,
|
|
187
|
+
findOptionsByKeys,
|
|
188
|
+
virtualOptions
|
|
189
|
+
} = useMultiOptionSerialization(options, value);
|
|
190
|
+
|
|
191
|
+
const handleSelectionChange = keys => {
|
|
192
|
+
const newValue = findOptionsByKeys(keys);
|
|
193
|
+
onChange === null || onChange === void 0 || onChange(newValue);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return /*#__PURE__*/React.createElement(MultiselectInner, { ...props,
|
|
197
|
+
size: size,
|
|
198
|
+
mode: mode,
|
|
199
|
+
theme: theme,
|
|
200
|
+
value: selectedKeys,
|
|
201
|
+
onChange: handleSelectionChange,
|
|
202
|
+
errorMessage: error,
|
|
203
|
+
description: note,
|
|
204
|
+
placement: convertPlacement(placement),
|
|
205
|
+
isSingleLine: isSingleLine,
|
|
206
|
+
disabledKeys: virtualOptions.map(option => getOptionValue(option)),
|
|
207
|
+
boldLabel: boldLabel,
|
|
208
|
+
reserveErrorLine: reserveErrorLine,
|
|
209
|
+
maxVisibleItems: maxVisibleItems,
|
|
210
|
+
isClearable: isClearable,
|
|
211
|
+
isLoading: isLoading,
|
|
212
|
+
isDisabled: isDisabled
|
|
213
|
+
}, convertOptions(options, virtualOptions));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
Multiselect.propTypes = {
|
|
217
|
+
className: PropTypes.string,
|
|
218
|
+
style: PropTypes.object,
|
|
219
|
+
options: PropTypes.arrayOf(PropTypes.oneOfType([optionType, optionsGroupType])),
|
|
220
|
+
value: PropTypes.arrayOf(optionType),
|
|
221
|
+
onChange: PropTypes.func,
|
|
222
|
+
size: PropTypes.oneOf(['m', 's', 'l']),
|
|
223
|
+
mode: PropTypes.oneOf(['classic', 'rock']),
|
|
224
|
+
theme: PropTypes.oneOf(['light', 'dark']),
|
|
225
|
+
placeholder: PropTypes.string,
|
|
226
|
+
isSingleLine: PropTypes.bool,
|
|
227
|
+
isClearable: PropTypes.bool,
|
|
228
|
+
isDisabled: PropTypes.bool,
|
|
229
|
+
isLoading: PropTypes.bool,
|
|
230
|
+
error: ErrorMessage.propTypes.children,
|
|
231
|
+
label: PropTypes.node,
|
|
232
|
+
note: PropTypes.node,
|
|
233
|
+
id: PropTypes.string,
|
|
234
|
+
noOptionsMessage: noOptionsMessageType,
|
|
235
|
+
placement: PropTypes.oneOf(['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start']),
|
|
236
|
+
name: PropTypes.string,
|
|
237
|
+
boldLabel: PropTypes.bool
|
|
238
|
+
};
|
|
239
|
+
export { Multiselect };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
6
|
+
import { ErrorMessage } from '@rescui/form-field';
|
|
7
|
+
import { useField, useFocusRing, mergeProps } from 'react-aria';
|
|
8
|
+
import { nativeOptionType, nativeOptionsGroupType, noOptionsMessageType } from './common-prop-types.js';
|
|
9
|
+
import { FormTriggerWrapper } from './parts/form-trigger-wrapper.js';
|
|
10
|
+
import { isOptionAGroup } from './utils/is-option-a-group.js';
|
|
11
|
+
import { getEmptyMessage } from './utils/get-empty-message.js';
|
|
12
|
+
import { useLabelFocus } from './hooks/use-label-focus.js';
|
|
13
|
+
import { NativeSelectTrigger } from './parts/native-select-trigger.js';
|
|
14
|
+
import { NativeSelectOptionsWithGroups } from './parts/native-select-options-with-groups.js';
|
|
15
|
+
import styles from './styles/native-select.p.module.css.js';
|
|
16
|
+
|
|
17
|
+
function findSelectedOption(options, selectedValue) {
|
|
18
|
+
let result = null;
|
|
19
|
+
|
|
20
|
+
const checkOption = option => {
|
|
21
|
+
if (result === null || option.value === selectedValue) {
|
|
22
|
+
result = option;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
options.forEach(optionOrGroup => {
|
|
27
|
+
if (isOptionAGroup(optionOrGroup)) {
|
|
28
|
+
var _group$options;
|
|
29
|
+
|
|
30
|
+
const group = optionOrGroup;
|
|
31
|
+
(_group$options = group.options) === null || _group$options === void 0 || _group$options.forEach(checkOption);
|
|
32
|
+
} else {
|
|
33
|
+
checkOption(optionOrGroup);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const SIZE_STYLES = {
|
|
40
|
+
s: styles.sizeS,
|
|
41
|
+
m: styles.sizeM,
|
|
42
|
+
l: styles.sizeL
|
|
43
|
+
}; // eslint-disable-next-line complexity
|
|
44
|
+
|
|
45
|
+
const NativeSelect = _ref => {
|
|
46
|
+
let {
|
|
47
|
+
options = [],
|
|
48
|
+
size = 'm',
|
|
49
|
+
theme: themeFromProps,
|
|
50
|
+
className = null,
|
|
51
|
+
id,
|
|
52
|
+
style,
|
|
53
|
+
value,
|
|
54
|
+
onChange,
|
|
55
|
+
placeholder,
|
|
56
|
+
isLoading = false,
|
|
57
|
+
isDisabled = false,
|
|
58
|
+
trigger,
|
|
59
|
+
label,
|
|
60
|
+
note,
|
|
61
|
+
error,
|
|
62
|
+
reserveErrorLine = false,
|
|
63
|
+
noOptionsMessage,
|
|
64
|
+
name,
|
|
65
|
+
boldLabel = true,
|
|
66
|
+
...ariaRestProps
|
|
67
|
+
} = _ref;
|
|
68
|
+
const {
|
|
69
|
+
labelProps,
|
|
70
|
+
fieldProps,
|
|
71
|
+
descriptionProps,
|
|
72
|
+
errorMessageProps
|
|
73
|
+
} = useField({ ...ariaRestProps,
|
|
74
|
+
label,
|
|
75
|
+
description: note,
|
|
76
|
+
errorMessage: error
|
|
77
|
+
});
|
|
78
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
79
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
80
|
+
|
|
81
|
+
const handleChange = event => {
|
|
82
|
+
const newValue = event.target.value;
|
|
83
|
+
const selectedOption = findSelectedOption(options, newValue);
|
|
84
|
+
|
|
85
|
+
if (onChange) {
|
|
86
|
+
onChange(selectedOption);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const triggerRef = React.useRef(null);
|
|
91
|
+
const {
|
|
92
|
+
isFocusVisible,
|
|
93
|
+
focusProps
|
|
94
|
+
} = useFocusRing({
|
|
95
|
+
within: true
|
|
96
|
+
});
|
|
97
|
+
const {
|
|
98
|
+
isFocusedByLabel,
|
|
99
|
+
labelClickProps,
|
|
100
|
+
triggerFocusProps: labelFocusForTriggerProps
|
|
101
|
+
} = useLabelFocus(triggerRef);
|
|
102
|
+
const isFocused = isFocusedByLabel || isFocusVisible;
|
|
103
|
+
const emptyListMessage = getEmptyMessage({
|
|
104
|
+
isLoading,
|
|
105
|
+
isNothingFound: false,
|
|
106
|
+
noOptionsMessage
|
|
107
|
+
});
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: cn(className, styles.main, SIZE_STYLES[size]),
|
|
110
|
+
id: id,
|
|
111
|
+
style: style,
|
|
112
|
+
"data-test": "native-select"
|
|
113
|
+
}, /*#__PURE__*/React.createElement(FormTriggerWrapper, {
|
|
114
|
+
theme: theme,
|
|
115
|
+
size: size,
|
|
116
|
+
disabled: isDisabled,
|
|
117
|
+
label: label,
|
|
118
|
+
labelProps: mergeProps(labelClickProps, labelProps),
|
|
119
|
+
boldLabel: boldLabel,
|
|
120
|
+
error: error,
|
|
121
|
+
errorMessageProps: errorMessageProps,
|
|
122
|
+
reserveErrorLine: reserveErrorLine,
|
|
123
|
+
note: note,
|
|
124
|
+
descriptionProps: descriptionProps
|
|
125
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
126
|
+
className: styles.wrapper
|
|
127
|
+
}, trigger ? trigger({
|
|
128
|
+
focused: isFocused,
|
|
129
|
+
hovered: isHovered,
|
|
130
|
+
selectedLabel: value === null || value === void 0 ? void 0 : value.label,
|
|
131
|
+
selectedValue: value === null || value === void 0 ? void 0 : value.value,
|
|
132
|
+
placeholder
|
|
133
|
+
}) : /*#__PURE__*/React.createElement(NativeSelectTrigger, {
|
|
134
|
+
value: value,
|
|
135
|
+
isLoading: isLoading,
|
|
136
|
+
isFocused: isFocused,
|
|
137
|
+
isHovered: isHovered,
|
|
138
|
+
isDisabled: isDisabled,
|
|
139
|
+
size: size,
|
|
140
|
+
theme: theme,
|
|
141
|
+
hasError: Boolean(error),
|
|
142
|
+
placeholder: placeholder
|
|
143
|
+
}), /*#__PURE__*/React.createElement("select", { ...mergeProps(fieldProps, focusProps, labelFocusForTriggerProps, {
|
|
144
|
+
onMouseEnter: () => setIsHovered(true),
|
|
145
|
+
onMouseLeave: () => setIsHovered(false)
|
|
146
|
+
}),
|
|
147
|
+
ref: triggerRef,
|
|
148
|
+
"data-test": "native-select_select",
|
|
149
|
+
"data-rs-internal": 'select-native__select',
|
|
150
|
+
className: styles.select,
|
|
151
|
+
disabled: isDisabled ? true : undefined,
|
|
152
|
+
onChange: handleChange,
|
|
153
|
+
name: name,
|
|
154
|
+
value: (value === null || value === void 0 ? void 0 : value.value) ?? ''
|
|
155
|
+
}, /*#__PURE__*/React.createElement(NativeSelectOptionsWithGroups, {
|
|
156
|
+
optionsWithGroups: options,
|
|
157
|
+
placeholder: placeholder,
|
|
158
|
+
emptyListMessage: emptyListMessage
|
|
159
|
+
})))));
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
NativeSelect.propTypes = {
|
|
163
|
+
className: PropTypes.string,
|
|
164
|
+
style: PropTypes.object,
|
|
165
|
+
id: PropTypes.string,
|
|
166
|
+
options: PropTypes.arrayOf(PropTypes.oneOfType([nativeOptionType, nativeOptionsGroupType])),
|
|
167
|
+
value: nativeOptionType,
|
|
168
|
+
onChange: PropTypes.func,
|
|
169
|
+
size: PropTypes.oneOf(['m', 's', 'l']),
|
|
170
|
+
theme: PropTypes.oneOf(['light', 'dark']),
|
|
171
|
+
placeholder: PropTypes.string,
|
|
172
|
+
isDisabled: PropTypes.bool,
|
|
173
|
+
isLoading: PropTypes.bool,
|
|
174
|
+
trigger: PropTypes.func,
|
|
175
|
+
error: ErrorMessage.propTypes.children,
|
|
176
|
+
label: PropTypes.node,
|
|
177
|
+
note: PropTypes.node,
|
|
178
|
+
noOptionsMessage: noOptionsMessageType,
|
|
179
|
+
name: PropTypes.string,
|
|
180
|
+
boldLabel: PropTypes.bool
|
|
181
|
+
};
|
|
182
|
+
export { NativeSelect, NativeSelect as default };
|
package/lib/parts/foldable.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import React, { Component } from 'react';
|
|
3
|
-
import { throttle } from '
|
|
2
|
+
import { throttle } from '../utils/throttle.js';
|
|
4
3
|
|
|
5
4
|
function lastVisibleIndex(lens, maxLen, gap) {
|
|
6
5
|
let extra = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
@@ -195,12 +194,11 @@ class Foldable extends Component {
|
|
|
195
194
|
const children = React.Children.toArray(_this.props.children);
|
|
196
195
|
const showLastChildIfFit = index === children.length - 2 && extra - gap - 1 > _this.childrenWidths[_this.childrenWidths.length - 1];
|
|
197
196
|
const newLastVisible = index + (showLastChildIfFit ? 1 : 0);
|
|
198
|
-
const newState = {
|
|
199
|
-
lastVisible: newLastVisible,
|
|
200
|
-
renderingStage: nextStage ? nextStage : _this.state.renderingStage
|
|
201
|
-
};
|
|
202
197
|
|
|
203
|
-
_this.setState(
|
|
198
|
+
_this.setState(prevState => ({ ...prevState,
|
|
199
|
+
lastVisible: newLastVisible,
|
|
200
|
+
renderingStage: nextStage ?? prevState.renderingStage
|
|
201
|
+
}));
|
|
204
202
|
};
|
|
205
203
|
})();
|
|
206
204
|
|
|
@@ -5,12 +5,30 @@ export declare type FormTriggerWrapperProps = {
|
|
|
5
5
|
size?: SelectSize;
|
|
6
6
|
theme?: Theme;
|
|
7
7
|
className?: string;
|
|
8
|
+
disabled?: boolean;
|
|
8
9
|
error?: boolean | React.ReactNode;
|
|
10
|
+
reserveErrorLine?: boolean;
|
|
11
|
+
errorMessageProps?: object;
|
|
9
12
|
label?: React.ReactNode;
|
|
13
|
+
labelProps?: object;
|
|
10
14
|
note?: React.ReactNode;
|
|
11
|
-
|
|
15
|
+
descriptionProps?: object;
|
|
12
16
|
boldLabel?: boolean;
|
|
13
17
|
children?: React.ReactNode;
|
|
14
|
-
}
|
|
15
|
-
declare const FormTriggerWrapper: React.ForwardRefExoticComponent<
|
|
18
|
+
} & React.HTMLAttributes<HTMLDivElement>;
|
|
19
|
+
export declare const FormTriggerWrapper: React.ForwardRefExoticComponent<{
|
|
20
|
+
size?: SelectSize;
|
|
21
|
+
theme?: Theme;
|
|
22
|
+
className?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
error?: boolean | React.ReactNode;
|
|
25
|
+
reserveErrorLine?: boolean;
|
|
26
|
+
errorMessageProps?: object;
|
|
27
|
+
label?: React.ReactNode;
|
|
28
|
+
labelProps?: object;
|
|
29
|
+
note?: React.ReactNode;
|
|
30
|
+
descriptionProps?: object;
|
|
31
|
+
boldLabel?: boolean;
|
|
32
|
+
children?: React.ReactNode;
|
|
33
|
+
} & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
16
34
|
export default FormTriggerWrapper;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import cn from 'classnames';
|
|
4
3
|
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
5
|
-
import
|
|
6
|
-
import styles from '
|
|
4
|
+
import { shouldRenderErrorMessage, ErrorMessage } from '@rescui/form-field';
|
|
5
|
+
import styles from '../styles/form-trigger.p.module.css.js';
|
|
7
6
|
const SIZE_STYLES = {
|
|
8
7
|
l: styles.sizeL,
|
|
9
8
|
m: styles.sizeM,
|
|
@@ -13,56 +12,47 @@ const THEME_STYLES = {
|
|
|
13
12
|
light: styles.themeLight,
|
|
14
13
|
dark: styles.themeDark
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let {
|
|
19
|
-
children,
|
|
20
|
-
boldLabel
|
|
21
|
-
} = _ref;
|
|
22
|
-
|
|
23
|
-
if (!children) {
|
|
24
|
-
return null;
|
|
25
|
-
} else {
|
|
26
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
27
|
-
className: styles.label,
|
|
28
|
-
"data-rs-internal": boldLabel ? 'select-form-trigger-wrapper__bold-label' : 'select-form-trigger-wrapper__label'
|
|
29
|
-
}, children);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const FormTriggerWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
15
|
+
const FormTriggerWrapper = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
|
|
16
|
+
(_ref, ref) => {
|
|
34
17
|
let {
|
|
35
18
|
size,
|
|
36
19
|
theme: themeFromProps,
|
|
37
20
|
className,
|
|
21
|
+
disabled,
|
|
38
22
|
error,
|
|
23
|
+
reserveErrorLine = false,
|
|
24
|
+
errorMessageProps,
|
|
39
25
|
label,
|
|
26
|
+
labelProps,
|
|
40
27
|
note,
|
|
28
|
+
descriptionProps,
|
|
41
29
|
children,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} =
|
|
30
|
+
boldLabel,
|
|
31
|
+
...restProps
|
|
32
|
+
} = _ref;
|
|
45
33
|
const theme = useThemeWithUndefined(themeFromProps);
|
|
34
|
+
const hasFooter = Boolean(note) || shouldRenderErrorMessage(error, reserveErrorLine);
|
|
46
35
|
return /*#__PURE__*/React.createElement("div", {
|
|
47
|
-
className: cn(className, styles.main, SIZE_STYLES[size], THEME_STYLES[theme]),
|
|
36
|
+
className: cn(className, styles.main, SIZE_STYLES[size], THEME_STYLES[theme], Boolean(error) && styles.error, disabled && styles.disabled),
|
|
48
37
|
ref: ref,
|
|
49
38
|
"data-test": "select-wrapper",
|
|
50
|
-
"data-rs-internal": 'select-form-trigger-wrapper'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
"data-rs-internal": 'select-form-trigger-wrapper',
|
|
40
|
+
...restProps
|
|
41
|
+
}, label && /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
className: styles.label,
|
|
43
|
+
"data-rs-internal": boldLabel ? 'select-form-trigger-wrapper__bold-label' : 'select-form-trigger-wrapper__label',
|
|
44
|
+
...labelProps
|
|
45
|
+
}, label), children, hasFooter && /*#__PURE__*/React.createElement("div", {
|
|
46
|
+
className: styles.footer
|
|
47
|
+
}, /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
56
48
|
className: styles.errorMessage,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"data-rs-internal": 'select-form-trigger-wrapper__error-icon',
|
|
61
|
-
"data-render-all-sizes": true
|
|
62
|
-
}), /*#__PURE__*/React.createElement("span", null, error)), note && /*#__PURE__*/React.createElement("div", {
|
|
49
|
+
reserveLine: reserveErrorLine,
|
|
50
|
+
...errorMessageProps
|
|
51
|
+
}, error), note && /*#__PURE__*/React.createElement("div", {
|
|
63
52
|
className: styles.note,
|
|
64
|
-
"data-rs-internal": 'select-form-trigger-wrapper__note'
|
|
65
|
-
|
|
53
|
+
"data-rs-internal": 'select-form-trigger-wrapper__note',
|
|
54
|
+
...descriptionProps
|
|
55
|
+
}, note)));
|
|
66
56
|
});
|
|
67
57
|
FormTriggerWrapper.displayName = 'FormTriggerWrapper';
|
|
68
|
-
export { FormTriggerWrapper as default };
|
|
58
|
+
export { FormTriggerWrapper, FormTriggerWrapper as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type ClearOrLoadingProps = {
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
canHaveClearIcon: boolean;
|
|
5
|
+
onClearClick: () => void;
|
|
6
|
+
triggerId?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const ClearOrLoading: React.FC<ClearOrLoadingProps>;
|
|
10
|
+
export declare type IconsProps = {
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
canHaveClearIcon?: boolean;
|
|
13
|
+
onClear?: () => void;
|
|
14
|
+
triggerId?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const Icons: ({ isLoading, canHaveClearIcon, onClear, triggerId }: IconsProps) => JSX.Element;
|
|
17
|
+
export {};
|