react-better-html 1.1.151 → 1.1.153
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 +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +44 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -479,6 +479,7 @@ type DropdownProps<Value, Data = unknown> = {
|
|
|
479
479
|
onChange?: (value: Value | undefined) => void;
|
|
480
480
|
onChangeSearch?: (query: string) => void;
|
|
481
481
|
renderOption?: (option: DropdownOption<Value, Data>, index: number, isSelected: boolean) => React.ReactNode;
|
|
482
|
+
renderOptionDivider?: (previousOption: DropdownOption<Value, Data> | undefined, nextOption: DropdownOption<Value, Data> | undefined, previousOptionIndex: number, nextOptionIndex: number) => React.ReactNode;
|
|
482
483
|
} & OmitProps<DivProps, "onChange" | "defaultChecked">;
|
|
483
484
|
type DropdownComponentType = {
|
|
484
485
|
<Value, Data>(props: ComponentPropWithRef<HTMLDivElement, DropdownProps<Value, Data>>): React.ReactElement;
|
|
@@ -560,6 +561,7 @@ declare function useForm<FormFields extends Record<string | number, string | num
|
|
|
560
561
|
getRadioButtonProps: <FieldName extends keyof FormFields>(field: FieldName, value: FormFields[FieldName]) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
|
|
561
562
|
getSwitchProps: <FieldName extends keyof FormFields>(field: FieldName) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
|
|
562
563
|
focusField: (field: keyof FormFields) => void;
|
|
564
|
+
validate: () => {};
|
|
563
565
|
onSubmit: (event: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
564
566
|
reset: () => void;
|
|
565
567
|
requiredFields: (keyof FormFields)[] | undefined;
|
|
@@ -994,4 +996,4 @@ type AlertsPluginOptions = {
|
|
|
994
996
|
declare const defaultAlertsPluginOptions: Required<AlertsPluginOptions>;
|
|
995
997
|
declare const alertsPlugin: BetterHtmlPluginConstructor<AlertsPluginOptions>;
|
|
996
998
|
|
|
997
|
-
export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, desaturateColor, formatPhoneNumber, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
|
|
999
|
+
export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, desaturateColor, formatPhoneNumber, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
|
package/dist/index.d.ts
CHANGED
|
@@ -479,6 +479,7 @@ type DropdownProps<Value, Data = unknown> = {
|
|
|
479
479
|
onChange?: (value: Value | undefined) => void;
|
|
480
480
|
onChangeSearch?: (query: string) => void;
|
|
481
481
|
renderOption?: (option: DropdownOption<Value, Data>, index: number, isSelected: boolean) => React.ReactNode;
|
|
482
|
+
renderOptionDivider?: (previousOption: DropdownOption<Value, Data> | undefined, nextOption: DropdownOption<Value, Data> | undefined, previousOptionIndex: number, nextOptionIndex: number) => React.ReactNode;
|
|
482
483
|
} & OmitProps<DivProps, "onChange" | "defaultChecked">;
|
|
483
484
|
type DropdownComponentType = {
|
|
484
485
|
<Value, Data>(props: ComponentPropWithRef<HTMLDivElement, DropdownProps<Value, Data>>): React.ReactElement;
|
|
@@ -560,6 +561,7 @@ declare function useForm<FormFields extends Record<string | number, string | num
|
|
|
560
561
|
getRadioButtonProps: <FieldName extends keyof FormFields>(field: FieldName, value: FormFields[FieldName]) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
|
|
561
562
|
getSwitchProps: <FieldName extends keyof FormFields>(field: FieldName) => ComponentPropWithRef<ToggleInputRef, ToggleInputProps<FormFields[FieldName]>>;
|
|
562
563
|
focusField: (field: keyof FormFields) => void;
|
|
564
|
+
validate: () => {};
|
|
563
565
|
onSubmit: (event: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
564
566
|
reset: () => void;
|
|
565
567
|
requiredFields: (keyof FormFields)[] | undefined;
|
|
@@ -994,4 +996,4 @@ type AlertsPluginOptions = {
|
|
|
994
996
|
declare const defaultAlertsPluginOptions: Required<AlertsPluginOptions>;
|
|
995
997
|
declare const alertsPlugin: BetterHtmlPluginConstructor<AlertsPluginOptions>;
|
|
996
998
|
|
|
997
|
-
export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, desaturateColor, formatPhoneNumber, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
|
|
999
|
+
export { type Alert, type AlertType, type AlertsPluginOptions, type AppConfig, type AssetName, type AssetsConfig, type BetterHtmlConfig, type BetterHtmlPlugin, _default as BetterHtmlProvider, type BetterHtmlProviderValue, type BrowserName, Button, type ButtonProps, Chip, type ChipProps, type Color, type ColorName, type ColorTheme, ColorThemeSwitch, type ColorThemeSwitchProps, type Colors, type ComponentHoverStyle, type ComponentMarginProps, type ComponentPaddingProps, type DeepPartialRecord, Div, type DivProps, _default$3 as Divider, Dropdown, type DropdownOption, type DropdownProps, type ExcludeOptions, Foldable, type FoldableProps, type FoldableRef, Form, type FormProps, FormRow, type FormRowProps, type HorizontalDividerProps, _default$5 as Icon, type IconName, type IconProps, type IconsConfig, _default$4 as Image, type ImageProps, InputField, type InputFieldProps, _default$1 as Label, type LabelProps, Loader, type LoaderConfig, type LoaderName, type LoaderProps, Modal, type ModalProps, type ModalRef, type OmitProps, PageHeader, type PageHeaderProps, PageHolder, type PageHolderProps, type PartialRecord, type PickAllRequired, type PickValue, type PluginName, type Styles, type TabGroup, Table, type TableColumn, type TableProps, type TableRef, Tabs, type TabsProps, type TabsRef, Text, type TextAs, type TextProps, type TextareaFieldProps, type Theme, type ThemeConfig, _default$2 as ToggleInput, type ToggleInputProps, type ToggleInputRef, Tooltip, type TooltipProps, type TooltipRef, type VerticalDividerProps, alertControls, alertsPlugin, colorThemeControls, countries, darkenColor, defaultAlertsPluginOptions, desaturateColor, formatPhoneNumber, generateRandomString, getBrowser, getFormErrorObject, isMobileDevice, lightenColor, loaderControls, reactRouterDomPlugin, saturateColor, useAlertControls, useBetterHtmlContext, useBooleanState, useDebounceState, useForm, useLoader, useLoaderControls, useMediaQuery, usePageResize, usePageScroll, useTheme, useUrlQuery };
|
package/dist/index.js
CHANGED
|
@@ -3037,13 +3037,17 @@ function useForm(options) {
|
|
|
3037
3037
|
const focusField = (0, import_react10.useCallback)((field) => {
|
|
3038
3038
|
inputFieldRefs.current[field]?.focus();
|
|
3039
3039
|
}, []);
|
|
3040
|
+
const validateForm = (0, import_react10.useCallback)(() => {
|
|
3041
|
+
const validationErrors = validate?.(values) || {};
|
|
3042
|
+
setErrors(validationErrors);
|
|
3043
|
+
return validationErrors;
|
|
3044
|
+
}, [validate, values]);
|
|
3040
3045
|
const onSubmitFunction = (0, import_react10.useCallback)(
|
|
3041
3046
|
async (event) => {
|
|
3042
3047
|
event.preventDefault();
|
|
3043
3048
|
setIsSubmitting.setTrue();
|
|
3044
3049
|
try {
|
|
3045
|
-
const validationErrors =
|
|
3046
|
-
setErrors(validationErrors);
|
|
3050
|
+
const validationErrors = validateForm();
|
|
3047
3051
|
if (Object.keys(validationErrors).length === 0) {
|
|
3048
3052
|
await onSubmit?.(values);
|
|
3049
3053
|
} else {
|
|
@@ -3054,7 +3058,7 @@ function useForm(options) {
|
|
|
3054
3058
|
setIsSubmitting.setFalse();
|
|
3055
3059
|
}
|
|
3056
3060
|
},
|
|
3057
|
-
[values,
|
|
3061
|
+
[values, validateForm, onSubmit, focusField]
|
|
3058
3062
|
);
|
|
3059
3063
|
const reset = (0, import_react10.useCallback)(() => {
|
|
3060
3064
|
setValues(defaultValues);
|
|
@@ -3085,6 +3089,7 @@ function useForm(options) {
|
|
|
3085
3089
|
getRadioButtonProps,
|
|
3086
3090
|
getSwitchProps,
|
|
3087
3091
|
focusField,
|
|
3092
|
+
validate: validateForm,
|
|
3088
3093
|
onSubmit: onSubmitFunction,
|
|
3089
3094
|
reset,
|
|
3090
3095
|
requiredFields,
|
|
@@ -5508,6 +5513,7 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
|
|
|
5508
5513
|
onChange,
|
|
5509
5514
|
onChangeSearch,
|
|
5510
5515
|
renderOption,
|
|
5516
|
+
renderOptionDivider,
|
|
5511
5517
|
id,
|
|
5512
5518
|
...props
|
|
5513
5519
|
}, ref) {
|
|
@@ -5609,31 +5615,41 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
|
|
|
5609
5615
|
);
|
|
5610
5616
|
const selectedOption = (0, import_react18.useMemo)(() => options.find((option) => option.value === value), [options, value]);
|
|
5611
5617
|
const renderedOptions = (0, import_react18.useMemo)(
|
|
5612
|
-
() =>
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
{
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5618
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
|
|
5619
|
+
renderOptionDivider ? renderOptionDivider(void 0, filteredOptions[0], -1, 0) : void 0,
|
|
5620
|
+
filteredOptions.map((option, index) => {
|
|
5621
|
+
const isSelected = option.value === value;
|
|
5622
|
+
const isDisabled = option.disabled;
|
|
5623
|
+
const isFocused2 = index === focusedOptionIndex;
|
|
5624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_react18.Fragment, { children: [
|
|
5625
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
5626
|
+
Div_default,
|
|
5627
|
+
{
|
|
5628
|
+
color: isDisabled ? theme2.colors.textSecondary + "80" : isSelected ? theme2.colors.base : theme2.colors.textPrimary,
|
|
5629
|
+
backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
|
|
5630
|
+
filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
|
|
5631
|
+
filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
|
|
5632
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
5633
|
+
padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
|
|
5634
|
+
value: option,
|
|
5635
|
+
onClickWithValue: onClickOption,
|
|
5636
|
+
onMouseMove: () => setFocusedOptionIndex(void 0),
|
|
5637
|
+
role: "option",
|
|
5638
|
+
"aria-selected": isSelected,
|
|
5639
|
+
"aria-disabled": isDisabled,
|
|
5640
|
+
children: renderOption ? renderOption(option, index, isSelected) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text_default, { children: option.label })
|
|
5641
|
+
}
|
|
5642
|
+
),
|
|
5643
|
+
renderOptionDivider ? renderOptionDivider(
|
|
5644
|
+
option,
|
|
5645
|
+
filteredOptions[index + 1],
|
|
5646
|
+
index,
|
|
5647
|
+
filteredOptions[index + 1] ? index + 1 : -1
|
|
5648
|
+
) : void 0
|
|
5649
|
+
] }, JSON.stringify(option));
|
|
5650
|
+
})
|
|
5651
|
+
] }),
|
|
5652
|
+
[filteredOptions, value, focusedOptionIndex, theme2.colors, onClickOption, renderOption, renderOptionDivider]
|
|
5637
5653
|
);
|
|
5638
5654
|
(0, import_react18.useEffect)(() => {
|
|
5639
5655
|
if (isOpen) {
|