@rentnerkev/select 1.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -83
- package/dist/Components/SelectView.d.ts +12 -0
- package/dist/Components/SelectView.d.ts.map +1 -0
- package/dist/Components/SelectView.js +90 -0
- package/dist/Components/SelectView.js.map +1 -0
- package/dist/Hooks/useSelect.logic.d.ts +69 -0
- package/dist/Hooks/useSelect.logic.d.ts.map +1 -0
- package/dist/Hooks/useSelect.logic.js +197 -0
- package/dist/Hooks/useSelect.logic.js.map +1 -0
- package/dist/Select.d.ts +6 -2
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +34 -154
- package/dist/Select.js.map +1 -1
- package/dist/i18n.d.ts +13 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +29 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/selectValue.d.ts +4 -0
- package/dist/selectValue.d.ts.map +1 -0
- package/dist/selectValue.js +14 -0
- package/dist/selectValue.js.map +1 -0
- package/dist/types.d.ts +28 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +34 -12
- package/tailwind.css +14 -0
- package/dist/Internal/Tooltip.d.ts +0 -16
- package/dist/Internal/Tooltip.d.ts.map +0 -1
- package/dist/Internal/Tooltip.js +0 -13
- package/dist/Internal/Tooltip.js.map +0 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
2
|
+
import { resolveSelectMessages, } from '../i18n.js';
|
|
3
|
+
export default function useSelectLogic({ id, options, selectedValues, multiple, required = false, externalError, disabled = false, readOnly = false, triggerRef, minSelection, maxSelection, locale = 'de', messages: providedMessages, isOptionEqualToValue: isOptionEqualToValueProp, onSelectValue, }) {
|
|
4
|
+
const messages = resolveSelectMessages(locale, providedMessages);
|
|
5
|
+
const [open, setOpen] = useState(false);
|
|
6
|
+
const interactionDisabled = disabled || readOnly;
|
|
7
|
+
const [previousInteractionDisabled, setPreviousInteractionDisabled] = useState(interactionDisabled);
|
|
8
|
+
const [searchValue, setSearchValue] = useState('');
|
|
9
|
+
const [isTouched, setIsTouched] = useState(false);
|
|
10
|
+
const searchInputRef = useRef(null);
|
|
11
|
+
const validationInputRef = useRef(null);
|
|
12
|
+
const internalTriggerRef = useRef(null);
|
|
13
|
+
const shouldKeepOpen = useRef(false);
|
|
14
|
+
const generatedId = useId();
|
|
15
|
+
const triggerId = id ?? `select-${generatedId}`;
|
|
16
|
+
const labelId = `${triggerId}-label`;
|
|
17
|
+
const descriptionId = `${triggerId}-description`;
|
|
18
|
+
const errorId = `${triggerId}-error`;
|
|
19
|
+
const isOptionEqualToValue = isOptionEqualToValueProp ?? Object.is;
|
|
20
|
+
const optionEntries = useMemo(() => options.map((option, index) => ({
|
|
21
|
+
option,
|
|
22
|
+
radixValue: `option-${index}`,
|
|
23
|
+
})), [options]);
|
|
24
|
+
const filteredOptions = useMemo(() => {
|
|
25
|
+
const normalizedSearch = searchValue.trim().toLowerCase();
|
|
26
|
+
if (!normalizedSearch)
|
|
27
|
+
return optionEntries;
|
|
28
|
+
return optionEntries.filter(({ option }) => {
|
|
29
|
+
const optionLabel = option.label.toLowerCase();
|
|
30
|
+
const optionValue = String(option.value).toLowerCase();
|
|
31
|
+
const subOption = option.subOption?.toLowerCase() || '';
|
|
32
|
+
return (optionLabel.includes(normalizedSearch) ||
|
|
33
|
+
optionValue.includes(normalizedSearch) ||
|
|
34
|
+
subOption.includes(normalizedSearch));
|
|
35
|
+
});
|
|
36
|
+
}, [optionEntries, searchValue]);
|
|
37
|
+
const selectedEntries = useMemo(() => optionEntries.filter(({ option }) => selectedValues.some((value) => isOptionEqualToValue(option.value, value))), [isOptionEqualToValue, optionEntries, selectedValues]);
|
|
38
|
+
const selectedRadixValue = multiple
|
|
39
|
+
? ''
|
|
40
|
+
: (selectedEntries[0]?.radixValue ?? '');
|
|
41
|
+
const internalError = useMemo(() => {
|
|
42
|
+
if (required && selectedValues.length === 0)
|
|
43
|
+
return messages.required;
|
|
44
|
+
if (multiple &&
|
|
45
|
+
minSelection !== undefined &&
|
|
46
|
+
selectedValues.length < minSelection) {
|
|
47
|
+
return messages.minSelection(minSelection);
|
|
48
|
+
}
|
|
49
|
+
if (multiple &&
|
|
50
|
+
maxSelection !== undefined &&
|
|
51
|
+
selectedValues.length > maxSelection) {
|
|
52
|
+
return messages.maxSelection(maxSelection);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}, [
|
|
56
|
+
maxSelection,
|
|
57
|
+
messages,
|
|
58
|
+
minSelection,
|
|
59
|
+
multiple,
|
|
60
|
+
required,
|
|
61
|
+
selectedValues,
|
|
62
|
+
]);
|
|
63
|
+
const resolvedError = externalError !== undefined ? externalError : internalError;
|
|
64
|
+
const hasError = externalError !== undefined
|
|
65
|
+
? Boolean(resolvedError)
|
|
66
|
+
: isTouched && Boolean(resolvedError);
|
|
67
|
+
const setTriggerRef = useCallback((node) => {
|
|
68
|
+
internalTriggerRef.current = node;
|
|
69
|
+
if (typeof triggerRef === 'function')
|
|
70
|
+
triggerRef(node);
|
|
71
|
+
}, [triggerRef]);
|
|
72
|
+
useImperativeHandle(typeof triggerRef === 'object' ? triggerRef : null, () => internalTriggerRef.current);
|
|
73
|
+
const focusSearchInput = useCallback(() => {
|
|
74
|
+
requestAnimationFrame(() => searchInputRef.current?.focus());
|
|
75
|
+
window.setTimeout(() => searchInputRef.current?.focus(), 0);
|
|
76
|
+
}, []);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (open)
|
|
79
|
+
focusSearchInput();
|
|
80
|
+
}, [focusSearchInput, open]);
|
|
81
|
+
if (previousInteractionDisabled !== interactionDisabled) {
|
|
82
|
+
setPreviousInteractionDisabled(interactionDisabled);
|
|
83
|
+
if (interactionDisabled && open) {
|
|
84
|
+
setOpen(false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
validationInputRef.current?.setCustomValidity(disabled ? '' : resolvedError || '');
|
|
89
|
+
}, [disabled, resolvedError]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
const input = validationInputRef.current;
|
|
92
|
+
const form = input?.form;
|
|
93
|
+
if (!input || !form)
|
|
94
|
+
return;
|
|
95
|
+
const currentInput = input;
|
|
96
|
+
function handleFormSubmit() {
|
|
97
|
+
if (currentInput.validity.valid)
|
|
98
|
+
setIsTouched(false);
|
|
99
|
+
}
|
|
100
|
+
form.addEventListener('submit', handleFormSubmit);
|
|
101
|
+
return () => form.removeEventListener('submit', handleFormSubmit);
|
|
102
|
+
}, []);
|
|
103
|
+
function handleInvalid(event) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
setIsTouched(true);
|
|
106
|
+
internalTriggerRef.current?.focus();
|
|
107
|
+
}
|
|
108
|
+
function handleValueChange(nextRadixValue) {
|
|
109
|
+
if (disabled || readOnly)
|
|
110
|
+
return;
|
|
111
|
+
const entry = optionEntries.find(({ radixValue }) => radixValue === nextRadixValue);
|
|
112
|
+
if (!entry)
|
|
113
|
+
return;
|
|
114
|
+
if (!multiple)
|
|
115
|
+
setSearchValue('');
|
|
116
|
+
onSelectValue(entry.option.value);
|
|
117
|
+
}
|
|
118
|
+
function handleOpenChange(nextOpen) {
|
|
119
|
+
if (disabled || readOnly) {
|
|
120
|
+
setOpen(false);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (multiple && !nextOpen && shouldKeepOpen.current) {
|
|
124
|
+
shouldKeepOpen.current = false;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
setOpen(nextOpen);
|
|
128
|
+
if (nextOpen)
|
|
129
|
+
focusSearchInput();
|
|
130
|
+
else
|
|
131
|
+
setSearchValue('');
|
|
132
|
+
}
|
|
133
|
+
function handleContentKeyDownCapture(event) {
|
|
134
|
+
if (event.target === searchInputRef.current) {
|
|
135
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
136
|
+
const focusableOptions = Array.from(event.currentTarget.querySelectorAll('[role="option"]:not([data-disabled])'));
|
|
137
|
+
const option = event.key === 'ArrowDown'
|
|
138
|
+
? focusableOptions[0]
|
|
139
|
+
: focusableOptions[focusableOptions.length - 1];
|
|
140
|
+
if (option) {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
option.focus();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (event.ctrlKey ||
|
|
149
|
+
event.altKey ||
|
|
150
|
+
event.metaKey ||
|
|
151
|
+
event.key.length !== 1) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
event.stopPropagation();
|
|
156
|
+
setSearchValue((current) => `${current}${event.key}`);
|
|
157
|
+
focusSearchInput();
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
ref: {
|
|
161
|
+
trigger: setTriggerRef,
|
|
162
|
+
searchInput: searchInputRef,
|
|
163
|
+
validationInput: validationInputRef,
|
|
164
|
+
},
|
|
165
|
+
state: {
|
|
166
|
+
messages,
|
|
167
|
+
triggerId,
|
|
168
|
+
labelId,
|
|
169
|
+
descriptionId,
|
|
170
|
+
errorId,
|
|
171
|
+
open: open && !disabled && !readOnly,
|
|
172
|
+
searchValue,
|
|
173
|
+
optionEntries,
|
|
174
|
+
filteredOptions,
|
|
175
|
+
selectedEntries,
|
|
176
|
+
selectedRadixValue,
|
|
177
|
+
hasError,
|
|
178
|
+
resolvedError,
|
|
179
|
+
hasLeftIcon: Boolean(hasError),
|
|
180
|
+
isOptionEqualToValue,
|
|
181
|
+
},
|
|
182
|
+
handler: {
|
|
183
|
+
handleInvalid,
|
|
184
|
+
handleValueChange,
|
|
185
|
+
handleOpenChange,
|
|
186
|
+
handleContentKeyDownCapture,
|
|
187
|
+
setSearchValue,
|
|
188
|
+
},
|
|
189
|
+
setter: {
|
|
190
|
+
setOpen,
|
|
191
|
+
setSearchValue,
|
|
192
|
+
setIsTouched,
|
|
193
|
+
shouldKeepOpen,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=useSelect.logic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSelect.logic.js","sourceRoot":"","sources":["../../src/Hooks/useSelect.logic.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,SAAS,EACT,KAAK,EACL,mBAAmB,EACnB,OAAO,EACP,MAAM,EACN,QAAQ,GACX,MAAM,OAAO,CAAA;AAEd,OAAO,EACH,qBAAqB,GAGxB,MAAM,YAAY,CAAA;AAsBnB,MAAM,CAAC,OAAO,UAAU,cAAc,CAAS,EAC3C,EAAE,EACF,OAAO,EACP,cAAc,EACd,QAAQ,EACR,QAAQ,GAAG,KAAK,EAChB,aAAa,EACb,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,MAAM,GAAG,IAAI,EACb,QAAQ,EAAE,gBAAgB,EAC1B,oBAAoB,EAAE,wBAAwB,EAC9C,aAAa,GACe;IAC5B,MAAM,QAAQ,GAAG,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAChE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACvC,MAAM,mBAAmB,GAAG,QAAQ,IAAI,QAAQ,CAAA;IAChD,MAAM,CAAC,2BAA2B,EAAE,8BAA8B,CAAC,GAC/D,QAAQ,CAAC,mBAAmB,CAAC,CAAA;IACjC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;IAClD,MAAM,CAAC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QACV,CAAC;QAED,IACI,KAAK,CAAC,OAAO;YACb,KAAK,CAAC,MAAM;YACZ,KAAK,CAAC,OAAO;YACb,KAAK,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,EACxB,CAAC;YACC,OAAM;QACV,CAAC;QACD,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,KAAK,CAAC,eAAe,EAAE,CAAA;QACvB,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAA;QACrD,gBAAgB,EAAE,CAAA;IACtB,CAAC;IAED,OAAO;QACH,GAAG,EAAE;YACD,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,cAAc;YAC3B,eAAe,EAAE,kBAAkB;SACtC;QACD,KAAK,EAAE;YACH,QAAQ;YACR,SAAS;YACT,OAAO;YACP,aAAa;YACb,OAAO;YACP,IAAI,EAAE,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ;YACpC,WAAW;YACX,aAAa;YACb,eAAe;YACf,eAAe;YACf,kBAAkB;YAClB,QAAQ;YACR,aAAa;YACb,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC;YAC9B,oBAAoB;SACvB;QACD,OAAO,EAAE;YACL,aAAa;YACb,iBAAiB;YACjB,gBAAgB;YAChB,2BAA2B;YAC3B,cAAc;SACjB;QACD,MAAM,EAAE;YACJ,OAAO;YACP,cAAc;YACd,YAAY;YACZ,cAAc;SACjB;KACJ,CAAA;AACL,CAAC"}
|
package/dist/Select.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { CustomSelectProps, MultipleSelectProps, SingleSelectProps } from './types.js';
|
|
3
|
+
export declare function CustomSelect<TValue = string>(props: SingleSelectProps<TValue>): ReactElement;
|
|
4
|
+
export declare function CustomSelect<TValue = string>(props: MultipleSelectProps<TValue>): ReactElement;
|
|
5
|
+
export declare function CustomSelect<TValue = string>(props: CustomSelectProps<TValue>): ReactElement;
|
|
6
|
+
export declare function CustomSelect(props: CustomSelectProps<string>): ReactElement;
|
|
3
7
|
//# sourceMappingURL=Select.d.ts.map
|
package/dist/Select.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../src/Select.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../src/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,KAAK,EACR,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACpB,MAAM,YAAY,CAAA;AAqEnB,wBAAgB,YAAY,CAAC,MAAM,GAAG,MAAM,EACxC,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,GACjC,YAAY,CAAA;AACf,wBAAgB,YAAY,CAAC,MAAM,GAAG,MAAM,EACxC,KAAK,EAAE,mBAAmB,CAAC,MAAM,CAAC,GACnC,YAAY,CAAA;AACf,wBAAgB,YAAY,CAAC,MAAM,GAAG,MAAM,EACxC,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,GACjC,YAAY,CAAA;AACf,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAAG,YAAY,CAAA"}
|
package/dist/Select.js
CHANGED
|
@@ -1,160 +1,40 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (multiple &&
|
|
28
|
-
maxSelection !== undefined &&
|
|
29
|
-
selectedValues.length > maxSelection) {
|
|
30
|
-
return `Maximal ${maxSelection} Optionen auswählen`;
|
|
31
|
-
}
|
|
32
|
-
return null;
|
|
33
|
-
}, [required, multiple, minSelection, maxSelection, selectedValues]);
|
|
34
|
-
const hasError = isTouched && error !== null;
|
|
35
|
-
const hasLeftIcon = Boolean(icon || hasError);
|
|
36
|
-
const filteredOptions = useMemo(() => {
|
|
37
|
-
const normalizedSearch = searchValue.trim().toLowerCase();
|
|
38
|
-
if (!normalizedSearch) {
|
|
39
|
-
return options;
|
|
40
|
-
}
|
|
41
|
-
return options.filter((option) => {
|
|
42
|
-
const label = option.label.toLowerCase();
|
|
43
|
-
const optionValue = option.value.toLowerCase();
|
|
44
|
-
const subOption = option.subOption?.toLowerCase() || '';
|
|
45
|
-
return (label.includes(normalizedSearch) ||
|
|
46
|
-
optionValue.includes(normalizedSearch) ||
|
|
47
|
-
subOption.includes(normalizedSearch));
|
|
48
|
-
});
|
|
49
|
-
}, [options, searchValue]);
|
|
50
|
-
const selectedOptions = useMemo(() => {
|
|
51
|
-
return options.filter((option) => selectedValues.includes(option.value));
|
|
52
|
-
}, [options, selectedValues]);
|
|
53
|
-
function handleValueChange(nextValue) {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import SelectView from './Components/SelectView.js';
|
|
3
|
+
import { isSingleValueEmpty, toggleSelectedValue } from './selectValue.js';
|
|
4
|
+
function defaultGetFormValue(value) {
|
|
5
|
+
return String(value);
|
|
6
|
+
}
|
|
7
|
+
function TypedCustomSelect({ value, onValueChange, multiple, getFormValue = defaultGetFormValue, ...viewProps }) {
|
|
8
|
+
const isOptionEqualToValue = viewProps.isOptionEqualToValue ?? Object.is;
|
|
9
|
+
const multipleValues = multiple && Array.isArray(value) ? value : [];
|
|
10
|
+
const selectedValues = multiple
|
|
11
|
+
? multipleValues
|
|
12
|
+
: isSingleValueEmpty(value)
|
|
13
|
+
? []
|
|
14
|
+
: [value];
|
|
15
|
+
const formEntries = selectedValues.map((selectedValue) => {
|
|
16
|
+
const optionIndex = viewProps.options.findIndex((option) => isOptionEqualToValue(option.value, selectedValue));
|
|
17
|
+
const formValue = getFormValue(selectedValue);
|
|
18
|
+
return {
|
|
19
|
+
key: optionIndex >= 0
|
|
20
|
+
? `option-${optionIndex}`
|
|
21
|
+
: `${typeof selectedValue}-${formValue}`,
|
|
22
|
+
value: formValue,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
function handleSelectValue(nextValue) {
|
|
54
26
|
if (multiple) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (maxSelection !== undefined &&
|
|
59
|
-
nextArray.length > maxSelection &&
|
|
60
|
-
!selectedValues.includes(nextValue)) {
|
|
61
|
-
return;
|
|
27
|
+
const nextValues = toggleSelectedValue(multipleValues, nextValue, isOptionEqualToValue, viewProps.maxSelection);
|
|
28
|
+
if (nextValues) {
|
|
29
|
+
onValueChange(nextValues);
|
|
62
30
|
}
|
|
63
|
-
onValueChange(nextArray.join(','));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
setSearchValue('');
|
|
67
|
-
onValueChange(nextValue);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function handleInvalid(event) {
|
|
71
|
-
event.preventDefault();
|
|
72
|
-
setIsTouched(true);
|
|
73
|
-
}
|
|
74
|
-
const focusSearchInput = useCallback(() => {
|
|
75
|
-
requestAnimationFrame(() => searchInputRef.current?.focus());
|
|
76
|
-
window.setTimeout(() => searchInputRef.current?.focus(), 0);
|
|
77
|
-
}, []);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (open) {
|
|
80
|
-
focusSearchInput();
|
|
81
|
-
}
|
|
82
|
-
}, [open, focusSearchInput]);
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
validationInputRef.current?.setCustomValidity(error || '');
|
|
85
|
-
}, [error]);
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
const input = validationInputRef.current;
|
|
88
|
-
const form = input?.form;
|
|
89
|
-
if (!input || !form) {
|
|
90
31
|
return;
|
|
91
32
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
form.addEventListener('submit', handleFormSubmit);
|
|
99
|
-
return () => {
|
|
100
|
-
form.removeEventListener('submit', handleFormSubmit);
|
|
101
|
-
};
|
|
102
|
-
}, []);
|
|
103
|
-
return (_jsxs(SelectPrimitive.Root, { open: open, onOpenChange: (nextOpen) => {
|
|
104
|
-
if (multiple && !nextOpen && shouldKeepOpen.current) {
|
|
105
|
-
shouldKeepOpen.current = false;
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
setOpen(nextOpen);
|
|
109
|
-
if (nextOpen) {
|
|
110
|
-
focusSearchInput();
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
setSearchValue('');
|
|
114
|
-
}
|
|
115
|
-
}, value: multiple ? '' : value, onValueChange: handleValueChange, children: [_jsxs("div", { className: "group relative", children: [_jsx("input", { ref: validationInputRef, name: name, value: value, onChange: () => undefined, onInvalid: handleInvalid, required: required, tabIndex: -1, "aria-hidden": "true", className: "pointer-events-none absolute left-0 top-1/2 h-px w-px -translate-y-1/2 opacity-0" }), hasLeftIcon && (_jsx("div", { className: "absolute left-2.5 top-1/2 -translate-y-1/2 z-10 text-gray-500", children: hasError ? (_jsx(CustomTooltip, { content: error || '', side: "bottom", children: _jsx(AlertCircle, { className: "h-4 w-4 text-red-500" }) })) : (_jsx("span", { className: "pointer-events-none flex items-center transition-colors group-focus-within:text-primary [&>svg]:h-4 [&>svg]:w-4", children: icon })) })), _jsxs(SelectPrimitive.Trigger, { id: id, "aria-invalid": hasError, className: `bg-input-dark border text-[11px] text-gray-300 rounded-lg ${hasLeftIcon ? 'pl-8' : 'pl-3'} pr-8 py-2 outline-none w-full uppercase font-bold tracking-wider cursor-pointer flex items-center justify-between transition-colors min-w-45 ${hasError
|
|
116
|
-
? 'border-red-500 focus:ring-2 focus:ring-red-500/50 data-[state=open]:border-red-500'
|
|
117
|
-
: 'border-border-dark focus:border-primary data-[state=open]:border-primary'} ${className || ''}`, children: [_jsx("span", { className: "min-w-0 flex-1 text-left", children: selectedOptions.length > 0 ? (_jsxs("span", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("span", { className: "truncate leading-4", children: selectedOptions
|
|
118
|
-
.map((o) => o.label)
|
|
119
|
-
.join(', ') }), selectedOptions.length === 1 &&
|
|
120
|
-
selectedOptions[0].subOption && (_jsx("span", { className: "truncate text-[10px] font-semibold leading-3 tracking-normal text-gray-500 normal-case", children: selectedOptions[0].subOption }))] })) : (_jsx(SelectPrimitive.Value, { placeholder: placeholder })) }), _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDown, { className: "h-4 w-4 opacity-50 absolute right-2.5 top-1/2 -translate-y-1/2" }) })] })] }), _jsx(SelectPrimitive.Portal, { children: _jsxs(SelectPrimitive.Content, { position: "popper", sideOffset: 4, onFocusCapture: (event) => {
|
|
121
|
-
if (event.target !== searchInputRef.current &&
|
|
122
|
-
searchInputRef.current) {
|
|
123
|
-
event.stopPropagation();
|
|
124
|
-
focusSearchInput();
|
|
125
|
-
}
|
|
126
|
-
}, onKeyDownCapture: (event) => {
|
|
127
|
-
if (event.target === searchInputRef.current ||
|
|
128
|
-
event.ctrlKey ||
|
|
129
|
-
event.altKey ||
|
|
130
|
-
event.metaKey ||
|
|
131
|
-
event.key.length !== 1) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
event.stopPropagation();
|
|
136
|
-
setSearchValue((current) => `${current}${event.key}`);
|
|
137
|
-
focusSearchInput();
|
|
138
|
-
}, className: "z-9998 w-(--radix-select-trigger-width) min-w-45 overflow-hidden rounded-lg border border-border-dark bg-surface-dark shadow-xl animate-in fade-in zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", children: [_jsx("div", { className: "border-b border-border-dark p-1", children: _jsx("input", { ref: searchInputRef, "aria-label": "Optionen suchen", value: searchValue, onChange: (event) => setSearchValue(event.target.value), onPointerDownCapture: (event) => event.stopPropagation(), onKeyDownCapture: (event) => {
|
|
139
|
-
if (event.key !== 'Escape') {
|
|
140
|
-
event.stopPropagation();
|
|
141
|
-
}
|
|
142
|
-
}, onKeyDown: (event) => {
|
|
143
|
-
if (event.key !== 'Escape') {
|
|
144
|
-
event.stopPropagation();
|
|
145
|
-
}
|
|
146
|
-
}, placeholder: "Suchen...", className: "h-8 w-full rounded-md border border-border-dark bg-input-dark px-2 text-[11px] font-bold uppercase tracking-wider text-gray-300 outline-none placeholder:text-gray-500 focus:border-primary" }) }), _jsx("div", { className: "rentnerselect-scrollbar max-h-[min(var(--radix-select-content-available-height),16rem)] overflow-y-scroll scrollbar-gutter-stable", children: _jsx(SelectPrimitive.Viewport, { className: "p-1", children: filteredOptions.length > 0 ? (filteredOptions.map((option) => (_jsxs(SelectPrimitive.Item, { value: option.value, onPointerDown: () => {
|
|
147
|
-
if (multiple) {
|
|
148
|
-
shouldKeepOpen.current = true;
|
|
149
|
-
}
|
|
150
|
-
}, onKeyDown: (e) => {
|
|
151
|
-
if (multiple &&
|
|
152
|
-
(e.key === 'Enter' ||
|
|
153
|
-
e.key === ' ')) {
|
|
154
|
-
shouldKeepOpen.current = true;
|
|
155
|
-
}
|
|
156
|
-
}, className: "relative flex w-full cursor-pointer select-none items-center rounded-md py-2 pl-8 pr-2 text-[11px] font-bold uppercase tracking-wider text-gray-300 outline-none focus:bg-primary/20 focus:text-primary transition-colors data-disabled:opacity-50", children: [_jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: multiple ? (selectedValues.includes(option.value) && (_jsx(Check, { className: "h-4 w-4" }))) : (_jsx(SelectPrimitive.ItemIndicator, { children: _jsx(Check, { className: "h-4 w-4" }) })) }), _jsx(SelectPrimitive.ItemText, { children: _jsxs("span", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("span", { className: "truncate leading-4", children: option.label }), option.subOption && (_jsx("span", { className: "truncate text-[10px] font-semibold leading-3 tracking-normal text-gray-500 normal-case", children: option.subOption }))] }) })] }, option.value)))) : (_jsx("div", { className: "relative flex w-full select-none items-center rounded-md py-2 pl-8 pr-2 text-[11px] font-bold uppercase tracking-wider text-gray-500 opacity-60 outline-none italic cursor-not-allowed", children: searchValue.trim()
|
|
157
|
-
? 'Keine Ergebnisse'
|
|
158
|
-
: fallbackOption || 'Keine Optionen' })) }) })] }) })] }));
|
|
33
|
+
onValueChange(nextValue);
|
|
34
|
+
}
|
|
35
|
+
return (_jsx(SelectView, { ...viewProps, selectedValues: selectedValues, formEntries: formEntries, multiple: multiple === true, onSelectValue: handleSelectValue }));
|
|
36
|
+
}
|
|
37
|
+
export function CustomSelect(props) {
|
|
38
|
+
return _jsx(TypedCustomSelect, { ...props });
|
|
159
39
|
}
|
|
160
40
|
//# sourceMappingURL=Select.js.map
|
package/dist/Select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sourceRoot":"","sources":["../src/Select.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Select.js","sourceRoot":"","sources":["../src/Select.tsx"],"names":[],"mappings":";AACA,OAAO,UAAU,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAW1E,SAAS,mBAAmB,CAAC,KAAc;IACvC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,iBAAiB,CAAS,EAC/B,KAAK,EACL,aAAa,EACb,QAAQ,EACR,YAAY,G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H,SAAS,EACb,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,QAAQ,KAAK,IAAI,EAC3B,aAAa,EAAE,iBAAiB,GAClC,CACL,CAAA;AACL,CAAC;AAYD,MAAM,UAAU,YAAY,CACxB,KAAgC;IAEhC,OAAO,KAAC,iBAAiB,OAAK,KAAK,GAAI,CAAA;AAC3C,CAAC"}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SelectLocale = 'de' | 'en';
|
|
2
|
+
export interface SelectMessages {
|
|
3
|
+
required: string;
|
|
4
|
+
minSelection: (count: number) => string;
|
|
5
|
+
maxSelection: (count: number) => string;
|
|
6
|
+
searchOptions: string;
|
|
7
|
+
searchPlaceholder: string;
|
|
8
|
+
noResults: string;
|
|
9
|
+
noOptions: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const selectMessageCatalog: Record<SelectLocale, SelectMessages>;
|
|
12
|
+
export declare function resolveSelectMessages(locale?: SelectLocale, messages?: Partial<SelectMessages>): SelectMessages;
|
|
13
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,CAAA;AAEtC,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACvC,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACvC,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CACpB;AAsBD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,YAAY,EAAE,cAAc,CAGrE,CAAA;AAED,wBAAgB,qBAAqB,CACjC,MAAM,GAAE,YAAmB,EAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GACnC,cAAc,CAKhB"}
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const germanMessages = {
|
|
2
|
+
required: 'Dieses Feld ist erforderlich',
|
|
3
|
+
minSelection: (count) => `Mindestens ${count} Optionen auswählen`,
|
|
4
|
+
maxSelection: (count) => `Maximal ${count} Optionen auswählen`,
|
|
5
|
+
searchOptions: 'Optionen suchen',
|
|
6
|
+
searchPlaceholder: 'Suchen…',
|
|
7
|
+
noResults: 'Keine Ergebnisse',
|
|
8
|
+
noOptions: 'Keine Optionen',
|
|
9
|
+
};
|
|
10
|
+
const englishMessages = {
|
|
11
|
+
required: 'This field is required',
|
|
12
|
+
minSelection: (count) => `Select at least ${count} options`,
|
|
13
|
+
maxSelection: (count) => `Select at most ${count} options`,
|
|
14
|
+
searchOptions: 'Search options',
|
|
15
|
+
searchPlaceholder: 'Search…',
|
|
16
|
+
noResults: 'No results',
|
|
17
|
+
noOptions: 'No options',
|
|
18
|
+
};
|
|
19
|
+
export const selectMessageCatalog = {
|
|
20
|
+
de: germanMessages,
|
|
21
|
+
en: englishMessages,
|
|
22
|
+
};
|
|
23
|
+
export function resolveSelectMessages(locale = 'de', messages) {
|
|
24
|
+
return {
|
|
25
|
+
...selectMessageCatalog[locale],
|
|
26
|
+
...messages,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAYA,MAAM,cAAc,GAAmB;IACnC,QAAQ,EAAE,8BAA8B;IACxC,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,KAAK,qBAAqB;IACjE,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,KAAK,qBAAqB;IAC9D,aAAa,EAAE,iBAAiB;IAChC,iBAAiB,EAAE,SAAS;IAC5B,SAAS,EAAE,kBAAkB;IAC7B,SAAS,EAAE,gBAAgB;CAC9B,CAAA;AAED,MAAM,eAAe,GAAmB;IACpC,QAAQ,EAAE,wBAAwB;IAClC,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,KAAK,UAAU;IAC3D,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,KAAK,UAAU;IAC1D,aAAa,EAAE,gBAAgB;IAC/B,iBAAiB,EAAE,SAAS;IAC5B,SAAS,EAAE,YAAY;IACvB,SAAS,EAAE,YAAY;CAC1B,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAyC;IACtE,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,eAAe;CACtB,CAAA;AAED,MAAM,UAAU,qBAAqB,CACjC,MAAM,GAAiB,IAAI,EAC3B,QAAkC;IAElC,OAAO;QACH,GAAG,oBAAoB,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;KACd,CAAA;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { CustomSelect } from './Select.js';
|
|
2
|
-
export
|
|
2
|
+
export { resolveSelectMessages, selectMessageCatalog } from './i18n.js';
|
|
3
|
+
export type { CustomSelectProps, MultipleSelectProps, Option, SingleSelectProps, } from './types.js';
|
|
4
|
+
export type { SelectLocale, SelectMessages } from './types.js';
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACvE,YAAY,EACR,iBAAiB,EACjB,mBAAmB,EACnB,MAAM,EACN,iBAAiB,GACpB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type SelectValueComparator<TValue> = (optionValue: TValue, value: TValue) => boolean;
|
|
2
|
+
export declare function isSingleValueEmpty(value: unknown): value is '' | null | undefined;
|
|
3
|
+
export declare function toggleSelectedValue<TValue>(selectedValues: ReadonlyArray<TValue>, nextValue: TValue, isEqual: SelectValueComparator<TValue>, maxSelection?: number): Array<TValue> | null;
|
|
4
|
+
//# sourceMappingURL=selectValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectValue.d.ts","sourceRoot":"","sources":["../src/selectValue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,CAAC,MAAM,IAAI,CACxC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,KACZ,OAAO,CAAA;AAEZ,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,EAAE,GAAG,IAAI,GAAG,SAAS,CAEhC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EACtC,cAAc,EAAE,aAAa,CAAC,MAAM,CAAC,EACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,EACtC,YAAY,CAAC,EAAE,MAAM,GACtB,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CActB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function isSingleValueEmpty(value) {
|
|
2
|
+
return value === null || value === undefined || value === '';
|
|
3
|
+
}
|
|
4
|
+
export function toggleSelectedValue(selectedValues, nextValue, isEqual, maxSelection) {
|
|
5
|
+
const selectedIndex = selectedValues.findIndex((value) => isEqual(nextValue, value));
|
|
6
|
+
if (selectedIndex >= 0) {
|
|
7
|
+
return selectedValues.filter((value) => !isEqual(nextValue, value));
|
|
8
|
+
}
|
|
9
|
+
if (maxSelection !== undefined && selectedValues.length >= maxSelection) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return [...selectedValues, nextValue];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=selectValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectValue.js","sourceRoot":"","sources":["../src/selectValue.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,kBAAkB,CAC9B,KAAc;IAEd,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAA;AAChE,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,cAAqC,EACrC,SAAiB,EACjB,OAAsC,EACtC,YAAqB;IAErB,MAAM,aAAa,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CACrD,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAC5B,CAAA;IAED,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,YAAY,KAAK,SAAS,IAAI,cAAc,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;QACtE,OAAO,IAAI,CAAA;IACf,CAAC;IAED,OAAO,CAAC,GAAG,cAAc,EAAE,SAAS,CAAC,CAAA;AACzC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { AriaAttributes, ReactNode, Ref } from 'react';
|
|
2
|
+
import type { SelectLocale, SelectMessages } from './i18n.js';
|
|
3
|
+
export interface Option<TValue = string> {
|
|
4
|
+
value: TValue;
|
|
4
5
|
label: string;
|
|
5
6
|
subOption?: string;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
interface SharedCustomSelectProps<TValue> extends AriaAttributes {
|
|
8
9
|
id?: string;
|
|
9
10
|
name?: string;
|
|
10
|
-
|
|
11
|
-
onValueChange: (value: string) => void;
|
|
12
|
-
options: Array<Option>;
|
|
11
|
+
options: ReadonlyArray<Option<TValue>>;
|
|
13
12
|
required?: boolean;
|
|
13
|
+
label?: ReactNode;
|
|
14
|
+
description?: ReactNode;
|
|
15
|
+
error?: string | null;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
readOnly?: boolean;
|
|
18
|
+
triggerRef?: Ref<HTMLButtonElement>;
|
|
14
19
|
icon?: ReactNode;
|
|
15
20
|
placeholder?: string;
|
|
16
21
|
className?: string;
|
|
17
22
|
fallbackOption?: string;
|
|
18
|
-
multiple?: boolean;
|
|
19
23
|
minSelection?: number;
|
|
20
24
|
maxSelection?: number;
|
|
25
|
+
locale?: SelectLocale;
|
|
26
|
+
messages?: Partial<SelectMessages>;
|
|
27
|
+
isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean;
|
|
28
|
+
getFormValue?: (value: TValue) => string;
|
|
21
29
|
}
|
|
30
|
+
export interface SingleSelectProps<TValue = string> extends SharedCustomSelectProps<TValue> {
|
|
31
|
+
value: TValue | null | undefined;
|
|
32
|
+
onValueChange: (value: TValue) => void;
|
|
33
|
+
multiple?: false;
|
|
34
|
+
}
|
|
35
|
+
export interface MultipleSelectProps<TValue = string> extends SharedCustomSelectProps<TValue> {
|
|
36
|
+
value: ReadonlyArray<TValue>;
|
|
37
|
+
onValueChange: (value: Array<TValue>) => void;
|
|
38
|
+
multiple: true;
|
|
39
|
+
}
|
|
40
|
+
export type CustomSelectProps<TValue = string> = SingleSelectProps<TValue> | MultipleSelectProps<TValue>;
|
|
41
|
+
export type { SelectLocale, SelectMessages } from './i18n.js';
|
|
22
42
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE7D,MAAM,WAAW,MAAM,CAAC,MAAM,GAAG,MAAM;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,UAAU,uBAAuB,CAAC,MAAM,CAAE,SAAQ,cAAc;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,aAAa,CAA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