@gaozh1024/rn-kit 0.2.0-beta.0 → 0.2.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/dist/index.d.mts +12 -14
- package/dist/index.d.ts +12 -14
- package/dist/index.js +61 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1972,15 +1972,16 @@ interface CheckboxProps {
|
|
|
1972
1972
|
*/
|
|
1973
1973
|
declare function Checkbox({ checked, defaultChecked, onChange, disabled, children, className, testID, }: CheckboxProps): react_jsx_runtime.JSX.Element;
|
|
1974
1974
|
|
|
1975
|
-
interface
|
|
1975
|
+
interface FormGroupOption {
|
|
1976
1976
|
label: string;
|
|
1977
1977
|
value: string;
|
|
1978
1978
|
disabled?: boolean;
|
|
1979
1979
|
}
|
|
1980
|
+
|
|
1980
1981
|
interface CheckboxGroupProps {
|
|
1981
1982
|
value?: string[];
|
|
1982
1983
|
onChange?: (value: string[]) => void;
|
|
1983
|
-
options?:
|
|
1984
|
+
options?: FormGroupOption[];
|
|
1984
1985
|
direction?: 'row' | 'column';
|
|
1985
1986
|
disabled?: boolean;
|
|
1986
1987
|
}
|
|
@@ -2003,15 +2004,10 @@ interface RadioProps {
|
|
|
2003
2004
|
*/
|
|
2004
2005
|
declare function Radio({ checked, defaultChecked, onChange, disabled, children, className, testID, }: RadioProps): react_jsx_runtime.JSX.Element;
|
|
2005
2006
|
|
|
2006
|
-
interface Option {
|
|
2007
|
-
label: string;
|
|
2008
|
-
value: string;
|
|
2009
|
-
disabled?: boolean;
|
|
2010
|
-
}
|
|
2011
2007
|
interface RadioGroupProps {
|
|
2012
2008
|
value?: string;
|
|
2013
2009
|
onChange?: (value: string) => void;
|
|
2014
|
-
options?:
|
|
2010
|
+
options?: FormGroupOption[];
|
|
2015
2011
|
direction?: 'row' | 'column';
|
|
2016
2012
|
disabled?: boolean;
|
|
2017
2013
|
}
|
|
@@ -2126,23 +2122,25 @@ interface FormItemProps {
|
|
|
2126
2122
|
}
|
|
2127
2123
|
declare function FormItem({ name: _name, label, error, help, required, children, className, labelClassName, }: FormItemProps): react_jsx_runtime.JSX.Element;
|
|
2128
2124
|
|
|
2129
|
-
|
|
2125
|
+
type FormValues = Record<string, unknown>;
|
|
2126
|
+
type FieldName<T extends FormValues> = Extract<keyof T, string>;
|
|
2127
|
+
interface UseFormOptions<T extends FormValues> {
|
|
2130
2128
|
schema: ZodSchema<T>;
|
|
2131
2129
|
defaultValues: T;
|
|
2132
2130
|
}
|
|
2133
2131
|
interface FormErrors {
|
|
2134
2132
|
[key: string]: string;
|
|
2135
2133
|
}
|
|
2136
|
-
declare function useForm<T extends
|
|
2134
|
+
declare function useForm<T extends FormValues>({ schema, defaultValues }: UseFormOptions<T>): {
|
|
2137
2135
|
values: T;
|
|
2138
2136
|
errors: FormErrors;
|
|
2139
2137
|
isValid: boolean;
|
|
2140
2138
|
isDirty: boolean;
|
|
2141
2139
|
isSubmitting: boolean;
|
|
2142
|
-
setValue: (name:
|
|
2143
|
-
getValue: (name:
|
|
2140
|
+
setValue: <K extends FieldName<T>>(name: K, value: T[K]) => void;
|
|
2141
|
+
getValue: <K extends FieldName<T>>(name: K) => T[K];
|
|
2144
2142
|
validate: () => Promise<boolean>;
|
|
2145
|
-
validateField: (name:
|
|
2143
|
+
validateField: (name: FieldName<T>) => Promise<boolean>;
|
|
2146
2144
|
reset: () => void;
|
|
2147
2145
|
handleSubmit: (onSubmit?: (values: T) => void | Promise<void>) => Promise<void>;
|
|
2148
2146
|
};
|
|
@@ -3462,4 +3460,4 @@ interface AlertContextType {
|
|
|
3462
3460
|
*/
|
|
3463
3461
|
declare function useAlert(): AlertContextType;
|
|
3464
3462
|
|
|
3465
|
-
export { ActionIcons, Alert, type AlertContextType, type AlertOptions, type AlertProps, type ApiBusinessErrorParser, type ApiConfig, type ApiEndpointConfig, type ApiErrorContext, type ApiErrorHandler, type ApiMethod, AppButton, type AppButtonProps, type AppError, AppHeader, type AppHeaderProps, AppImage, type AppImageProps, AppInput, type AppInputProps, AppList, type AppListProps, type AppNavigation, AppPressable, type AppPressableProps, AppProvider, type AppProviderProps, AppScrollView, type AppScrollViewProps, AppStatusBar, type AppStatusBarProps, AppText, type AppTextProps, AppView, type AppViewProps, BottomTabBar, Card, type CardProps, Center, type CenterProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, Col, type ColProps, type ColorPalette$1 as ColorPalette, type ColorToken, type CustomBottomTabBarProps, DatePicker, type DatePickerProps, DrawerContent, type DrawerContentProps, type DrawerItem, type DrawerNavigation, DrawerNavigator, type DrawerNavigatorProps, type DrawerOptions, type DrawerParamList, type DrawerRouteConfig, type DrawerScreenOptions, type DrawerScreenProps, ErrorCode, FileIcons, FormItem, type FormItemProps, Icon, type IconProps, type IconSize, type InfiniteFetchParams, type InfiniteFetchResult, type LinkingConfig, Loading, type LoadingContextType, type LoadingProps, type LoadingState, MemoryStorage, NavigationIcons, NavigationProvider, type NavigationProviderProps, type Orientation, OverlayProvider, type OverlayProviderProps, Page, type PaginationParams, type PaginationResult, type ParamListBase, type PathConfig, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RgbObject, type RouteConfig, Row, type RowProps, SafeBottom, SafeScreen, type SafeScreenProps, Select, type SelectOption, type SelectProps, Slider, type SliderProps, type StackNavigation, StackNavigator, type StackNavigatorProps, type StackParamList, type StackRouteConfig, type StackScreenOptions, type StackScreenProps, StatusIcons, Switch, type SwitchProps, type TabBarOptions, type TabNavigation, TabNavigator, type TabNavigatorProps, type TabParamList, type TabRouteConfig, type TabScreenOptions, type TabScreenProps, type Theme, type ColorPalette as ThemeColorPalette, type ThemeConfig, ThemeProvider, Toast, type ToastContextType, type ToastItem, type ToastProps, type ToastType, type UseAsyncState, type UseDimensionsReturn, type UseInfiniteOptions, type UseInfiniteReturn, type UseKeyboardReturn, type UseOrientationReturn, type UsePaginationOptions, type UsePaginationReturn, type UseRefreshReturn, type UseToggleActions, adjustBrightness, capitalize, clamp, cn, createAPI, createDrawerScreens, createNavigationTheme, createStackScreens, createTabScreens, createTheme, deepMerge, enhanceError, formatCurrency, formatDate, formatNumber, formatPercent, formatRelativeTime, generateColorPalette, getThemeColors, getValidationErrors, hexToRgb, isDevelopment, isValidEmail, isValidPhone, mapHttpStatus, omit, pick, rgbToHex, slugify, storage, truncate, useAlert, useAsyncState, useBackHandler, useDebounce, useDimensions, useDrawerNavigation, useForm, useInfinite, useKeyboard, useLoading, useMemoizedFn, useNavigation, useNavigationState, useOrientation, usePagination, usePrevious, useRefresh, useRequest, useRoute, useSetState, useStackNavigation, useStorage, useTabNavigation, useTheme, useThemeColors, useThrottle, useToast, useToggle, useUpdateEffect };
|
|
3463
|
+
export { ActionIcons, Alert, type AlertContextType, type AlertOptions, type AlertProps, type ApiBusinessErrorParser, type ApiConfig, type ApiEndpointConfig, type ApiErrorContext, type ApiErrorHandler, type ApiMethod, AppButton, type AppButtonProps, type AppError, AppHeader, type AppHeaderProps, AppImage, type AppImageProps, AppInput, type AppInputProps, AppList, type AppListProps, type AppNavigation, AppPressable, type AppPressableProps, AppProvider, type AppProviderProps, AppScrollView, type AppScrollViewProps, AppStatusBar, type AppStatusBarProps, AppText, type AppTextProps, AppView, type AppViewProps, BottomTabBar, Card, type CardProps, Center, type CenterProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, Col, type ColProps, type ColorPalette$1 as ColorPalette, type ColorToken, type CustomBottomTabBarProps, DatePicker, type DatePickerProps, DrawerContent, type DrawerContentProps, type DrawerItem, type DrawerNavigation, DrawerNavigator, type DrawerNavigatorProps, type DrawerOptions, type DrawerParamList, type DrawerRouteConfig, type DrawerScreenOptions, type DrawerScreenProps, ErrorCode, FileIcons, type FormErrors, type FormGroupOption, FormItem, type FormItemProps, Icon, type IconProps, type IconSize, type InfiniteFetchParams, type InfiniteFetchResult, type LinkingConfig, Loading, type LoadingContextType, type LoadingProps, type LoadingState, MemoryStorage, NavigationIcons, NavigationProvider, type NavigationProviderProps, type Orientation, OverlayProvider, type OverlayProviderProps, Page, type PaginationParams, type PaginationResult, type ParamListBase, type PathConfig, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RgbObject, type RouteConfig, Row, type RowProps, SafeBottom, SafeScreen, type SafeScreenProps, Select, type SelectOption, type SelectProps, Slider, type SliderProps, type StackNavigation, StackNavigator, type StackNavigatorProps, type StackParamList, type StackRouteConfig, type StackScreenOptions, type StackScreenProps, StatusIcons, Switch, type SwitchProps, type TabBarOptions, type TabNavigation, TabNavigator, type TabNavigatorProps, type TabParamList, type TabRouteConfig, type TabScreenOptions, type TabScreenProps, type Theme, type ColorPalette as ThemeColorPalette, type ThemeConfig, ThemeProvider, Toast, type ToastContextType, type ToastItem, type ToastProps, type ToastType, type UseAsyncState, type UseDimensionsReturn, type UseFormOptions, type UseInfiniteOptions, type UseInfiniteReturn, type UseKeyboardReturn, type UseOrientationReturn, type UsePaginationOptions, type UsePaginationReturn, type UseRefreshReturn, type UseToggleActions, adjustBrightness, capitalize, clamp, cn, createAPI, createDrawerScreens, createNavigationTheme, createStackScreens, createTabScreens, createTheme, deepMerge, enhanceError, formatCurrency, formatDate, formatNumber, formatPercent, formatRelativeTime, generateColorPalette, getThemeColors, getValidationErrors, hexToRgb, isDevelopment, isValidEmail, isValidPhone, mapHttpStatus, omit, pick, rgbToHex, slugify, storage, truncate, useAlert, useAsyncState, useBackHandler, useDebounce, useDimensions, useDrawerNavigation, useForm, useInfinite, useKeyboard, useLoading, useMemoizedFn, useNavigation, useNavigationState, useOrientation, usePagination, usePrevious, useRefresh, useRequest, useRoute, useSetState, useStackNavigation, useStorage, useTabNavigation, useTheme, useThemeColors, useThrottle, useToast, useToggle, useUpdateEffect };
|
package/dist/index.d.ts
CHANGED
|
@@ -1972,15 +1972,16 @@ interface CheckboxProps {
|
|
|
1972
1972
|
*/
|
|
1973
1973
|
declare function Checkbox({ checked, defaultChecked, onChange, disabled, children, className, testID, }: CheckboxProps): react_jsx_runtime.JSX.Element;
|
|
1974
1974
|
|
|
1975
|
-
interface
|
|
1975
|
+
interface FormGroupOption {
|
|
1976
1976
|
label: string;
|
|
1977
1977
|
value: string;
|
|
1978
1978
|
disabled?: boolean;
|
|
1979
1979
|
}
|
|
1980
|
+
|
|
1980
1981
|
interface CheckboxGroupProps {
|
|
1981
1982
|
value?: string[];
|
|
1982
1983
|
onChange?: (value: string[]) => void;
|
|
1983
|
-
options?:
|
|
1984
|
+
options?: FormGroupOption[];
|
|
1984
1985
|
direction?: 'row' | 'column';
|
|
1985
1986
|
disabled?: boolean;
|
|
1986
1987
|
}
|
|
@@ -2003,15 +2004,10 @@ interface RadioProps {
|
|
|
2003
2004
|
*/
|
|
2004
2005
|
declare function Radio({ checked, defaultChecked, onChange, disabled, children, className, testID, }: RadioProps): react_jsx_runtime.JSX.Element;
|
|
2005
2006
|
|
|
2006
|
-
interface Option {
|
|
2007
|
-
label: string;
|
|
2008
|
-
value: string;
|
|
2009
|
-
disabled?: boolean;
|
|
2010
|
-
}
|
|
2011
2007
|
interface RadioGroupProps {
|
|
2012
2008
|
value?: string;
|
|
2013
2009
|
onChange?: (value: string) => void;
|
|
2014
|
-
options?:
|
|
2010
|
+
options?: FormGroupOption[];
|
|
2015
2011
|
direction?: 'row' | 'column';
|
|
2016
2012
|
disabled?: boolean;
|
|
2017
2013
|
}
|
|
@@ -2126,23 +2122,25 @@ interface FormItemProps {
|
|
|
2126
2122
|
}
|
|
2127
2123
|
declare function FormItem({ name: _name, label, error, help, required, children, className, labelClassName, }: FormItemProps): react_jsx_runtime.JSX.Element;
|
|
2128
2124
|
|
|
2129
|
-
|
|
2125
|
+
type FormValues = Record<string, unknown>;
|
|
2126
|
+
type FieldName<T extends FormValues> = Extract<keyof T, string>;
|
|
2127
|
+
interface UseFormOptions<T extends FormValues> {
|
|
2130
2128
|
schema: ZodSchema<T>;
|
|
2131
2129
|
defaultValues: T;
|
|
2132
2130
|
}
|
|
2133
2131
|
interface FormErrors {
|
|
2134
2132
|
[key: string]: string;
|
|
2135
2133
|
}
|
|
2136
|
-
declare function useForm<T extends
|
|
2134
|
+
declare function useForm<T extends FormValues>({ schema, defaultValues }: UseFormOptions<T>): {
|
|
2137
2135
|
values: T;
|
|
2138
2136
|
errors: FormErrors;
|
|
2139
2137
|
isValid: boolean;
|
|
2140
2138
|
isDirty: boolean;
|
|
2141
2139
|
isSubmitting: boolean;
|
|
2142
|
-
setValue: (name:
|
|
2143
|
-
getValue: (name:
|
|
2140
|
+
setValue: <K extends FieldName<T>>(name: K, value: T[K]) => void;
|
|
2141
|
+
getValue: <K extends FieldName<T>>(name: K) => T[K];
|
|
2144
2142
|
validate: () => Promise<boolean>;
|
|
2145
|
-
validateField: (name:
|
|
2143
|
+
validateField: (name: FieldName<T>) => Promise<boolean>;
|
|
2146
2144
|
reset: () => void;
|
|
2147
2145
|
handleSubmit: (onSubmit?: (values: T) => void | Promise<void>) => Promise<void>;
|
|
2148
2146
|
};
|
|
@@ -3462,4 +3460,4 @@ interface AlertContextType {
|
|
|
3462
3460
|
*/
|
|
3463
3461
|
declare function useAlert(): AlertContextType;
|
|
3464
3462
|
|
|
3465
|
-
export { ActionIcons, Alert, type AlertContextType, type AlertOptions, type AlertProps, type ApiBusinessErrorParser, type ApiConfig, type ApiEndpointConfig, type ApiErrorContext, type ApiErrorHandler, type ApiMethod, AppButton, type AppButtonProps, type AppError, AppHeader, type AppHeaderProps, AppImage, type AppImageProps, AppInput, type AppInputProps, AppList, type AppListProps, type AppNavigation, AppPressable, type AppPressableProps, AppProvider, type AppProviderProps, AppScrollView, type AppScrollViewProps, AppStatusBar, type AppStatusBarProps, AppText, type AppTextProps, AppView, type AppViewProps, BottomTabBar, Card, type CardProps, Center, type CenterProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, Col, type ColProps, type ColorPalette$1 as ColorPalette, type ColorToken, type CustomBottomTabBarProps, DatePicker, type DatePickerProps, DrawerContent, type DrawerContentProps, type DrawerItem, type DrawerNavigation, DrawerNavigator, type DrawerNavigatorProps, type DrawerOptions, type DrawerParamList, type DrawerRouteConfig, type DrawerScreenOptions, type DrawerScreenProps, ErrorCode, FileIcons, FormItem, type FormItemProps, Icon, type IconProps, type IconSize, type InfiniteFetchParams, type InfiniteFetchResult, type LinkingConfig, Loading, type LoadingContextType, type LoadingProps, type LoadingState, MemoryStorage, NavigationIcons, NavigationProvider, type NavigationProviderProps, type Orientation, OverlayProvider, type OverlayProviderProps, Page, type PaginationParams, type PaginationResult, type ParamListBase, type PathConfig, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RgbObject, type RouteConfig, Row, type RowProps, SafeBottom, SafeScreen, type SafeScreenProps, Select, type SelectOption, type SelectProps, Slider, type SliderProps, type StackNavigation, StackNavigator, type StackNavigatorProps, type StackParamList, type StackRouteConfig, type StackScreenOptions, type StackScreenProps, StatusIcons, Switch, type SwitchProps, type TabBarOptions, type TabNavigation, TabNavigator, type TabNavigatorProps, type TabParamList, type TabRouteConfig, type TabScreenOptions, type TabScreenProps, type Theme, type ColorPalette as ThemeColorPalette, type ThemeConfig, ThemeProvider, Toast, type ToastContextType, type ToastItem, type ToastProps, type ToastType, type UseAsyncState, type UseDimensionsReturn, type UseInfiniteOptions, type UseInfiniteReturn, type UseKeyboardReturn, type UseOrientationReturn, type UsePaginationOptions, type UsePaginationReturn, type UseRefreshReturn, type UseToggleActions, adjustBrightness, capitalize, clamp, cn, createAPI, createDrawerScreens, createNavigationTheme, createStackScreens, createTabScreens, createTheme, deepMerge, enhanceError, formatCurrency, formatDate, formatNumber, formatPercent, formatRelativeTime, generateColorPalette, getThemeColors, getValidationErrors, hexToRgb, isDevelopment, isValidEmail, isValidPhone, mapHttpStatus, omit, pick, rgbToHex, slugify, storage, truncate, useAlert, useAsyncState, useBackHandler, useDebounce, useDimensions, useDrawerNavigation, useForm, useInfinite, useKeyboard, useLoading, useMemoizedFn, useNavigation, useNavigationState, useOrientation, usePagination, usePrevious, useRefresh, useRequest, useRoute, useSetState, useStackNavigation, useStorage, useTabNavigation, useTheme, useThemeColors, useThrottle, useToast, useToggle, useUpdateEffect };
|
|
3463
|
+
export { ActionIcons, Alert, type AlertContextType, type AlertOptions, type AlertProps, type ApiBusinessErrorParser, type ApiConfig, type ApiEndpointConfig, type ApiErrorContext, type ApiErrorHandler, type ApiMethod, AppButton, type AppButtonProps, type AppError, AppHeader, type AppHeaderProps, AppImage, type AppImageProps, AppInput, type AppInputProps, AppList, type AppListProps, type AppNavigation, AppPressable, type AppPressableProps, AppProvider, type AppProviderProps, AppScrollView, type AppScrollViewProps, AppStatusBar, type AppStatusBarProps, AppText, type AppTextProps, AppView, type AppViewProps, BottomTabBar, Card, type CardProps, Center, type CenterProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, Col, type ColProps, type ColorPalette$1 as ColorPalette, type ColorToken, type CustomBottomTabBarProps, DatePicker, type DatePickerProps, DrawerContent, type DrawerContentProps, type DrawerItem, type DrawerNavigation, DrawerNavigator, type DrawerNavigatorProps, type DrawerOptions, type DrawerParamList, type DrawerRouteConfig, type DrawerScreenOptions, type DrawerScreenProps, ErrorCode, FileIcons, type FormErrors, type FormGroupOption, FormItem, type FormItemProps, Icon, type IconProps, type IconSize, type InfiniteFetchParams, type InfiniteFetchResult, type LinkingConfig, Loading, type LoadingContextType, type LoadingProps, type LoadingState, MemoryStorage, NavigationIcons, NavigationProvider, type NavigationProviderProps, type Orientation, OverlayProvider, type OverlayProviderProps, Page, type PaginationParams, type PaginationResult, type ParamListBase, type PathConfig, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, type RgbObject, type RouteConfig, Row, type RowProps, SafeBottom, SafeScreen, type SafeScreenProps, Select, type SelectOption, type SelectProps, Slider, type SliderProps, type StackNavigation, StackNavigator, type StackNavigatorProps, type StackParamList, type StackRouteConfig, type StackScreenOptions, type StackScreenProps, StatusIcons, Switch, type SwitchProps, type TabBarOptions, type TabNavigation, TabNavigator, type TabNavigatorProps, type TabParamList, type TabRouteConfig, type TabScreenOptions, type TabScreenProps, type Theme, type ColorPalette as ThemeColorPalette, type ThemeConfig, ThemeProvider, Toast, type ToastContextType, type ToastItem, type ToastProps, type ToastType, type UseAsyncState, type UseDimensionsReturn, type UseFormOptions, type UseInfiniteOptions, type UseInfiniteReturn, type UseKeyboardReturn, type UseOrientationReturn, type UsePaginationOptions, type UsePaginationReturn, type UseRefreshReturn, type UseToggleActions, adjustBrightness, capitalize, clamp, cn, createAPI, createDrawerScreens, createNavigationTheme, createStackScreens, createTabScreens, createTheme, deepMerge, enhanceError, formatCurrency, formatDate, formatNumber, formatPercent, formatRelativeTime, generateColorPalette, getThemeColors, getValidationErrors, hexToRgb, isDevelopment, isValidEmail, isValidPhone, mapHttpStatus, omit, pick, rgbToHex, slugify, storage, truncate, useAlert, useAsyncState, useBackHandler, useDebounce, useDimensions, useDrawerNavigation, useForm, useInfinite, useKeyboard, useLoading, useMemoizedFn, useNavigation, useNavigationState, useOrientation, usePagination, usePrevious, useRefresh, useRequest, useRoute, useSetState, useStackNavigation, useStorage, useTabNavigation, useTheme, useThemeColors, useThrottle, useToast, useToggle, useUpdateEffect };
|
package/dist/index.js
CHANGED
|
@@ -2259,6 +2259,17 @@ var styles5 = import_react_native13.StyleSheet.create({
|
|
|
2259
2259
|
}
|
|
2260
2260
|
});
|
|
2261
2261
|
|
|
2262
|
+
// src/ui/form/group.ts
|
|
2263
|
+
var toggleGroupValue = (values, optionValue, checked) => {
|
|
2264
|
+
if (checked) {
|
|
2265
|
+
return values.includes(optionValue) ? values : [...values, optionValue];
|
|
2266
|
+
}
|
|
2267
|
+
return values.filter((value) => value !== optionValue);
|
|
2268
|
+
};
|
|
2269
|
+
var isGroupOptionDisabled = (groupDisabled, optionDisabled) => {
|
|
2270
|
+
return groupDisabled || Boolean(optionDisabled);
|
|
2271
|
+
};
|
|
2272
|
+
|
|
2262
2273
|
// src/ui/form/CheckboxGroup.tsx
|
|
2263
2274
|
var import_jsx_runtime21 = require("nativewind/jsx-runtime");
|
|
2264
2275
|
function CheckboxGroup({
|
|
@@ -2270,18 +2281,15 @@ function CheckboxGroup({
|
|
|
2270
2281
|
}) {
|
|
2271
2282
|
const handleChange = (optionValue, checked) => {
|
|
2272
2283
|
if (!onChange) return;
|
|
2273
|
-
|
|
2274
|
-
onChange([...value, optionValue]);
|
|
2275
|
-
} else {
|
|
2276
|
-
onChange(value.filter((v) => v !== optionValue));
|
|
2277
|
-
}
|
|
2284
|
+
onChange(toggleGroupValue(value, optionValue, checked));
|
|
2278
2285
|
};
|
|
2279
|
-
|
|
2286
|
+
const isRow = direction === "row";
|
|
2287
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AppView, { row: isRow, flex: isRow, gap: 4, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2280
2288
|
Checkbox,
|
|
2281
2289
|
{
|
|
2282
2290
|
checked: value.includes(option.value),
|
|
2283
2291
|
onChange: (checked) => handleChange(option.value, checked),
|
|
2284
|
-
disabled: disabled
|
|
2292
|
+
disabled: isGroupOptionDisabled(disabled, option.disabled),
|
|
2285
2293
|
children: option.label
|
|
2286
2294
|
},
|
|
2287
2295
|
option.value
|
|
@@ -2368,12 +2376,13 @@ function RadioGroup({
|
|
|
2368
2376
|
direction = "column",
|
|
2369
2377
|
disabled = false
|
|
2370
2378
|
}) {
|
|
2371
|
-
|
|
2379
|
+
const isRow = direction === "row";
|
|
2380
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(AppView, { row: isRow, flex: isRow, gap: 4, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2372
2381
|
Radio,
|
|
2373
2382
|
{
|
|
2374
2383
|
checked: value === option.value,
|
|
2375
2384
|
onChange: () => onChange?.(option.value),
|
|
2376
|
-
disabled: disabled
|
|
2385
|
+
disabled: isGroupOptionDisabled(disabled, option.disabled),
|
|
2377
2386
|
children: option.label
|
|
2378
2387
|
},
|
|
2379
2388
|
option.value
|
|
@@ -3223,10 +3232,21 @@ function FormItem({
|
|
|
3223
3232
|
|
|
3224
3233
|
// src/ui/form/useForm.ts
|
|
3225
3234
|
var import_react24 = require("react");
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3235
|
+
var getIssuePath = (issue) => issue.path.map(String).join(".");
|
|
3236
|
+
var getFieldError = (issues, name) => {
|
|
3237
|
+
const exactIssue = issues.find((issue) => getIssuePath(issue) === name);
|
|
3238
|
+
if (exactIssue) return exactIssue.message;
|
|
3239
|
+
const nestedIssue = issues.find((issue) => issue.path[0] === name);
|
|
3240
|
+
return nestedIssue?.message;
|
|
3241
|
+
};
|
|
3242
|
+
var buildFormErrors = (issues) => {
|
|
3243
|
+
return issues.reduce((acc, issue) => {
|
|
3244
|
+
const path = getIssuePath(issue);
|
|
3245
|
+
acc[path || "root"] = issue.message;
|
|
3246
|
+
return acc;
|
|
3247
|
+
}, {});
|
|
3248
|
+
};
|
|
3249
|
+
function useForm({ schema, defaultValues }) {
|
|
3230
3250
|
const [values, setValues] = (0, import_react24.useState)(defaultValues);
|
|
3231
3251
|
const [errors, setErrors] = (0, import_react24.useState)({});
|
|
3232
3252
|
const [isSubmitting, setIsSubmitting] = (0, import_react24.useState)(false);
|
|
@@ -3236,14 +3256,21 @@ function useForm({
|
|
|
3236
3256
|
const isValid = (0, import_react24.useMemo)(() => {
|
|
3237
3257
|
return Object.keys(errors).length === 0;
|
|
3238
3258
|
}, [errors]);
|
|
3239
|
-
const
|
|
3240
|
-
setValues((prev) => ({ ...prev, [name]: value }));
|
|
3259
|
+
const clearFieldError = (0, import_react24.useCallback)((name) => {
|
|
3241
3260
|
setErrors((prev) => {
|
|
3261
|
+
if (!(name in prev)) return prev;
|
|
3242
3262
|
const next = { ...prev };
|
|
3243
3263
|
delete next[name];
|
|
3244
3264
|
return next;
|
|
3245
3265
|
});
|
|
3246
3266
|
}, []);
|
|
3267
|
+
const setValue = (0, import_react24.useCallback)(
|
|
3268
|
+
(name, value) => {
|
|
3269
|
+
setValues((prev) => ({ ...prev, [name]: value }));
|
|
3270
|
+
clearFieldError(name);
|
|
3271
|
+
},
|
|
3272
|
+
[clearFieldError]
|
|
3273
|
+
);
|
|
3247
3274
|
const getValue = (0, import_react24.useCallback)(
|
|
3248
3275
|
(name) => {
|
|
3249
3276
|
return values[name];
|
|
@@ -3252,42 +3279,33 @@ function useForm({
|
|
|
3252
3279
|
);
|
|
3253
3280
|
const validateField = (0, import_react24.useCallback)(
|
|
3254
3281
|
async (name) => {
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
return true;
|
|
3265
|
-
}
|
|
3282
|
+
const fieldName = name;
|
|
3283
|
+
const result = await schema.safeParseAsync(values);
|
|
3284
|
+
if (result.success) {
|
|
3285
|
+
clearFieldError(fieldName);
|
|
3286
|
+
return true;
|
|
3287
|
+
}
|
|
3288
|
+
const errorMessage = getFieldError(result.error.issues, fieldName);
|
|
3289
|
+
if (!errorMessage) {
|
|
3290
|
+
clearFieldError(fieldName);
|
|
3266
3291
|
return true;
|
|
3267
|
-
} catch (error) {
|
|
3268
|
-
setErrors((prev) => ({
|
|
3269
|
-
...prev,
|
|
3270
|
-
[name]: error.errors?.[0]?.message || "\u9A8C\u8BC1\u5931\u8D25"
|
|
3271
|
-
}));
|
|
3272
|
-
return false;
|
|
3273
3292
|
}
|
|
3293
|
+
setErrors((prev) => ({
|
|
3294
|
+
...prev,
|
|
3295
|
+
[fieldName]: errorMessage
|
|
3296
|
+
}));
|
|
3297
|
+
return false;
|
|
3274
3298
|
},
|
|
3275
|
-
[schema, values]
|
|
3299
|
+
[schema, values, clearFieldError]
|
|
3276
3300
|
);
|
|
3277
3301
|
const validate = (0, import_react24.useCallback)(async () => {
|
|
3278
|
-
|
|
3279
|
-
|
|
3302
|
+
const result = await schema.safeParseAsync(values);
|
|
3303
|
+
if (result.success) {
|
|
3280
3304
|
setErrors({});
|
|
3281
3305
|
return true;
|
|
3282
|
-
} catch (error) {
|
|
3283
|
-
const formErrors = {};
|
|
3284
|
-
error.errors?.forEach((err) => {
|
|
3285
|
-
const path = err.path.join(".");
|
|
3286
|
-
formErrors[path] = err.message;
|
|
3287
|
-
});
|
|
3288
|
-
setErrors(formErrors);
|
|
3289
|
-
return false;
|
|
3290
3306
|
}
|
|
3307
|
+
setErrors(buildFormErrors(result.error.issues));
|
|
3308
|
+
return false;
|
|
3291
3309
|
}, [schema, values]);
|
|
3292
3310
|
const reset = (0, import_react24.useCallback)(() => {
|
|
3293
3311
|
setValues(defaultValues);
|