bako-ui 0.5.5 → 0.5.7
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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +34 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -145,6 +145,7 @@ type RhfComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<
|
|
|
145
145
|
label?: FieldLabelProps;
|
|
146
146
|
input?: Omit<InputProps, 'value' | 'onChange' | 'disabled' | 'type'>;
|
|
147
147
|
};
|
|
148
|
+
onlyLowercase?: boolean;
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
/**
|
|
@@ -164,7 +165,7 @@ type RhfComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<
|
|
|
164
165
|
* ]}
|
|
165
166
|
* />
|
|
166
167
|
*/
|
|
167
|
-
declare function RhfCombobox<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({ control, name, defaultValue, label, placeholder, error, options, disabled, helperText, isLoadingOptions, noOptionsText, openOnFocus, slotProps, variant, clearTriggerIcon, showTrigger, allowCustomValue, onInputValueChange, }: RhfComboboxProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
168
|
+
declare function RhfCombobox<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({ control, name, defaultValue, label, placeholder, error, options, disabled, helperText, isLoadingOptions, noOptionsText, openOnFocus, slotProps, variant, clearTriggerIcon, showTrigger, allowCustomValue, onlyLowercase, onInputValueChange, }: RhfComboboxProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
168
169
|
|
|
169
170
|
type RhfInputProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = UseControllerProps<TFieldValues, TName> & {
|
|
170
171
|
label?: React.ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -145,6 +145,7 @@ type RhfComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<
|
|
|
145
145
|
label?: FieldLabelProps;
|
|
146
146
|
input?: Omit<InputProps, 'value' | 'onChange' | 'disabled' | 'type'>;
|
|
147
147
|
};
|
|
148
|
+
onlyLowercase?: boolean;
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
/**
|
|
@@ -164,7 +165,7 @@ type RhfComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<
|
|
|
164
165
|
* ]}
|
|
165
166
|
* />
|
|
166
167
|
*/
|
|
167
|
-
declare function RhfCombobox<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({ control, name, defaultValue, label, placeholder, error, options, disabled, helperText, isLoadingOptions, noOptionsText, openOnFocus, slotProps, variant, clearTriggerIcon, showTrigger, allowCustomValue, onInputValueChange, }: RhfComboboxProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
168
|
+
declare function RhfCombobox<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>>({ control, name, defaultValue, label, placeholder, error, options, disabled, helperText, isLoadingOptions, noOptionsText, openOnFocus, slotProps, variant, clearTriggerIcon, showTrigger, allowCustomValue, onlyLowercase, onInputValueChange, }: RhfComboboxProps<TFieldValues, TName>): react_jsx_runtime.JSX.Element;
|
|
168
169
|
|
|
169
170
|
type RhfInputProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = UseControllerProps<TFieldValues, TName> & {
|
|
170
171
|
label?: React.ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -247,6 +247,7 @@ function RhfCombobox({
|
|
|
247
247
|
clearTriggerIcon,
|
|
248
248
|
showTrigger = false,
|
|
249
249
|
allowCustomValue = true,
|
|
250
|
+
onlyLowercase = false,
|
|
250
251
|
onInputValueChange
|
|
251
252
|
}) {
|
|
252
253
|
const {
|
|
@@ -257,38 +258,48 @@ function RhfCombobox({
|
|
|
257
258
|
initialItems: options,
|
|
258
259
|
filter: contains
|
|
259
260
|
});
|
|
260
|
-
const
|
|
261
|
+
const normalizeValue = React.useCallback(
|
|
262
|
+
(val) => {
|
|
263
|
+
if (!val) return val;
|
|
264
|
+
return onlyLowercase ? val.toLowerCase() : val;
|
|
265
|
+
},
|
|
266
|
+
[onlyLowercase]
|
|
267
|
+
);
|
|
268
|
+
const [inputValue, setInputValue] = React.useState(normalizeValue(value || ""));
|
|
261
269
|
const [isTyping, setIsTyping] = React.useState(false);
|
|
262
270
|
React.useEffect(() => {
|
|
263
271
|
if (isTyping) return;
|
|
264
|
-
|
|
265
|
-
|
|
272
|
+
const normalizedValue = normalizeValue(value || "");
|
|
273
|
+
if (normalizedValue !== inputValue) {
|
|
274
|
+
setInputValue(normalizedValue || "");
|
|
266
275
|
}
|
|
267
|
-
}, [value, inputValue, isTyping]);
|
|
276
|
+
}, [value, inputValue, isTyping, normalizeValue]);
|
|
268
277
|
const handleValueChange = React.useCallback(
|
|
269
278
|
(details) => {
|
|
270
279
|
const newValue = details.value[0] || "";
|
|
280
|
+
const normalizedValue = normalizeValue(newValue);
|
|
271
281
|
setIsTyping(false);
|
|
272
|
-
onChange(
|
|
273
|
-
setInputValue(
|
|
274
|
-
onInputValueChange == null ? void 0 : onInputValueChange(
|
|
282
|
+
onChange(normalizedValue);
|
|
283
|
+
setInputValue(normalizedValue);
|
|
284
|
+
onInputValueChange == null ? void 0 : onInputValueChange(normalizedValue);
|
|
275
285
|
},
|
|
276
|
-
[onChange, onInputValueChange]
|
|
286
|
+
[onChange, onInputValueChange, normalizeValue]
|
|
277
287
|
);
|
|
278
288
|
const handleInputValueChange = React.useCallback(
|
|
279
289
|
(details) => {
|
|
280
290
|
setIsTyping(true);
|
|
281
|
-
|
|
291
|
+
const normalizedInputValue = normalizeValue(details.inputValue);
|
|
292
|
+
setInputValue(normalizedInputValue);
|
|
282
293
|
reactDom.flushSync(() => {
|
|
283
|
-
filter(
|
|
294
|
+
filter(normalizedInputValue);
|
|
284
295
|
});
|
|
285
|
-
onInputValueChange == null ? void 0 : onInputValueChange(
|
|
296
|
+
onInputValueChange == null ? void 0 : onInputValueChange(normalizedInputValue);
|
|
286
297
|
if (allowCustomValue) {
|
|
287
|
-
onChange(
|
|
298
|
+
onChange(normalizedInputValue);
|
|
288
299
|
}
|
|
289
300
|
setTimeout(() => setIsTyping(false), 100);
|
|
290
301
|
},
|
|
291
|
-
[filter, allowCustomValue, onChange, onInputValueChange]
|
|
302
|
+
[filter, allowCustomValue, onChange, onInputValueChange, normalizeValue]
|
|
292
303
|
);
|
|
293
304
|
const handleOpenChange = React.useCallback(
|
|
294
305
|
(details) => {
|
|
@@ -340,7 +351,7 @@ function RhfCombobox({
|
|
|
340
351
|
width: "full",
|
|
341
352
|
variant,
|
|
342
353
|
inputValue,
|
|
343
|
-
value: value ? [value] : [],
|
|
354
|
+
value: value ? [normalizeValue(value)] : [],
|
|
344
355
|
borderRadius: "lg",
|
|
345
356
|
onValueChange: handleValueChange,
|
|
346
357
|
onOpenChange: handleOpenChange,
|
|
@@ -351,7 +362,7 @@ function RhfCombobox({
|
|
|
351
362
|
invalid: !!error,
|
|
352
363
|
allowCustomValue,
|
|
353
364
|
selectionBehavior: "preserve",
|
|
354
|
-
defaultValue: [defaultValue || ""],
|
|
365
|
+
defaultValue: [normalizeValue(defaultValue || "")],
|
|
355
366
|
placeholder,
|
|
356
367
|
...slotProps == null ? void 0 : slotProps.root,
|
|
357
368
|
children: [
|
|
@@ -370,9 +381,15 @@ function RhfCombobox({
|
|
|
370
381
|
showTrigger && /* @__PURE__ */ jsxRuntime.jsx(react.Combobox.Trigger, {})
|
|
371
382
|
] })
|
|
372
383
|
] }),
|
|
373
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
384
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
385
|
+
ComboboxHiddenInput,
|
|
386
|
+
{
|
|
387
|
+
name: rest.name,
|
|
388
|
+
value: normalizeValue(value != null ? value : "")
|
|
389
|
+
}
|
|
390
|
+
),
|
|
374
391
|
helperText && /* @__PURE__ */ jsxRuntime.jsx(react.Field.HelperText, { children: helperText }),
|
|
375
|
-
error && /* @__PURE__ */ jsxRuntime.jsx(react.Field.ErrorText, { children: error.message }),
|
|
392
|
+
(error == null ? void 0 : error.message) && /* @__PURE__ */ jsxRuntime.jsx(react.Field.ErrorText, { children: error.message }),
|
|
376
393
|
/* @__PURE__ */ jsxRuntime.jsx(react.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(react.Combobox.Positioner, { children: (showOptions || !allowCustomValue) && /* @__PURE__ */ jsxRuntime.jsxs(react.Combobox.Content, { children: [
|
|
377
394
|
isLoadingOptions && /* @__PURE__ */ jsxRuntime.jsxs(react.HStack, { p: "2", children: [
|
|
378
395
|
/* @__PURE__ */ jsxRuntime.jsx(react.Spinner, { size: "xs", borderWidth: "1px" }),
|