@noya-app/noya-designsystem 0.1.43 → 0.1.44
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Combobox.tsx +22 -10
- package/src/components/SelectMenu.tsx +4 -0
package/package.json
CHANGED
|
@@ -45,7 +45,7 @@ export type BaseComboboxProps = {
|
|
|
45
45
|
|
|
46
46
|
export type StringModeOnlyProps = {
|
|
47
47
|
mode: "string";
|
|
48
|
-
|
|
48
|
+
value?: string;
|
|
49
49
|
onChange?: (value: string) => void;
|
|
50
50
|
onSelectItem?: (value: string) => void;
|
|
51
51
|
onBlur?: (didSubmit: boolean, value: string) => void;
|
|
@@ -57,7 +57,7 @@ export type StringModeProps = BaseComboboxProps & StringModeOnlyProps;
|
|
|
57
57
|
|
|
58
58
|
export type OptionModeOnlyProps = {
|
|
59
59
|
mode?: "option";
|
|
60
|
-
|
|
60
|
+
value?: ComboboxOption;
|
|
61
61
|
onChange?: (value: ComboboxOption) => void;
|
|
62
62
|
onSelectItem?: (value: ComboboxOption) => void;
|
|
63
63
|
onBlur?: (didSubmit: boolean, value: ComboboxOption) => void;
|
|
@@ -103,7 +103,7 @@ export const Combobox = memo(
|
|
|
103
103
|
if (rest.mode === "string") {
|
|
104
104
|
return {
|
|
105
105
|
mode: rest.mode,
|
|
106
|
-
|
|
106
|
+
value: rest.value,
|
|
107
107
|
onChange: rest.onChange,
|
|
108
108
|
onSelectItem: rest.onSelectItem,
|
|
109
109
|
onHoverItem: rest.onHoverItem,
|
|
@@ -113,7 +113,7 @@ export const Combobox = memo(
|
|
|
113
113
|
} else {
|
|
114
114
|
return {
|
|
115
115
|
mode: rest.mode,
|
|
116
|
-
|
|
116
|
+
value: rest.value,
|
|
117
117
|
onChange: rest.onChange,
|
|
118
118
|
onSelectItem: rest.onSelectItem,
|
|
119
119
|
onHoverItem: rest.onHoverItem,
|
|
@@ -122,7 +122,7 @@ export const Combobox = memo(
|
|
|
122
122
|
}
|
|
123
123
|
}, [
|
|
124
124
|
rest.mode,
|
|
125
|
-
rest.
|
|
125
|
+
rest.value,
|
|
126
126
|
rest.onChange,
|
|
127
127
|
rest.onSelectItem,
|
|
128
128
|
rest.onHoverItem,
|
|
@@ -131,10 +131,17 @@ export const Combobox = memo(
|
|
|
131
131
|
]);
|
|
132
132
|
|
|
133
133
|
const ref = useRef<HTMLInputElement>(null);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
|
|
135
|
+
function getInitialValueString() {
|
|
136
|
+
if (props.mode === "string") {
|
|
137
|
+
return props.value ?? "";
|
|
138
|
+
} else {
|
|
139
|
+
return props.value?.name ?? "";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const initialValueString = getInitialValueString();
|
|
144
|
+
|
|
138
145
|
const [comboboxState] = useState(
|
|
139
146
|
() =>
|
|
140
147
|
new ComboboxState(
|
|
@@ -153,6 +160,10 @@ export const Combobox = memo(
|
|
|
153
160
|
comboboxState.setItems(items);
|
|
154
161
|
}, [items, comboboxState]);
|
|
155
162
|
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
comboboxState.setFilter(initialValueString);
|
|
165
|
+
}, [comboboxState, initialValueString]);
|
|
166
|
+
|
|
156
167
|
const { filter, selectedIndex, filteredItems } = state;
|
|
157
168
|
|
|
158
169
|
const shouldShowMenu =
|
|
@@ -401,9 +412,10 @@ export const Combobox = memo(
|
|
|
401
412
|
|
|
402
413
|
useEffect(() => {
|
|
403
414
|
if (!shouldBlur) return;
|
|
415
|
+
if (document.activeElement !== ref.current) return;
|
|
416
|
+
setShouldBlur(false);
|
|
404
417
|
ref.current?.focus();
|
|
405
418
|
handleBlur();
|
|
406
|
-
setShouldBlur(false);
|
|
407
419
|
}, [shouldBlur, handleBlur]);
|
|
408
420
|
|
|
409
421
|
return (
|
|
@@ -31,6 +31,7 @@ type Props<T extends string> = {
|
|
|
31
31
|
label?: React.ReactNode;
|
|
32
32
|
onFocus?: FocusEventHandler;
|
|
33
33
|
onBlur?: FocusEventHandler;
|
|
34
|
+
contentStyle?: React.CSSProperties;
|
|
34
35
|
} & Pick<SelectProps, "open" | "onOpenChange">;
|
|
35
36
|
|
|
36
37
|
const readOnlyStyle: CSSProperties = {
|
|
@@ -68,6 +69,7 @@ export const SelectMenu = memoGeneric(function SelectMenu<
|
|
|
68
69
|
onFocus,
|
|
69
70
|
onBlur,
|
|
70
71
|
onOpenChange,
|
|
72
|
+
contentStyle,
|
|
71
73
|
}: Props<T>) {
|
|
72
74
|
const selectedItem = menuItems.find(
|
|
73
75
|
(item): item is RegularMenuItem<T> =>
|
|
@@ -184,6 +186,8 @@ export const SelectMenu = memoGeneric(function SelectMenu<
|
|
|
184
186
|
align="end"
|
|
185
187
|
style={{
|
|
186
188
|
width: "var(--radix-select-trigger-width)",
|
|
189
|
+
maxHeight: "500px",
|
|
190
|
+
...contentStyle,
|
|
187
191
|
}}
|
|
188
192
|
>
|
|
189
193
|
<Select.ScrollUpButton className={scrollButtonStyles}>
|