react-hook-form-next-ui 3.0.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/README.md +124 -0
- package/dist/index.d.ts +240 -0
- package/dist/index.js +1417 -0
- package/package.json +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Configure your project
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
|
|
6
|
+
## Demo
|
|
7
|
+
[Storybook - Demo](https://storybook-rhfnextui.web.app)
|
|
8
|
+
|
|
9
|
+
## Install the library
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i react-hook-form-next-ui
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Update tailwind file *(tailwind.config.js)*
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
It is important to import the styles from NextUI and this library.
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
//tailwind.config.js
|
|
22
|
+
import { heroui } from "@heroui/react";
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
content: [
|
|
26
|
+
"./node_modules/react-hook-form-next-ui/dist/**/*.{js,ts,jsx,tsx}",
|
|
27
|
+
"./node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}",
|
|
28
|
+
],
|
|
29
|
+
theme: {
|
|
30
|
+
extend: {},
|
|
31
|
+
},
|
|
32
|
+
plugins: [
|
|
33
|
+
heroui()
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { FormProvider, SubmitHandler, useForm } from "react-hook-form"
|
|
42
|
+
import { Button } from "@heroui/react";
|
|
43
|
+
import RHFInput from "../components/RHFInput";
|
|
44
|
+
import schema from "../static/schema";
|
|
45
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
46
|
+
import { IForm } from "../types/app";
|
|
47
|
+
|
|
48
|
+
const App = () => {
|
|
49
|
+
const methods = useForm<IForm>({
|
|
50
|
+
resolver: yupResolver(schema),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const onSubmit: SubmitHandler<IForm> = async data => {
|
|
54
|
+
console.log("🚀 ~ Event ~ data:", data)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<FormProvider {...methods}>
|
|
59
|
+
<Panel title="Contact Form" collapse>
|
|
60
|
+
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
61
|
+
<RHFInput name="user" label="User Name" color="primary" />
|
|
62
|
+
<Button type="submit">Submit</Button>
|
|
63
|
+
</form>
|
|
64
|
+
</Panel>
|
|
65
|
+
</FormProvider>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
# Yup Schema Helpers (Helper)
|
|
71
|
+
|
|
72
|
+
This documentation provides an overview of custom helpers for validating dates and times, as well as their integration with `yup`.
|
|
73
|
+
|
|
74
|
+
## Summary
|
|
75
|
+
|
|
76
|
+
This set of utilities includes:
|
|
77
|
+
|
|
78
|
+
- **`dateMinMaxValidate`**: Validates a date within a minimum and maximum range.
|
|
79
|
+
- **`dualDateValidate`**: Generates rules to validate date pairs (start and end) with range restrictions.
|
|
80
|
+
- **`dualTimeValidate`**: Validates time pairs (start and end) with range restrictions.
|
|
81
|
+
|
|
82
|
+
## Example
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import * as yup from "yup";
|
|
86
|
+
import { dateMinMaxValidate, dualDateValidate, dualTimeValidate } from "../helpers/yup/dates";
|
|
87
|
+
|
|
88
|
+
const { endDateRule, startDateRule } = dualDateValidate({
|
|
89
|
+
startDate: "date1",
|
|
90
|
+
endDate: "date2",
|
|
91
|
+
range: 2,
|
|
92
|
+
type: "months",
|
|
93
|
+
maxEndDate: "2024-09-28",
|
|
94
|
+
minEndDate: "2024-09-01",
|
|
95
|
+
maxStartDate: "2024-09-28",
|
|
96
|
+
minStartDate: "2024-09-01"
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const { endTimeRule, startTimeRule } = dualTimeValidate({
|
|
100
|
+
endTime: "dualtime2",
|
|
101
|
+
startTime: "dualtime1",
|
|
102
|
+
range: 1,
|
|
103
|
+
type: "hours",
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const rangeValue = dateMinMaxValidate({
|
|
107
|
+
maxDate: "2024-09-05",
|
|
108
|
+
minDate: "2024-09-02"
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const schema = yup
|
|
112
|
+
.object({
|
|
113
|
+
date: rangeValue.required(),
|
|
114
|
+
date1: startDateRule.required(),
|
|
115
|
+
date2: endDateRule.required(),
|
|
116
|
+
dualtime1: startTimeRule.required(),
|
|
117
|
+
dualtime2: endTimeRule.required(),
|
|
118
|
+
}).required();
|
|
119
|
+
|
|
120
|
+
export default schema
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
NPM TOKEN
|
|
124
|
+
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
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { AnyObject } from 'yup';
|
|
2
|
+
import { AutocompleteItemProps } from '@heroui/react';
|
|
3
|
+
import { AutocompleteProps } from '@heroui/react';
|
|
4
|
+
import { ButtonProps } from '@heroui/react';
|
|
5
|
+
import { CheckboxGroupProps } from '@heroui/react';
|
|
6
|
+
import { CheckboxProps } from '@heroui/react';
|
|
7
|
+
import { DatePickerProps } from '@heroui/react';
|
|
8
|
+
import { DateValue } from '@heroui/react';
|
|
9
|
+
import { default as default_2 } from 'react';
|
|
10
|
+
import { InputOtpProps } from '@heroui/react';
|
|
11
|
+
import { InputProps } from '@heroui/react';
|
|
12
|
+
import { MixedSchema } from 'yup';
|
|
13
|
+
import { ModalProps } from '@heroui/react';
|
|
14
|
+
import { RadioGroupProps } from '@heroui/react';
|
|
15
|
+
import { RadioProps } from '@heroui/react';
|
|
16
|
+
import { ReactNode } from 'react';
|
|
17
|
+
import { RegisterOptions } from 'react-hook-form';
|
|
18
|
+
import { SelectItemProps } from '@heroui/react';
|
|
19
|
+
import { SelectProps } from '@heroui/react';
|
|
20
|
+
import { TableColumnProps } from '@heroui/react';
|
|
21
|
+
import { TableProps } from '@heroui/react';
|
|
22
|
+
import { TextAreaProps } from '@heroui/react';
|
|
23
|
+
import { TimeInputProps } from '@heroui/react';
|
|
24
|
+
import { TimeInputValue } from '@heroui/react';
|
|
25
|
+
|
|
26
|
+
declare interface ColumnFormat {
|
|
27
|
+
value: string;
|
|
28
|
+
row: any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare interface ColumnsTableProps extends Omit<TableColumnProps<any>, "children"> {
|
|
32
|
+
format?: ({ value, row }: ColumnFormat) => ReactNode;
|
|
33
|
+
dateFormat?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare const DataTable: ({ hideFilterSearch, loading, isVirtualized, onSelect, selectionMode, inputSearch, hideRowsPerPageOptions, extraTopContent, cellClass, rows, columns, keyRow, itemsName, rowsPerPageOptions, ...props }: DataTableProps) => default_2.JSX.Element;
|
|
37
|
+
|
|
38
|
+
export declare interface DataTableProps extends TableProps {
|
|
39
|
+
rows: any[];
|
|
40
|
+
keyRow?: string;
|
|
41
|
+
rowsPerPageOptions?: RowsPerPageTableProps;
|
|
42
|
+
hideRowsPerPageOptions?: boolean;
|
|
43
|
+
inputSearch?: InputProps;
|
|
44
|
+
hideFilterSearch?: boolean;
|
|
45
|
+
extraTopContent?: ReactNode;
|
|
46
|
+
columns: ColumnsTableProps[];
|
|
47
|
+
loading?: boolean;
|
|
48
|
+
onSelect?: (row: any) => void;
|
|
49
|
+
itemsName?: string;
|
|
50
|
+
cellClass?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const dateMinMaxValidate: ({ minDate, maxDate }: DateMinMaxValueProps) => MixedSchema<DateValue | undefined, AnyObject, undefined, "">;
|
|
54
|
+
|
|
55
|
+
declare interface DateMinMaxValueProps {
|
|
56
|
+
minDate?: string;
|
|
57
|
+
maxDate?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare const dualDateValidate: ({ endDate, startDate, range, type, maxEndDate, maxStartDate, minEndDate, minStartDate }: DualDateValidateProps) => {
|
|
61
|
+
startDateRule: MixedSchema<DateValue | undefined, AnyObject, undefined, "">;
|
|
62
|
+
endDateRule: MixedSchema<DateValue | undefined, AnyObject, undefined, "">;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
declare interface DualDateValidateProps {
|
|
66
|
+
startDate: string;
|
|
67
|
+
endDate: string;
|
|
68
|
+
type?: TypeRangeDateValue;
|
|
69
|
+
range?: number;
|
|
70
|
+
maxStartDate?: string;
|
|
71
|
+
minStartDate?: string;
|
|
72
|
+
maxEndDate?: string;
|
|
73
|
+
minEndDate?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare const dualTimeValidate: ({ endTime, startTime, range, type }: DualTimeValidateProps) => {
|
|
77
|
+
startTimeRule: MixedSchema<TimeInputValue | undefined, AnyObject, undefined, "">;
|
|
78
|
+
endTimeRule: MixedSchema<TimeInputValue | undefined, AnyObject, undefined, "">;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare interface DualTimeValidateProps {
|
|
82
|
+
startTime: string;
|
|
83
|
+
endTime: string;
|
|
84
|
+
range?: number;
|
|
85
|
+
type?: TypeRangeTimeValue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare type Icolor = "danger" | "default" | "primary" | "secondary" | "success" | "warning" | undefined;
|
|
89
|
+
|
|
90
|
+
export declare const Layout: ({ children, title, color }: RHFNextUiLayoutProps) => default_2.JSX.Element;
|
|
91
|
+
|
|
92
|
+
export declare function Modal({ display, onClose, children, title, cancelButton, acceptButton, ...props }: RHFNextUiModalProps): default_2.JSX.Element;
|
|
93
|
+
|
|
94
|
+
export declare const Panel: ({ title, color, children, collapse }: RHFNextUiPanelProps) => default_2.JSX.Element;
|
|
95
|
+
|
|
96
|
+
export declare const RHFAutocomplete: ({ onSelectionChange, defaultSelectedKey, name, data, rules, ...props }: RHFAutocompleteProps) => default_2.JSX.Element;
|
|
97
|
+
|
|
98
|
+
declare interface RHFAutocompleteProps extends Omit<AutocompleteProps, "children" | "defaultItems" | "selectedKey" | "isInvalid" | "errorMessage"> {
|
|
99
|
+
name: string;
|
|
100
|
+
rules?: RegisterOptions;
|
|
101
|
+
data: AutocompleteItemProps[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare const RHFCheckbox: ({ rules, name, ...props }: RHFCheckboxProps) => default_2.JSX.Element;
|
|
105
|
+
|
|
106
|
+
export declare const RHFCheckboxGroup: ({ defaultValue, rules, name, data, ...props }: RHFCheckboxProps_2) => default_2.JSX.Element;
|
|
107
|
+
|
|
108
|
+
declare interface RHFCheckboxProps extends Omit<CheckboxProps, "isSelected" | "isInvalid"> {
|
|
109
|
+
rules?: RegisterOptions;
|
|
110
|
+
name: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare interface RHFCheckboxProps_2 extends Omit<CheckboxGroupProps, "children" | "isInvalid"> {
|
|
114
|
+
rules?: RegisterOptions;
|
|
115
|
+
name: string;
|
|
116
|
+
data: CheckboxProps[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare const RHFDate: ({ name, rules, defaultValue, ...props }: RHFDateProps) => default_2.JSX.Element;
|
|
120
|
+
|
|
121
|
+
declare interface RHFDateProps extends Omit<DatePickerProps, "value" | "errorMessage" | "isInvalid"> {
|
|
122
|
+
name: string;
|
|
123
|
+
rules?: RegisterOptions;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export declare const RHFDualDate: ({ startDate, endDate }: RHFDualDateProps) => default_2.JSX.Element;
|
|
127
|
+
|
|
128
|
+
declare interface RHFDualDateProps {
|
|
129
|
+
startDate: RHFNextUiDate;
|
|
130
|
+
endDate: RHFNextUiDate;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare const RHFDualTime: ({ startTime, endTime }: RHFDualTimeProps) => default_2.JSX.Element;
|
|
134
|
+
|
|
135
|
+
declare interface RHFDualTimeProps {
|
|
136
|
+
startTime: RHFTimeProps_2;
|
|
137
|
+
endTime: RHFTimeProps_2;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export declare const RHFInput: ({ defaultValue, rules, name, classNames, ...props }: RHFInputProps) => default_2.JSX.Element;
|
|
141
|
+
|
|
142
|
+
export declare const RHFInputOtp: ({ defaultValue, rules, name, classNames, ...props }: RHFInputProps_2) => default_2.JSX.Element;
|
|
143
|
+
|
|
144
|
+
declare interface RHFInputProps extends Omit<InputProps, "errorMessage" | "isInvalid"> {
|
|
145
|
+
name: string;
|
|
146
|
+
rules?: RegisterOptions;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare interface RHFInputProps_2 extends Omit<InputOtpProps, "errorMessage" | "isInvalid"> {
|
|
150
|
+
name: string;
|
|
151
|
+
rules?: RegisterOptions;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare interface RHFNextUiDate extends Omit<DatePickerProps, "value" | "errorMessage" | "isInvalid"> {
|
|
155
|
+
name: string;
|
|
156
|
+
rules?: RegisterOptions;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare type RHFNextUiLayoutProps = {
|
|
160
|
+
children: ReactNode;
|
|
161
|
+
title: string;
|
|
162
|
+
color?: Icolor;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
declare interface RHFNextUiModalProps extends Omit<ModalProps, "onOpenChange" | "isOpen"> {
|
|
166
|
+
display: boolean;
|
|
167
|
+
children: ReactNode;
|
|
168
|
+
title?: string;
|
|
169
|
+
onClose: () => void;
|
|
170
|
+
cancelButton?: ButtonProps;
|
|
171
|
+
acceptButton?: ButtonProps;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare interface RHFNextUiPanelProps {
|
|
175
|
+
title: string;
|
|
176
|
+
children: ReactNode;
|
|
177
|
+
color?: Icolor;
|
|
178
|
+
collapse?: boolean;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export declare const RHFRadioGroup: ({ data, rules, name, defaultValue, ...props }: RHFRadioGroupProps) => default_2.JSX.Element;
|
|
182
|
+
|
|
183
|
+
declare interface RHFRadioGroupProps extends Omit<RadioGroupProps, "isInvalid" | "errorMessage"> {
|
|
184
|
+
rules?: RegisterOptions;
|
|
185
|
+
data: RadioProps[];
|
|
186
|
+
name: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export declare const RHFSelect: ({ name, data, rules, defaultSelectedKeys, disabledKeys, renderValue, allOptions, allSelectText, onSelectionChange, selectionMode, ...props }: RHFSelectProps) => default_2.JSX.Element;
|
|
190
|
+
|
|
191
|
+
declare interface RHFSelectProps extends Omit<SelectProps, "children" | "items" | "selectedKeys" | "errorMessage" | "isInvalid"> {
|
|
192
|
+
name: string;
|
|
193
|
+
rules?: RegisterOptions;
|
|
194
|
+
data: SelectItemProps[];
|
|
195
|
+
allOptions?: Omit<SelectItemProps, "key">;
|
|
196
|
+
allSelectText?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export declare const RHFTextArea: ({ defaultValue, rules, name, classNames, ...props }: RHFTextAreaProps) => default_2.JSX.Element;
|
|
200
|
+
|
|
201
|
+
declare interface RHFTextAreaProps extends Omit<TextAreaProps, "errorMessage" | "isInvalid"> {
|
|
202
|
+
name: string;
|
|
203
|
+
rules?: RegisterOptions;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export declare const RHFTime: ({ name, rules, defaultValue, ...props }: RHFTimeProps) => default_2.JSX.Element;
|
|
207
|
+
|
|
208
|
+
declare interface RHFTimeProps extends Omit<TimeInputProps, "value" | "errorMessage" | "isInvalid"> {
|
|
209
|
+
name: string;
|
|
210
|
+
rules?: RegisterOptions;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
declare interface RHFTimeProps_2 extends Omit<TimeInputProps, "value" | "errorMessage" | "isInvalid"> {
|
|
214
|
+
rules?: RegisterOptions;
|
|
215
|
+
name: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
declare interface RowsPerPageTableProps {
|
|
219
|
+
default: number;
|
|
220
|
+
options: number[];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export declare interface SkeletonTableProps {
|
|
224
|
+
size?: number;
|
|
225
|
+
columns: ColumnsTableProps[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
declare type TypeRangeDateValue = "days" | "months" | "years";
|
|
229
|
+
|
|
230
|
+
declare type TypeRangeTimeValue = "hours" | "minutes";
|
|
231
|
+
|
|
232
|
+
export declare namespace validation {
|
|
233
|
+
export {
|
|
234
|
+
dualDateValidate,
|
|
235
|
+
dateMinMaxValidate,
|
|
236
|
+
dualTimeValidate
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export { }
|