react-hook-form-next-ui 1.3.30 → 2.1.1

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.
Files changed (4) hide show
  1. package/README.md +104 -35
  2. package/dist/index.d.ts +56 -69
  3. package/dist/index.js +1228 -621
  4. package/package.json +51 -35
package/README.md CHANGED
@@ -1,50 +1,119 @@
1
- # React + TypeScript + Vite
1
+ # Configure your project
2
2
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3
+ This library is based on NextUI and React-hook-form. Here you will find form components where we combine these two libraries for easier and faster use. There is also refactoring of components (currently modal and table) for faster and more complete use of all functions.
4
4
 
5
- Currently, two official plugins are available:
6
5
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
6
+ ## Demo
7
+ [Storybook - Demo](https://storybook-rhfnextui.web.app)
9
8
 
10
- ## Expanding the ESLint configuration
9
+ ## Install the library
11
10
 
12
- If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
11
+ ```bash
12
+ npm i react-hook-form-next-ui
13
+ ```
14
+
15
+ ## Update tailwind file *(tailwind.config.js)*
13
16
 
14
- - Configure the top-level `parserOptions` property like this:
17
+
18
+ It is important to import the styles from NextUI and this library.
15
19
 
16
20
  ```js
17
- export default tseslint.config({
18
- languageOptions: {
19
- // other options...
20
- parserOptions: {
21
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
22
- tsconfigRootDir: import.meta.dirname,
23
- },
21
+ export default {
22
+ content: [
23
+ "./node_modules/react-hook-form-next-ui/dist/**/*.{js,ts,jsx,tsx}",
24
+ "./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}",
25
+ ],
26
+ theme: {
27
+ extend: {},
24
28
  },
25
- })
29
+ plugins: [
30
+ nextui()
31
+ ]
32
+ }
26
33
  ```
27
34
 
28
- - Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29
- - Optionally add `...tseslint.configs.stylisticTypeChecked`
30
- - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
35
+ ## Example
31
36
 
32
37
  ```js
33
- // eslint.config.js
34
- import react from 'eslint-plugin-react'
35
-
36
- export default tseslint.config({
37
- // Set the react version
38
- settings: { react: { version: '18.3' } },
39
- plugins: {
40
- // Add the react plugin
41
- react,
42
- },
43
- rules: {
44
- // other rules...
45
- // Enable its recommended rules
46
- ...react.configs.recommended.rules,
47
- ...react.configs['jsx-runtime'].rules,
48
- },
38
+ import { FormProvider, SubmitHandler, useForm } from "react-hook-form"
39
+ import { Button } from "@nextui-org/react";
40
+ import RHFInput from "../components/RHFInput";
41
+ import schema from "../static/schema";
42
+ import { yupResolver } from "@hookform/resolvers/yup";
43
+ import { IForm } from "../types/app";
44
+
45
+ const App = () => {
46
+ const methods = useForm<IForm>({
47
+ resolver: yupResolver(schema),
48
+ });
49
+
50
+ const onSubmit: SubmitHandler<IForm> = async data => {
51
+ console.log("🚀 ~ Event ~ data:", data)
52
+ }
53
+
54
+ return (
55
+ <FormProvider {...methods}>
56
+ <Panel title="Contact Form" collapse>
57
+ <form onSubmit={methods.handleSubmit(onSubmit)}>
58
+ <RHFInput name="user" label="User Name" color="primary" />
59
+ <Button type="submit">Submit</Button>
60
+ </form>
61
+ </Panel>
62
+ </FormProvider>
63
+ )
64
+ }
65
+ ```
66
+
67
+ # Yup Schema Helpers (Helper)
68
+
69
+ This documentation provides an overview of custom helpers for validating dates and times, as well as their integration with `yup`.
70
+
71
+ ## Summary
72
+
73
+ This set of utilities includes:
74
+
75
+ - **`dateMinMaxValidate`**: Validates a date within a minimum and maximum range.
76
+ - **`dualDateValidate`**: Generates rules to validate date pairs (start and end) with range restrictions.
77
+ - **`dualTimeValidate`**: Validates time pairs (start and end) with range restrictions.
78
+
79
+ ## Example
80
+
81
+ ```js
82
+ import * as yup from "yup";
83
+ import { dateMinMaxValidate, dualDateValidate, dualTimeValidate } from "../helpers/yup/dates";
84
+
85
+ const { endDateRule, startDateRule } = dualDateValidate({
86
+ startDate: "date1",
87
+ endDate: "date2",
88
+ range: 2,
89
+ type: "months",
90
+ maxEndDate: "2024-09-28",
91
+ minEndDate: "2024-09-01",
92
+ maxStartDate: "2024-09-28",
93
+ minStartDate: "2024-09-01"
94
+ });
95
+
96
+ const { endTimeRule, startTimeRule } = dualTimeValidate({
97
+ endTime: "dualtime2",
98
+ startTime: "dualtime1",
99
+ range: 1,
100
+ type: "hours",
101
+ })
102
+
103
+ const rangeValue = dateMinMaxValidate({
104
+ maxDate: "2024-09-05",
105
+ minDate: "2024-09-02"
49
106
  })
107
+
108
+ const schema = yup
109
+ .object({
110
+ date: rangeValue.required(),
111
+ date1: startDateRule.required(),
112
+ date2: endDateRule.required(),
113
+ dualtime1: startTimeRule.required(),
114
+ dualtime2: endTimeRule.required(),
115
+ }).required();
116
+
117
+ export default schema
50
118
  ```
119
+
package/dist/index.d.ts CHANGED
@@ -1,17 +1,21 @@
1
1
  import { AnyObject } from 'yup';
2
+ import { AutocompleteItemProps } from '@nextui-org/react';
2
3
  import { AutocompleteProps } from '@nextui-org/react';
3
4
  import { ButtonProps } from '@nextui-org/react';
5
+ import { CheckboxGroupProps } from '@nextui-org/react';
6
+ import { CheckboxProps } from '@nextui-org/react';
4
7
  import { DatePickerProps } from '@nextui-org/react';
5
8
  import { DateValue } from '@nextui-org/react';
6
9
  import { default as default_2 } from 'react';
10
+ import { InputOtpProps } from '@nextui-org/react';
7
11
  import { InputProps } from '@nextui-org/react';
8
- import { LocaleObject } from 'yup';
9
12
  import { MixedSchema } from 'yup';
10
13
  import { ModalProps } from '@nextui-org/react';
11
14
  import { RadioGroupProps } from '@nextui-org/react';
12
15
  import { RadioProps } from '@nextui-org/react';
13
16
  import { ReactNode } from 'react';
14
17
  import { RegisterOptions } from 'react-hook-form';
18
+ import { SelectItemProps } from '@nextui-org/react';
15
19
  import { SelectProps } from '@nextui-org/react';
16
20
  import { TableColumnProps } from '@nextui-org/react';
17
21
  import { TableProps } from '@nextui-org/react';
@@ -19,51 +23,38 @@ import { TextAreaProps } from '@nextui-org/react';
19
23
  import { TimeInputProps } from '@nextui-org/react';
20
24
  import { TimeInputValue } from '@nextui-org/react';
21
25
 
22
- declare const array: LocaleObject['array'];
23
-
24
- declare const boolean: LocaleObject['boolean'];
25
-
26
- declare interface ButtonModalFooter extends Omit<ButtonProps, "onClick"> {
26
+ declare interface AcceptButton extends Omit<ButtonProps, "onClick"> {
27
27
  onClick: () => void | Promise<void>;
28
28
  }
29
29
 
30
- export declare interface ColumnsTableProps extends Omit<TableColumnProps<any>, "children"> {
31
- export?: boolean;
32
- dateFormat?: IdateFormats;
33
- renderRow?: ({ value, row }: ReturnRowTable) => ReactNode;
34
- }
35
-
36
- declare interface DataOptionsRHFAutocomplete {
37
- key: string;
38
- label: string;
30
+ declare interface ColumnFormat {
31
+ value: string;
32
+ row: any;
39
33
  }
40
34
 
41
- declare interface DataOptionsRHFSelect {
42
- key: string;
43
- label: string;
35
+ export declare interface ColumnsTableProps extends Omit<TableColumnProps<any>, "children"> {
36
+ format?: ({ value, row }: ColumnFormat) => ReactNode;
37
+ dateFormat?: string;
44
38
  }
45
39
 
46
- export declare const DataTable: ({ rows, columns, showFilter, loading, keyRow, buttonExcelExport, exportName, skeletonSize, selectionMode, inputSearch, showHandlePaginate, defaultSelectedKeys, onSelect, defaultPaginateNumber, cellClass, excelExport, ...props }: DataTableProps) => default_2.JSX.Element;
40
+ export declare const DataTable: ({ rows, columns, showFilter, loading, keyRow, defaultSelectedKeys, itemsName, selectionMode, inputSearch, showHandlePaginate, extraTopContent, cellClass, onSelect, defaultPaginateNumber, optionsPaginateNumber, ...props }: DataTableProps) => default_2.JSX.Element;
47
41
 
48
- declare interface DataTableProps extends TableProps {
49
- buttonExcelExport?: Omit<ButtonProps, "onClick">;
42
+ export declare interface DataTableProps extends TableProps {
50
43
  inputSearch?: InputProps;
51
- excelExport?: boolean;
52
- exportName?: string;
44
+ extraTopContent?: ReactNode;
53
45
  rows: any[];
54
46
  columns: ColumnsTableProps[];
55
47
  loading?: boolean;
56
48
  showFilter?: boolean;
57
- showHandlePaginate?: boolean;
58
49
  onSelect?: (row: any) => void;
59
- defaultPaginateNumber?: 5 | 10 | 15;
50
+ showHandlePaginate?: boolean;
51
+ defaultPaginateNumber?: number;
52
+ optionsPaginateNumber?: number[];
53
+ itemsName?: string;
60
54
  cellClass?: string;
61
- skeletonSize?: number;
62
55
  keyRow?: string;
63
56
  }
64
57
 
65
- declare const date: LocaleObject['date'];
66
-
67
58
  declare const dateMinMaxValidate: ({ minDate, maxDate }: DateMinMaxValueProps) => MixedSchema<DateValue | undefined, AnyObject, undefined, "">;
68
59
 
69
60
  declare interface DateMinMaxValueProps {
@@ -101,32 +92,33 @@ declare interface DualTimeValidateProps {
101
92
 
102
93
  declare type Icolor = "danger" | "default" | "primary" | "secondary" | "success" | "warning" | undefined;
103
94
 
104
- declare type IdateFormats = "DD/MM/YYYY" | "DD/MM/YYYY HH:mm" | "DD-MM-YYYY hh:mm" | "DD-MM-YYYY HH:mm" | "DD-MM-YYYY hh:mm";
105
-
106
95
  export declare const Layout: ({ children, title, color }: RHFNextUiLayoutProps) => default_2.JSX.Element;
107
96
 
108
- declare const mixed: LocaleObject['mixed'];
109
-
110
97
  export declare function Modal({ display, children, title, onCancel, cancelButton, acceptButton, ...props }: RHFNextUiModalProps): default_2.JSX.Element;
111
98
 
112
- declare const number: LocaleObject['number'];
99
+ export declare const Panel: ({ title, color, children, collapse }: RHFNextUiPanelProps) => default_2.JSX.Element;
113
100
 
114
- declare const object: LocaleObject['object'];
101
+ export declare const RHFAutocomplete: ({ onSelectionChange, defaultSelectedKey, name, data, rules, ...props }: RHFAutocompleteProps) => default_2.JSX.Element;
115
102
 
116
- export declare const Panel: ({ title, color, children }: RHFNextUiPanelProps) => default_2.JSX.Element;
117
-
118
- declare interface ReturnRowTable {
119
- value: string;
120
- row: any;
103
+ declare interface RHFAutocompleteProps extends Omit<AutocompleteProps, "children"> {
104
+ name: string;
105
+ rules?: RegisterOptions;
106
+ data: AutocompleteItemProps[];
121
107
  }
122
108
 
123
- export declare const RHFAutocomplete: ({ onSelectionChange, defaultValue, name, data, rules, ...props }: RHFAutocompleteProps) => default_2.JSX.Element;
109
+ export declare const RHFCheckbox: ({ rules, name, ...props }: RHFCheckboxProps) => default_2.JSX.Element;
124
110
 
125
- declare interface RHFAutocompleteProps extends Omit<AutocompleteProps, "children"> {
111
+ export declare const RHFCheckboxGroup: ({ defaultValue, rules, name, data, ...props }: RHFCheckboxProps_2) => default_2.JSX.Element;
112
+
113
+ declare interface RHFCheckboxProps extends CheckboxProps {
114
+ rules?: RegisterOptions;
126
115
  name: string;
116
+ }
117
+
118
+ declare interface RHFCheckboxProps_2 extends CheckboxGroupProps {
127
119
  rules?: RegisterOptions;
128
- data: DataOptionsRHFAutocomplete[];
129
- defaultValue?: string;
120
+ name: string;
121
+ data: CheckboxProps[];
130
122
  }
131
123
 
132
124
  export declare const RHFDate: ({ name, rules, defaultValue, ...props }: RHFDateProps) => default_2.JSX.Element;
@@ -152,11 +144,18 @@ declare interface RHFDualTimeProps {
152
144
 
153
145
  export declare const RHFInput: ({ defaultValue, rules, name, classNames, ...props }: RHFInputProps) => default_2.JSX.Element;
154
146
 
147
+ export declare const RHFInputOtp: ({ defaultValue, rules, name, classNames, ...props }: RHFInputProps_2) => default_2.JSX.Element;
148
+
155
149
  declare interface RHFInputProps extends InputProps {
156
150
  name: string;
157
151
  rules?: RegisterOptions;
158
152
  }
159
153
 
154
+ declare interface RHFInputProps_2 extends InputOtpProps {
155
+ name: string;
156
+ rules?: RegisterOptions;
157
+ }
158
+
160
159
  declare interface RHFNextUiDate extends DatePickerProps {
161
160
  name: string;
162
161
  rules?: RegisterOptions;
@@ -172,37 +171,34 @@ declare interface RHFNextUiModalProps extends ModalProps {
172
171
  display: boolean;
173
172
  onCancel: () => void;
174
173
  title?: string;
175
- cancelButton?: Omit<ButtonModalFooter, "onClick">;
176
- acceptButton?: ButtonModalFooter;
174
+ cancelButton?: ButtonProps;
175
+ acceptButton?: AcceptButton;
176
+ children: ReactNode;
177
177
  }
178
178
 
179
179
  declare interface RHFNextUiPanelProps {
180
180
  title: string;
181
181
  children: ReactNode;
182
182
  color?: Icolor;
183
+ collapse?: boolean;
183
184
  }
184
185
 
185
- export declare const RHFRadioGroup: ({ radio, data, rules, name, defaultValue, ...props }: RHFRadioGroupProps) => default_2.JSX.Element;
186
-
187
- declare interface RHFRadioGroupDataProps {
188
- key: string;
189
- label: string;
190
- }
186
+ export declare const RHFRadioGroup: ({ data, rules, name, defaultValue, ...props }: RHFRadioGroupProps) => default_2.JSX.Element;
191
187
 
192
188
  declare interface RHFRadioGroupProps extends RadioGroupProps {
193
189
  rules?: RegisterOptions;
194
- radio?: RadioProps;
195
- data: RHFRadioGroupDataProps[];
190
+ data: RadioProps[];
196
191
  name: string;
197
192
  }
198
193
 
199
- export declare const RHFSelect: ({ name, data, rules, defaultOptions, ...props }: RHFSelectProps) => default_2.JSX.Element;
194
+ export declare const RHFSelect: ({ name, data, rules, defaultSelectedKeys, allOptions, allSelectText, onSelectionChange, ...props }: RHFSelectProps) => default_2.JSX.Element;
200
195
 
201
196
  declare interface RHFSelectProps extends Omit<SelectProps, "children"> {
202
- data: DataOptionsRHFSelect[];
203
197
  name: string;
204
198
  rules?: RegisterOptions;
205
- defaultOptions?: string;
199
+ data: SelectItemProps[];
200
+ allOptions?: Omit<SelectItemProps, "key">;
201
+ allSelectText?: string;
206
202
  }
207
203
 
208
204
  export declare const RHFTextArea: ({ defaultValue, rules, name, classNames, ...props }: RHFTextAreaProps) => default_2.JSX.Element;
@@ -224,7 +220,10 @@ declare interface RHFTimeProps_2 extends TimeInputProps {
224
220
  name: string;
225
221
  }
226
222
 
227
- declare const string: LocaleObject['string'];
223
+ export declare interface SkeletonTableProps {
224
+ size?: number;
225
+ columns: ColumnsTableProps[];
226
+ }
228
227
 
229
228
  declare type TypeRangeDateValue = "days" | "months" | "years";
230
229
 
@@ -238,16 +237,4 @@ export declare namespace validation {
238
237
  }
239
238
  }
240
239
 
241
- export declare namespace yupEs {
242
- export {
243
- mixed,
244
- string,
245
- number,
246
- date,
247
- boolean,
248
- object,
249
- array
250
- }
251
- }
252
-
253
240
  export { }