@skybin-tech/nebula-ui 0.0.26 → 0.0.28
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 +6 -4
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +24 -0
- package/dist/cjs/components/Accordion/Accordion.cjs +20 -10
- package/dist/cjs/components/Accordion/Accordion.cjs.map +1 -1
- package/dist/cjs/components/Alert/Alert.cjs +19 -9
- package/dist/cjs/components/Alert/Alert.cjs.map +1 -1
- package/dist/cjs/components/Avatar/Avatar.cjs +19 -9
- package/dist/cjs/components/Avatar/Avatar.cjs.map +1 -1
- package/dist/cjs/components/Badge/Badge.cjs +8 -7
- package/dist/cjs/components/Badge/Badge.cjs.map +1 -1
- package/dist/cjs/components/Button/Button.cjs +37 -47
- package/dist/cjs/components/Button/Button.cjs.map +1 -1
- package/dist/cjs/components/Card/Card.cjs +31 -12
- package/dist/cjs/components/Card/Card.cjs.map +1 -1
- package/dist/cjs/components/Checkbox/Checkbox.cjs +12 -7
- package/dist/cjs/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs +55 -21
- package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
- package/dist/cjs/components/Form/Checkbox.cjs +128 -142
- package/dist/cjs/components/Form/Checkbox.cjs.map +1 -1
- package/dist/cjs/components/Form/Form.cjs +106 -105
- package/dist/cjs/components/Form/Form.cjs.map +1 -1
- package/dist/cjs/components/Form/FormSwitch.cjs +126 -0
- package/dist/cjs/components/Form/FormSwitch.cjs.map +1 -0
- package/dist/cjs/components/Form/Radio.cjs +157 -172
- package/dist/cjs/components/Form/Radio.cjs.map +1 -1
- package/dist/cjs/components/Form/Select.cjs +131 -0
- package/dist/cjs/components/Form/Select.cjs.map +1 -0
- package/dist/cjs/components/Form/TextArea.cjs +137 -152
- package/dist/cjs/components/Form/TextArea.cjs.map +1 -1
- package/dist/cjs/components/Form/TextBox.cjs +184 -206
- package/dist/cjs/components/Form/TextBox.cjs.map +1 -1
- package/dist/cjs/components/Form/context.cjs +109 -122
- package/dist/cjs/components/Form/context.cjs.map +1 -1
- package/dist/cjs/components/Form/hooks.cjs +34 -24
- package/dist/cjs/components/Form/hooks.cjs.map +1 -1
- package/dist/cjs/components/Form/index.cjs +29 -0
- package/dist/cjs/components/Form/variants.cjs +14 -14
- package/dist/cjs/components/Form/variants.cjs.map +1 -1
- package/dist/cjs/components/Input/Input.cjs +11 -7
- package/dist/cjs/components/Input/Input.cjs.map +1 -1
- package/dist/cjs/components/Label/Label.cjs +11 -7
- package/dist/cjs/components/Label/Label.cjs.map +1 -1
- package/dist/cjs/components/Pagination/Pagination.cjs +58 -95
- package/dist/cjs/components/Pagination/Pagination.cjs.map +1 -1
- package/dist/cjs/components/Separator/Separator.cjs +11 -7
- package/dist/cjs/components/Separator/Separator.cjs.map +1 -1
- package/dist/cjs/components/Skeleton/Skeleton.cjs +7 -6
- package/dist/cjs/components/Skeleton/Skeleton.cjs.map +1 -1
- package/dist/cjs/components/Switch/Switch.cjs +14 -0
- package/dist/cjs/components/Switch/Switch.cjs.map +1 -0
- package/dist/cjs/components/Tabs/Tabs.cjs +23 -10
- package/dist/cjs/components/Tabs/Tabs.cjs.map +1 -1
- package/dist/cjs/components/Textarea/Textarea.cjs +11 -7
- package/dist/cjs/components/Textarea/Textarea.cjs.map +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.cjs +14 -10
- package/dist/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
- package/dist/cjs/hooks/useDebounce.cjs +22 -14
- package/dist/cjs/hooks/useDebounce.cjs.map +1 -1
- package/dist/cjs/hooks/useToast.cjs +105 -84
- package/dist/cjs/hooks/useToast.cjs.map +1 -1
- package/dist/cjs/hooks/useToggle.cjs +15 -9
- package/dist/cjs/hooks/useToggle.cjs.map +1 -1
- package/dist/cjs/index.cjs +172 -170
- package/dist/cjs/primitives/accordion.cjs +38 -61
- package/dist/cjs/primitives/accordion.cjs.map +1 -1
- package/dist/cjs/primitives/alert.cjs +33 -63
- package/dist/cjs/primitives/alert.cjs.map +1 -1
- package/dist/cjs/primitives/avatar.cjs +29 -58
- package/dist/cjs/primitives/avatar.cjs.map +1 -1
- package/dist/cjs/primitives/badge.cjs +26 -27
- package/dist/cjs/primitives/badge.cjs.map +1 -1
- package/dist/cjs/primitives/button.cjs +44 -63
- package/dist/cjs/primitives/button.cjs.map +1 -1
- package/dist/cjs/primitives/calendar.cjs +41 -44
- package/dist/cjs/primitives/calendar.cjs.map +1 -1
- package/dist/cjs/primitives/card.cjs +39 -70
- package/dist/cjs/primitives/card.cjs.map +1 -1
- package/dist/cjs/primitives/checkbox.cjs +22 -45
- package/dist/cjs/primitives/checkbox.cjs.map +1 -1
- package/dist/cjs/primitives/command.cjs +65 -73
- package/dist/cjs/primitives/command.cjs.map +1 -1
- package/dist/cjs/primitives/dialog.cjs +55 -84
- package/dist/cjs/primitives/dialog.cjs.map +1 -1
- package/dist/cjs/primitives/dropdown-menu.cjs +82 -153
- package/dist/cjs/primitives/dropdown-menu.cjs.map +1 -1
- package/dist/cjs/primitives/input.cjs +17 -39
- package/dist/cjs/primitives/input.cjs.map +1 -1
- package/dist/cjs/primitives/label.cjs +19 -38
- package/dist/cjs/primitives/label.cjs.map +1 -1
- package/dist/cjs/primitives/popover.cjs +22 -42
- package/dist/cjs/primitives/popover.cjs.map +1 -1
- package/dist/cjs/primitives/radio-group.cjs +31 -50
- package/dist/cjs/primitives/radio-group.cjs.map +1 -1
- package/dist/cjs/primitives/scroll-area.cjs +33 -55
- package/dist/cjs/primitives/scroll-area.cjs.map +1 -1
- package/dist/cjs/primitives/select.cjs +76 -133
- package/dist/cjs/primitives/select.cjs.map +1 -1
- package/dist/cjs/primitives/separator.cjs +20 -42
- package/dist/cjs/primitives/separator.cjs.map +1 -1
- package/dist/cjs/primitives/skeleton.cjs +10 -12
- package/dist/cjs/primitives/skeleton.cjs.map +1 -1
- package/dist/cjs/primitives/sonner.cjs +16 -20
- package/dist/cjs/primitives/sonner.cjs.map +1 -1
- package/dist/cjs/primitives/switch.cjs +19 -45
- package/dist/cjs/primitives/switch.cjs.map +1 -1
- package/dist/cjs/primitives/table.cjs +52 -61
- package/dist/cjs/primitives/table.cjs.map +1 -1
- package/dist/cjs/primitives/tabs.cjs +30 -62
- package/dist/cjs/primitives/tabs.cjs.map +1 -1
- package/dist/cjs/primitives/textarea.cjs +15 -35
- package/dist/cjs/primitives/textarea.cjs.map +1 -1
- package/dist/cjs/primitives/textbox.cjs +17 -39
- package/dist/cjs/primitives/textbox.cjs.map +1 -1
- package/dist/cjs/primitives/toast.cjs +59 -107
- package/dist/cjs/primitives/toast.cjs.map +1 -1
- package/dist/cjs/primitives/toggle.cjs +39 -55
- package/dist/cjs/primitives/toggle.cjs.map +1 -1
- package/dist/cjs/primitives/tooltip.cjs +21 -41
- package/dist/cjs/primitives/tooltip.cjs.map +1 -1
- package/dist/cjs/utils/cn.cjs +11 -6
- package/dist/cjs/utils/cn.cjs.map +1 -1
- package/dist/components/Accordion/Accordion.js +20 -13
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Alert/Alert.js +19 -11
- package/dist/components/Alert/Alert.js.map +1 -1
- package/dist/components/Avatar/Avatar.js +19 -11
- package/dist/components/Avatar/Avatar.js.map +1 -1
- package/dist/components/Badge/Badge.d.ts +1 -1
- package/dist/components/Badge/Badge.d.ts.map +1 -1
- package/dist/components/Badge/Badge.js +8 -8
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Button/Button.js +37 -48
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Card/Card.js +31 -17
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.js +12 -7
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +4 -4
- package/dist/components/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.js +55 -35
- package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/dist/components/Form/Checkbox.js +126 -140
- package/dist/components/Form/Checkbox.js.map +1 -1
- package/dist/components/Form/Form.d.ts +1 -1
- package/dist/components/Form/Form.d.ts.map +1 -1
- package/dist/components/Form/Form.js +104 -103
- package/dist/components/Form/Form.js.map +1 -1
- package/dist/components/Form/{Switch.d.ts → FormSwitch.d.ts} +3 -3
- package/dist/components/Form/FormSwitch.d.ts.map +1 -0
- package/dist/components/Form/FormSwitch.js +126 -0
- package/dist/components/Form/FormSwitch.js.map +1 -0
- package/dist/components/Form/Radio.d.ts +1 -1
- package/dist/components/Form/Radio.d.ts.map +1 -1
- package/dist/components/Form/Radio.js +155 -171
- package/dist/components/Form/Radio.js.map +1 -1
- package/dist/components/Form/Select.d.ts +1 -1
- package/dist/components/Form/Select.d.ts.map +1 -1
- package/dist/components/Form/Select.js +131 -0
- package/dist/components/Form/Select.js.map +1 -0
- package/dist/components/Form/TextArea.js +134 -149
- package/dist/components/Form/TextArea.js.map +1 -1
- package/dist/components/Form/TextBox.js +179 -201
- package/dist/components/Form/TextBox.js.map +1 -1
- package/dist/components/Form/context.d.ts +3 -5
- package/dist/components/Form/context.d.ts.map +1 -1
- package/dist/components/Form/context.js +109 -125
- package/dist/components/Form/context.js.map +1 -1
- package/dist/components/Form/hooks.js +35 -28
- package/dist/components/Form/hooks.js.map +1 -1
- package/dist/components/Form/index.d.ts +4 -4
- package/dist/components/Form/index.d.ts.map +1 -1
- package/dist/components/Form/index.js +11 -0
- package/dist/components/Form/variants.js +15 -14
- package/dist/components/Form/variants.js.map +1 -1
- package/dist/components/Input/Input.js +11 -7
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Label/Label.js +11 -7
- package/dist/components/Label/Label.js.map +1 -1
- package/dist/components/Pagination/Pagination.d.ts +5 -5
- package/dist/components/Pagination/Pagination.js +55 -83
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Separator/Separator.js +11 -7
- package/dist/components/Separator/Separator.js.map +1 -1
- package/dist/components/Skeleton/Skeleton.d.ts +1 -1
- package/dist/components/Skeleton/Skeleton.d.ts.map +1 -1
- package/dist/components/Skeleton/Skeleton.js +7 -6
- package/dist/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/components/Switch/Switch.d.ts +4 -1
- package/dist/components/Switch/Switch.d.ts.map +1 -1
- package/dist/components/Switch/Switch.js +14 -0
- package/dist/components/Switch/Switch.js.map +1 -0
- package/dist/components/Switch/index.d.ts +1 -0
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/Tabs/Tabs.js +23 -13
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/Textarea/Textarea.js +11 -7
- package/dist/components/Textarea/Textarea.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.js +14 -13
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/hooks/useDebounce.js +23 -15
- package/dist/hooks/useDebounce.js.map +1 -1
- package/dist/hooks/useToast.js +103 -69
- package/dist/hooks/useToast.js.map +1 -1
- package/dist/hooks/useToggle.js +16 -10
- package/dist/hooks/useToggle.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -160
- package/dist/primitives/accordion.js +32 -43
- package/dist/primitives/accordion.js.map +1 -1
- package/dist/primitives/alert.js +30 -47
- package/dist/primitives/alert.js.map +1 -1
- package/dist/primitives/avatar.js +22 -38
- package/dist/primitives/avatar.js.map +1 -1
- package/dist/primitives/badge.d.ts +1 -1
- package/dist/primitives/badge.d.ts.map +1 -1
- package/dist/primitives/badge.js +23 -27
- package/dist/primitives/badge.js.map +1 -1
- package/dist/primitives/button.js +41 -46
- package/dist/primitives/button.js.map +1 -1
- package/dist/primitives/calendar.d.ts +1 -1
- package/dist/primitives/calendar.d.ts.map +1 -1
- package/dist/primitives/calendar.js +37 -42
- package/dist/primitives/calendar.js.map +1 -1
- package/dist/primitives/card.js +37 -58
- package/dist/primitives/card.js.map +1 -1
- package/dist/primitives/checkbox.js +17 -25
- package/dist/primitives/checkbox.js.map +1 -1
- package/dist/primitives/command.d.ts +2 -2
- package/dist/primitives/command.d.ts.map +1 -1
- package/dist/primitives/command.js +70 -71
- package/dist/primitives/command.js.map +1 -1
- package/dist/primitives/dialog.d.ts +2 -2
- package/dist/primitives/dialog.js +47 -70
- package/dist/primitives/dialog.js.map +1 -1
- package/dist/primitives/dropdown-menu.d.ts +1 -1
- package/dist/primitives/dropdown-menu.js +70 -140
- package/dist/primitives/dropdown-menu.js.map +1 -1
- package/dist/primitives/input.js +15 -22
- package/dist/primitives/input.js.map +1 -1
- package/dist/primitives/label.js +14 -18
- package/dist/primitives/label.js.map +1 -1
- package/dist/primitives/popover.js +17 -25
- package/dist/primitives/popover.js.map +1 -1
- package/dist/primitives/radio-group.js +25 -30
- package/dist/primitives/radio-group.js.map +1 -1
- package/dist/primitives/scroll-area.js +27 -35
- package/dist/primitives/scroll-area.js.map +1 -1
- package/dist/primitives/select.js +65 -116
- package/dist/primitives/select.js.map +1 -1
- package/dist/primitives/separator.js +15 -22
- package/dist/primitives/separator.js.map +1 -1
- package/dist/primitives/skeleton.d.ts +1 -1
- package/dist/primitives/skeleton.d.ts.map +1 -1
- package/dist/primitives/skeleton.js +10 -12
- package/dist/primitives/skeleton.js.map +1 -1
- package/dist/primitives/sonner.d.ts +1 -1
- package/dist/primitives/sonner.d.ts.map +1 -1
- package/dist/primitives/sonner.js +17 -21
- package/dist/primitives/sonner.js.map +1 -1
- package/dist/primitives/switch.js +14 -25
- package/dist/primitives/switch.js.map +1 -1
- package/dist/primitives/table.js +50 -51
- package/dist/primitives/table.js.map +1 -1
- package/dist/primitives/tabs.js +23 -43
- package/dist/primitives/tabs.js.map +1 -1
- package/dist/primitives/textarea.js +13 -18
- package/dist/primitives/textarea.js.map +1 -1
- package/dist/primitives/textbox.js +15 -22
- package/dist/primitives/textbox.js.map +1 -1
- package/dist/primitives/toast.js +48 -87
- package/dist/primitives/toast.js.map +1 -1
- package/dist/primitives/toggle.js +34 -36
- package/dist/primitives/toggle.js.map +1 -1
- package/dist/primitives/tooltip.js +16 -24
- package/dist/primitives/tooltip.js.map +1 -1
- package/dist/stories/Button.d.ts +1 -1
- package/dist/stories/Button.d.ts.map +1 -1
- package/dist/stories/Button.stories.d.ts +1 -1
- package/dist/stories/Header.d.ts +1 -1
- package/dist/stories/Header.d.ts.map +1 -1
- package/dist/stories/Header.stories.d.ts +1 -1
- package/dist/utils/cn.js +10 -5
- package/dist/utils/cn.js.map +1 -1
- package/package.json +503 -497
- package/dist/cjs/components/Form/Switch.cjs +0 -126
- package/dist/cjs/components/Form/Switch.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/components/Form/Switch.d.ts.map +0 -1
- package/dist/components/Form/Switch.js +0 -126
- package/dist/components/Form/Switch.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,132 +1,116 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
"use client";
|
|
3
|
+
import { createContext, useCallback, useRef } from "react";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
//#region src/components/Form/context.ts
|
|
6
|
+
/**
|
|
7
|
+
* Default form configuration
|
|
8
|
+
*/
|
|
9
|
+
var defaultFormConfig = {
|
|
10
|
+
showInlineErrors: true,
|
|
11
|
+
validateOnBlur: true,
|
|
12
|
+
validateOnChange: false,
|
|
13
|
+
size: "md",
|
|
14
|
+
layout: "vertical",
|
|
15
|
+
disabled: false,
|
|
16
|
+
colon: true
|
|
12
17
|
};
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Form context for sharing form state and configuration
|
|
20
|
+
*/
|
|
21
|
+
var FormConfigContext = createContext(null);
|
|
22
|
+
/**
|
|
23
|
+
* Build a Zod schema from validation rules
|
|
24
|
+
*/
|
|
14
25
|
function buildZodSchemaFromRules(type, rules) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const schema = z.boolean();
|
|
80
|
-
if (rules.required) {
|
|
81
|
-
return schema.refine((val) => val === true, {
|
|
82
|
-
message: typeof rules.required === "string" ? rules.required : "This field is required"
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return schema.optional();
|
|
86
|
-
}
|
|
87
|
-
if (type === "date") {
|
|
88
|
-
const schema = z.coerce.date();
|
|
89
|
-
if (!rules.required) {
|
|
90
|
-
return schema.optional();
|
|
91
|
-
}
|
|
92
|
-
return schema;
|
|
93
|
-
}
|
|
94
|
-
if (type === "array") {
|
|
95
|
-
let schema = z.array(z.unknown());
|
|
96
|
-
if (rules.required) {
|
|
97
|
-
const message = typeof rules.required === "string" ? rules.required : "This field is required";
|
|
98
|
-
schema = schema.min(1, message);
|
|
99
|
-
}
|
|
100
|
-
return schema;
|
|
101
|
-
}
|
|
102
|
-
return z.unknown();
|
|
26
|
+
const getValueAndMessage = (rule, defaultMessage) => {
|
|
27
|
+
if (rule === void 0) return null;
|
|
28
|
+
if (typeof rule === "object" && rule !== null && "value" in rule) return rule;
|
|
29
|
+
return {
|
|
30
|
+
value: rule,
|
|
31
|
+
message: defaultMessage
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
if (type === "string") {
|
|
35
|
+
let schema = z.string();
|
|
36
|
+
const minLengthRule = getValueAndMessage(rules.minLength, `Minimum ${typeof rules.minLength === "number" ? rules.minLength : rules.minLength?.value} characters required`);
|
|
37
|
+
if (minLengthRule) schema = schema.min(minLengthRule.value, minLengthRule.message);
|
|
38
|
+
const maxLengthRule = getValueAndMessage(rules.maxLength, `Maximum ${typeof rules.maxLength === "number" ? rules.maxLength : rules.maxLength?.value} characters allowed`);
|
|
39
|
+
if (maxLengthRule) schema = schema.max(maxLengthRule.value, maxLengthRule.message);
|
|
40
|
+
if (rules.pattern !== void 0) {
|
|
41
|
+
const patternRule = rules.pattern instanceof RegExp ? {
|
|
42
|
+
value: rules.pattern,
|
|
43
|
+
message: "Invalid format"
|
|
44
|
+
} : rules.pattern;
|
|
45
|
+
schema = schema.regex(patternRule.value, patternRule.message);
|
|
46
|
+
}
|
|
47
|
+
if (rules.email) {
|
|
48
|
+
const message = typeof rules.email === "string" ? rules.email : "Invalid email address";
|
|
49
|
+
schema = schema.email(message);
|
|
50
|
+
}
|
|
51
|
+
if (rules.url) {
|
|
52
|
+
const message = typeof rules.url === "string" ? rules.url : "Invalid URL";
|
|
53
|
+
schema = schema.url(message);
|
|
54
|
+
}
|
|
55
|
+
if (rules.required) {
|
|
56
|
+
const message = typeof rules.required === "string" ? rules.required : "This field is required";
|
|
57
|
+
schema = schema.min(1, message);
|
|
58
|
+
return schema;
|
|
59
|
+
}
|
|
60
|
+
return schema.optional();
|
|
61
|
+
}
|
|
62
|
+
if (type === "number") {
|
|
63
|
+
let schema = z.coerce.number();
|
|
64
|
+
const minRule = getValueAndMessage(rules.min, `Minimum value is ${typeof rules.min === "number" ? rules.min : rules.min?.value}`);
|
|
65
|
+
if (minRule) schema = schema.min(minRule.value, minRule.message);
|
|
66
|
+
const maxRule = getValueAndMessage(rules.max, `Maximum value is ${typeof rules.max === "number" ? rules.max : rules.max?.value}`);
|
|
67
|
+
if (maxRule) schema = schema.max(maxRule.value, maxRule.message);
|
|
68
|
+
if (!rules.required) return schema.optional();
|
|
69
|
+
return schema;
|
|
70
|
+
}
|
|
71
|
+
if (type === "boolean") {
|
|
72
|
+
const schema = z.boolean();
|
|
73
|
+
if (rules.required) return schema.refine((val) => val === true, { message: typeof rules.required === "string" ? rules.required : "This field is required" });
|
|
74
|
+
return schema.optional();
|
|
75
|
+
}
|
|
76
|
+
if (type === "date") {
|
|
77
|
+
const schema = z.coerce.date();
|
|
78
|
+
if (!rules.required) return schema.optional();
|
|
79
|
+
return schema;
|
|
80
|
+
}
|
|
81
|
+
if (type === "array") {
|
|
82
|
+
let schema = z.array(z.unknown());
|
|
83
|
+
if (rules.required) {
|
|
84
|
+
const message = typeof rules.required === "string" ? rules.required : "This field is required";
|
|
85
|
+
schema = schema.min(1, message);
|
|
86
|
+
}
|
|
87
|
+
return schema;
|
|
88
|
+
}
|
|
89
|
+
return z.unknown();
|
|
103
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Hook to manage field validations
|
|
93
|
+
*/
|
|
104
94
|
function useFieldValidationRegistry() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
getValidationSchema,
|
|
123
|
-
fieldsRef
|
|
124
|
-
};
|
|
95
|
+
const fieldsRef = useRef(/* @__PURE__ */ new Map());
|
|
96
|
+
return {
|
|
97
|
+
registerFieldValidation: useCallback((field) => {
|
|
98
|
+
fieldsRef.current.set(field.name, field);
|
|
99
|
+
}, []),
|
|
100
|
+
unregisterFieldValidation: useCallback((name) => {
|
|
101
|
+
fieldsRef.current.delete(name);
|
|
102
|
+
}, []),
|
|
103
|
+
getValidationSchema: useCallback(() => {
|
|
104
|
+
const shape = {};
|
|
105
|
+
fieldsRef.current.forEach((field) => {
|
|
106
|
+
shape[field.name] = buildZodSchemaFromRules(field.type, field.rules);
|
|
107
|
+
});
|
|
108
|
+
return z.object(shape);
|
|
109
|
+
}, []),
|
|
110
|
+
fieldsRef
|
|
111
|
+
};
|
|
125
112
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
useFieldValidationRegistry
|
|
131
|
-
};
|
|
132
|
-
//# sourceMappingURL=context.js.map
|
|
113
|
+
//#endregion
|
|
114
|
+
export { FormConfigContext, buildZodSchemaFromRules, defaultFormConfig, useFieldValidationRegistry };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../../../src/components/Form/context.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useCallback, useRef } from \"react\";\r\nimport type { UseFormReturn, FieldValues } from \"react-hook-form\";\r\nimport { z } from \"zod\";\r\n\r\n/**\r\n * Validation rule types that can be applied to form fields\r\n */\r\nexport interface FieldValidationRules {\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Minimum length for strings */\r\n minLength?: number | { value: number; message: string };\r\n /** Maximum length for strings */\r\n maxLength?: number | { value: number; message: string };\r\n /** Minimum value for numbers */\r\n min?: number | { value: number; message: string };\r\n /** Maximum value for numbers */\r\n max?: number | { value: number; message: string };\r\n /** Regex pattern for validation */\r\n pattern?: RegExp | { value: RegExp; message: string };\r\n /** Email validation */\r\n email?: boolean | string;\r\n /** URL validation */\r\n url?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * Form configuration options\r\n */\r\nexport interface FormConfig {\r\n /** Show validation errors inline */\r\n showInlineErrors?: boolean;\r\n /** Validate on blur */\r\n validateOnBlur?: boolean;\r\n /** Validate on change */\r\n validateOnChange?: boolean;\r\n /** Size of form controls */\r\n size?: \"sm\" | \"md\" | \"lg\";\r\n /** Layout direction */\r\n layout?: \"horizontal\" | \"vertical\" | \"inline\";\r\n /** Label width for horizontal layout */\r\n labelWidth?: string | number;\r\n /** Whether form is disabled */\r\n disabled?: boolean;\r\n /** Colon after label */\r\n colon?: boolean;\r\n}\r\n\r\n/**\r\n * Field registration info\r\n */\r\nexport interface FieldRegistration {\r\n name: string;\r\n type: \"string\" | \"number\" | \"boolean\" | \"date\" | \"array\";\r\n rules: FieldValidationRules;\r\n}\r\n\r\n/**\r\n * Form context value\r\n */\r\nexport interface FormContextValue<TFieldValues extends FieldValues = FieldValues>\r\n extends FormConfig {\r\n form: UseFormReturn<TFieldValues>;\r\n /** Register a field's validation rules */\r\n registerFieldValidation: (field: FieldRegistration) => void;\r\n /** Unregister a field's validation rules */\r\n unregisterFieldValidation: (name: string) => void;\r\n /** Get current validation schema */\r\n getValidationSchema: () => z.ZodObject<Record<string, z.ZodTypeAny>>;\r\n /** Trigger validation for a specific field */\r\n triggerValidation: (name: string) => Promise<boolean>;\r\n}\r\n\r\n/**\r\n * Default form configuration\r\n */\r\nexport const defaultFormConfig: FormConfig = {\r\n showInlineErrors: true,\r\n validateOnBlur: true,\r\n validateOnChange: false,\r\n size: \"md\",\r\n layout: \"vertical\",\r\n disabled: false,\r\n colon: true,\r\n};\r\n\r\n/**\r\n * Form context for sharing form state and configuration\r\n */\r\nexport const FormConfigContext = createContext<FormContextValue | null>(null);\r\n\r\n/**\r\n * Build a Zod schema from validation rules\r\n */\r\nexport function buildZodSchemaFromRules(\r\n type: FieldRegistration[\"type\"],\r\n rules: FieldValidationRules\r\n): z.ZodTypeAny {\r\n // Helper to extract value and message\r\n const getValueAndMessage = <T>(\r\n rule: T | { value: T; message: string } | undefined,\r\n defaultMessage: string\r\n ): { value: T; message: string } | null => {\r\n if (rule === undefined) return null;\r\n if (typeof rule === \"object\" && rule !== null && \"value\" in rule) {\r\n return rule as { value: T; message: string };\r\n }\r\n return { value: rule as T, message: defaultMessage };\r\n };\r\n\r\n // Build string schema\r\n if (type === \"string\") {\r\n let schema = z.string();\r\n\r\n const minLengthRule = getValueAndMessage(\r\n rules.minLength,\r\n `Minimum ${typeof rules.minLength === \"number\" ? rules.minLength : (rules.minLength as { value: number })?.value} characters required`\r\n );\r\n if (minLengthRule) {\r\n schema = schema.min(minLengthRule.value as number, minLengthRule.message);\r\n }\r\n\r\n const maxLengthRule = getValueAndMessage(\r\n rules.maxLength,\r\n `Maximum ${typeof rules.maxLength === \"number\" ? rules.maxLength : (rules.maxLength as { value: number })?.value} characters allowed`\r\n );\r\n if (maxLengthRule) {\r\n schema = schema.max(maxLengthRule.value as number, maxLengthRule.message);\r\n }\r\n\r\n if (rules.pattern !== undefined) {\r\n const patternRule = rules.pattern instanceof RegExp\r\n ? { value: rules.pattern, message: \"Invalid format\" }\r\n : rules.pattern;\r\n schema = schema.regex(patternRule.value, patternRule.message);\r\n }\r\n\r\n if (rules.email) {\r\n const message = typeof rules.email === \"string\" ? rules.email : \"Invalid email address\";\r\n schema = schema.email(message);\r\n }\r\n\r\n if (rules.url) {\r\n const message = typeof rules.url === \"string\" ? rules.url : \"Invalid URL\";\r\n schema = schema.url(message);\r\n }\r\n\r\n // Handle required - for strings, require non-empty\r\n if (rules.required) {\r\n const message = typeof rules.required === \"string\" ? rules.required : \"This field is required\";\r\n schema = schema.min(1, message);\r\n return schema;\r\n }\r\n\r\n return schema.optional();\r\n }\r\n\r\n // Build number schema\r\n if (type === \"number\") {\r\n let schema = z.coerce.number();\r\n\r\n const minRule = getValueAndMessage(\r\n rules.min,\r\n `Minimum value is ${typeof rules.min === \"number\" ? rules.min : (rules.min as { value: number })?.value}`\r\n );\r\n if (minRule) {\r\n schema = schema.min(minRule.value as number, minRule.message);\r\n }\r\n\r\n const maxRule = getValueAndMessage(\r\n rules.max,\r\n `Maximum value is ${typeof rules.max === \"number\" ? rules.max : (rules.max as { value: number })?.value}`\r\n );\r\n if (maxRule) {\r\n schema = schema.max(maxRule.value as number, maxRule.message);\r\n }\r\n\r\n if (!rules.required) {\r\n return schema.optional();\r\n }\r\n return schema;\r\n }\r\n\r\n // Build boolean schema\r\n if (type === \"boolean\") {\r\n const schema = z.boolean();\r\n if (rules.required) {\r\n // For required boolean, must be true (like accepting terms)\r\n return schema.refine((val) => val === true, {\r\n message: typeof rules.required === \"string\" ? rules.required : \"This field is required\",\r\n });\r\n }\r\n return schema.optional();\r\n }\r\n\r\n // Build date schema\r\n if (type === \"date\") {\r\n const schema = z.coerce.date();\r\n if (!rules.required) {\r\n return schema.optional();\r\n }\r\n return schema;\r\n }\r\n\r\n // Build array schema\r\n if (type === \"array\") {\r\n let schema = z.array(z.unknown());\r\n if (rules.required) {\r\n const message = typeof rules.required === \"string\" ? rules.required : \"This field is required\";\r\n schema = schema.min(1, message);\r\n }\r\n return schema;\r\n }\r\n\r\n // Default fallback\r\n return z.unknown();\r\n}\r\n\r\n/**\r\n * Hook to manage field validations\r\n */\r\nexport function useFieldValidationRegistry() {\r\n const fieldsRef = useRef<Map<string, FieldRegistration>>(new Map());\r\n\r\n const registerFieldValidation = useCallback((field: FieldRegistration) => {\r\n fieldsRef.current.set(field.name, field);\r\n }, []);\r\n\r\n const unregisterFieldValidation = useCallback((name: string) => {\r\n fieldsRef.current.delete(name);\r\n }, []);\r\n\r\n const getValidationSchema = useCallback(() => {\r\n const shape: Record<string, z.ZodTypeAny> = {};\r\n \r\n fieldsRef.current.forEach((field) => {\r\n shape[field.name] = buildZodSchemaFromRules(field.type, field.rules);\r\n });\r\n\r\n return z.object(shape);\r\n }, []);\r\n\r\n return {\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n fieldsRef,\r\n };\r\n}\r\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../../src/components/Form/context.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useCallback, useRef } from \"react\";\r\nimport type { UseFormReturn, FieldValues } from \"react-hook-form\";\r\nimport { z } from \"zod\";\r\n\r\n/**\r\n * Validation rule types that can be applied to form fields\r\n */\r\nexport interface FieldValidationRules {\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Minimum length for strings */\r\n minLength?: number | { value: number; message: string };\r\n /** Maximum length for strings */\r\n maxLength?: number | { value: number; message: string };\r\n /** Minimum value for numbers */\r\n min?: number | { value: number; message: string };\r\n /** Maximum value for numbers */\r\n max?: number | { value: number; message: string };\r\n /** Regex pattern for validation */\r\n pattern?: RegExp | { value: RegExp; message: string };\r\n /** Email validation */\r\n email?: boolean | string;\r\n /** URL validation */\r\n url?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * Form configuration options\r\n */\r\nexport interface FormConfig {\r\n /** Show validation errors inline */\r\n showInlineErrors?: boolean;\r\n /** Validate on blur */\r\n validateOnBlur?: boolean;\r\n /** Validate on change */\r\n validateOnChange?: boolean;\r\n /** Size of form controls */\r\n size?: \"sm\" | \"md\" | \"lg\";\r\n /** Layout direction */\r\n layout?: \"horizontal\" | \"vertical\" | \"inline\";\r\n /** Label width for horizontal layout */\r\n labelWidth?: string | number;\r\n /** Whether form is disabled */\r\n disabled?: boolean;\r\n /** Colon after label */\r\n colon?: boolean;\r\n}\r\n\r\n/**\r\n * Field registration info\r\n */\r\nexport interface FieldRegistration {\r\n name: string;\r\n type: \"string\" | \"number\" | \"boolean\" | \"date\" | \"array\";\r\n rules: FieldValidationRules;\r\n}\r\n\r\n/**\r\n * Form context value\r\n */\r\nexport interface FormContextValue<TFieldValues extends FieldValues = FieldValues>\r\n extends FormConfig {\r\n form: UseFormReturn<TFieldValues>;\r\n /** Register a field's validation rules */\r\n registerFieldValidation: (field: FieldRegistration) => void;\r\n /** Unregister a field's validation rules */\r\n unregisterFieldValidation: (name: string) => void;\r\n /** Get current validation schema */\r\n getValidationSchema: () => z.ZodObject<Record<string, z.ZodTypeAny>>;\r\n /** Trigger validation for a specific field */\r\n triggerValidation: (name: string) => Promise<boolean>;\r\n}\r\n\r\n/**\r\n * Default form configuration\r\n */\r\nexport const defaultFormConfig: FormConfig = {\r\n showInlineErrors: true,\r\n validateOnBlur: true,\r\n validateOnChange: false,\r\n size: \"md\",\r\n layout: \"vertical\",\r\n disabled: false,\r\n colon: true,\r\n};\r\n\r\n/**\r\n * Form context for sharing form state and configuration\r\n */\r\nexport const FormConfigContext = createContext<FormContextValue | null>(null);\r\n\r\n/**\r\n * Build a Zod schema from validation rules\r\n */\r\nexport function buildZodSchemaFromRules(\r\n type: FieldRegistration[\"type\"],\r\n rules: FieldValidationRules\r\n): z.ZodTypeAny {\r\n // Helper to extract value and message\r\n const getValueAndMessage = <T>(\r\n rule: T | { value: T; message: string } | undefined,\r\n defaultMessage: string\r\n ): { value: T; message: string } | null => {\r\n if (rule === undefined) return null;\r\n if (typeof rule === \"object\" && rule !== null && \"value\" in rule) {\r\n return rule as { value: T; message: string };\r\n }\r\n return { value: rule as T, message: defaultMessage };\r\n };\r\n\r\n // Build string schema\r\n if (type === \"string\") {\r\n let schema = z.string();\r\n\r\n const minLengthRule = getValueAndMessage(\r\n rules.minLength,\r\n `Minimum ${typeof rules.minLength === \"number\" ? rules.minLength : (rules.minLength as { value: number })?.value} characters required`\r\n );\r\n if (minLengthRule) {\r\n schema = schema.min(minLengthRule.value as number, minLengthRule.message);\r\n }\r\n\r\n const maxLengthRule = getValueAndMessage(\r\n rules.maxLength,\r\n `Maximum ${typeof rules.maxLength === \"number\" ? rules.maxLength : (rules.maxLength as { value: number })?.value} characters allowed`\r\n );\r\n if (maxLengthRule) {\r\n schema = schema.max(maxLengthRule.value as number, maxLengthRule.message);\r\n }\r\n\r\n if (rules.pattern !== undefined) {\r\n const patternRule = rules.pattern instanceof RegExp\r\n ? { value: rules.pattern, message: \"Invalid format\" }\r\n : rules.pattern;\r\n schema = schema.regex(patternRule.value, patternRule.message);\r\n }\r\n\r\n if (rules.email) {\r\n const message = typeof rules.email === \"string\" ? rules.email : \"Invalid email address\";\r\n schema = schema.email(message);\r\n }\r\n\r\n if (rules.url) {\r\n const message = typeof rules.url === \"string\" ? rules.url : \"Invalid URL\";\r\n schema = schema.url(message);\r\n }\r\n\r\n // Handle required - for strings, require non-empty\r\n if (rules.required) {\r\n const message = typeof rules.required === \"string\" ? rules.required : \"This field is required\";\r\n schema = schema.min(1, message);\r\n return schema;\r\n }\r\n\r\n return schema.optional();\r\n }\r\n\r\n // Build number schema\r\n if (type === \"number\") {\r\n let schema = z.coerce.number();\r\n\r\n const minRule = getValueAndMessage(\r\n rules.min,\r\n `Minimum value is ${typeof rules.min === \"number\" ? rules.min : (rules.min as { value: number })?.value}`\r\n );\r\n if (minRule) {\r\n schema = schema.min(minRule.value as number, minRule.message);\r\n }\r\n\r\n const maxRule = getValueAndMessage(\r\n rules.max,\r\n `Maximum value is ${typeof rules.max === \"number\" ? rules.max : (rules.max as { value: number })?.value}`\r\n );\r\n if (maxRule) {\r\n schema = schema.max(maxRule.value as number, maxRule.message);\r\n }\r\n\r\n if (!rules.required) {\r\n return schema.optional();\r\n }\r\n return schema;\r\n }\r\n\r\n // Build boolean schema\r\n if (type === \"boolean\") {\r\n const schema = z.boolean();\r\n if (rules.required) {\r\n // For required boolean, must be true (like accepting terms)\r\n return schema.refine((val) => val === true, {\r\n message: typeof rules.required === \"string\" ? rules.required : \"This field is required\",\r\n });\r\n }\r\n return schema.optional();\r\n }\r\n\r\n // Build date schema\r\n if (type === \"date\") {\r\n const schema = z.coerce.date();\r\n if (!rules.required) {\r\n return schema.optional();\r\n }\r\n return schema;\r\n }\r\n\r\n // Build array schema\r\n if (type === \"array\") {\r\n let schema = z.array(z.unknown());\r\n if (rules.required) {\r\n const message = typeof rules.required === \"string\" ? rules.required : \"This field is required\";\r\n schema = schema.min(1, message);\r\n }\r\n return schema;\r\n }\r\n\r\n // Default fallback\r\n return z.unknown();\r\n}\r\n\r\n/**\r\n * Hook to manage field validations\r\n */\r\nexport function useFieldValidationRegistry() {\r\n const fieldsRef = useRef<Map<string, FieldRegistration>>(new Map());\r\n\r\n const registerFieldValidation = useCallback((field: FieldRegistration) => {\r\n fieldsRef.current.set(field.name, field);\r\n }, []);\r\n\r\n const unregisterFieldValidation = useCallback((name: string) => {\r\n fieldsRef.current.delete(name);\r\n }, []);\r\n\r\n const getValidationSchema = useCallback(() => {\r\n const shape: Record<string, z.ZodTypeAny> = {};\r\n \r\n fieldsRef.current.forEach((field) => {\r\n shape[field.name] = buildZodSchemaFromRules(field.type, field.rules);\r\n });\r\n\r\n return z.object(shape);\r\n }, []);\r\n\r\n return {\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n fieldsRef,\r\n };\r\n}\r\n"],"mappings":";;;;;;;;AAgFA,IAAa,oBAAgC;CAC3C,kBAAkB;CAClB,gBAAgB;CAChB,kBAAkB;CAClB,MAAM;CACN,QAAQ;CACR,UAAU;CACV,OAAO;AACT;;;;AAKA,IAAa,oBAAoB,cAAuC,IAAI;;;;AAK5E,SAAgB,wBACd,MACA,OACc;CAEd,MAAM,sBACJ,MACA,mBACyC;EACzC,IAAI,SAAS,KAAA,GAAW,OAAO;EAC/B,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,WAAW,MAC1D,OAAO;EAET,OAAO;GAAE,OAAO;GAAW,SAAS;EAAe;CACrD;CAGA,IAAI,SAAS,UAAU;EACrB,IAAI,SAAS,EAAE,OAAO;EAEtB,MAAM,gBAAgB,mBACpB,MAAM,WACN,WAAW,OAAO,MAAM,cAAc,WAAW,MAAM,YAAa,MAAM,WAAiC,MAAM,qBACnH;EACA,IAAI,eACF,SAAS,OAAO,IAAI,cAAc,OAAiB,cAAc,OAAO;EAG1E,MAAM,gBAAgB,mBACpB,MAAM,WACN,WAAW,OAAO,MAAM,cAAc,WAAW,MAAM,YAAa,MAAM,WAAiC,MAAM,oBACnH;EACA,IAAI,eACF,SAAS,OAAO,IAAI,cAAc,OAAiB,cAAc,OAAO;EAG1E,IAAI,MAAM,YAAY,KAAA,GAAW;GAC/B,MAAM,cAAc,MAAM,mBAAmB,SACzC;IAAE,OAAO,MAAM;IAAS,SAAS;GAAiB,IAClD,MAAM;GACV,SAAS,OAAO,MAAM,YAAY,OAAO,YAAY,OAAO;EAC9D;EAEA,IAAI,MAAM,OAAO;GACf,MAAM,UAAU,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ;GAChE,SAAS,OAAO,MAAM,OAAO;EAC/B;EAEA,IAAI,MAAM,KAAK;GACb,MAAM,UAAU,OAAO,MAAM,QAAQ,WAAW,MAAM,MAAM;GAC5D,SAAS,OAAO,IAAI,OAAO;EAC7B;EAGA,IAAI,MAAM,UAAU;GAClB,MAAM,UAAU,OAAO,MAAM,aAAa,WAAW,MAAM,WAAW;GACtE,SAAS,OAAO,IAAI,GAAG,OAAO;GAC9B,OAAO;EACT;EAEA,OAAO,OAAO,SAAS;CACzB;CAGA,IAAI,SAAS,UAAU;EACrB,IAAI,SAAS,EAAE,OAAO,OAAO;EAE7B,MAAM,UAAU,mBACd,MAAM,KACN,oBAAoB,OAAO,MAAM,QAAQ,WAAW,MAAM,MAAO,MAAM,KAA2B,OACpG;EACA,IAAI,SACF,SAAS,OAAO,IAAI,QAAQ,OAAiB,QAAQ,OAAO;EAG9D,MAAM,UAAU,mBACd,MAAM,KACN,oBAAoB,OAAO,MAAM,QAAQ,WAAW,MAAM,MAAO,MAAM,KAA2B,OACpG;EACA,IAAI,SACF,SAAS,OAAO,IAAI,QAAQ,OAAiB,QAAQ,OAAO;EAG9D,IAAI,CAAC,MAAM,UACT,OAAO,OAAO,SAAS;EAEzB,OAAO;CACT;CAGA,IAAI,SAAS,WAAW;EACtB,MAAM,SAAS,EAAE,QAAQ;EACzB,IAAI,MAAM,UAER,OAAO,OAAO,QAAQ,QAAQ,QAAQ,MAAM,EAC1C,SAAS,OAAO,MAAM,aAAa,WAAW,MAAM,WAAW,yBACjE,CAAC;EAEH,OAAO,OAAO,SAAS;CACzB;CAGA,IAAI,SAAS,QAAQ;EACnB,MAAM,SAAS,EAAE,OAAO,KAAK;EAC7B,IAAI,CAAC,MAAM,UACT,OAAO,OAAO,SAAS;EAEzB,OAAO;CACT;CAGA,IAAI,SAAS,SAAS;EACpB,IAAI,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC;EAChC,IAAI,MAAM,UAAU;GAClB,MAAM,UAAU,OAAO,MAAM,aAAa,WAAW,MAAM,WAAW;GACtE,SAAS,OAAO,IAAI,GAAG,OAAO;EAChC;EACA,OAAO;CACT;CAGA,OAAO,EAAE,QAAQ;AACnB;;;;AAKA,SAAgB,6BAA6B;CAC3C,MAAM,YAAY,uBAAuC,IAAI,IAAI,CAAC;CAoBlE,OAAO;EACL,yBAnB8B,aAAa,UAA6B;GACxE,UAAU,QAAQ,IAAI,MAAM,MAAM,KAAK;EACzC,GAAG,CAAC,CAiBF;EACA,2BAhBgC,aAAa,SAAiB;GAC9D,UAAU,QAAQ,OAAO,IAAI;EAC/B,GAAG,CAAC,CAcF;EACA,qBAb0B,kBAAkB;GAC5C,MAAM,QAAsC,CAAC;GAE7C,UAAU,QAAQ,SAAS,UAAU;IACnC,MAAM,MAAM,QAAQ,wBAAwB,MAAM,MAAM,MAAM,KAAK;GACrE,CAAC;GAED,OAAO,EAAE,OAAO,KAAK;EACvB,GAAG,CAAC,CAKF;EACA;CACF;AACF"}
|
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import { useFormContext, useController } from "react-hook-form";
|
|
2
|
+
"use client";
|
|
4
3
|
import { FormConfigContext } from "./context.js";
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
import { useController, useFormContext } from "react-hook-form";
|
|
6
|
+
//#region src/components/Form/hooks.ts
|
|
7
|
+
/**
|
|
8
|
+
* Hook to access form configuration context
|
|
9
|
+
*/
|
|
5
10
|
function useFormConfig() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return context;
|
|
11
|
+
const context = useContext(FormConfigContext);
|
|
12
|
+
if (!context) throw new Error("useFormConfig must be used within a Form component");
|
|
13
|
+
return context;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Hook to access react-hook-form context directly
|
|
17
|
+
*/
|
|
18
|
+
function useForm$1() {
|
|
19
|
+
return useFormContext();
|
|
14
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Hook to create a controlled field with form context awareness
|
|
23
|
+
*/
|
|
15
24
|
function useFormField(props) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
+
const { form, ...config } = useFormConfig();
|
|
26
|
+
return {
|
|
27
|
+
...useController({
|
|
28
|
+
...props,
|
|
29
|
+
control: form.control
|
|
30
|
+
}),
|
|
31
|
+
config
|
|
32
|
+
};
|
|
25
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Hook to get field error
|
|
36
|
+
*/
|
|
26
37
|
function useFieldError(name) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return error?.message;
|
|
38
|
+
const { form } = useFormConfig();
|
|
39
|
+
return form.formState.errors[name]?.message;
|
|
30
40
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
useFormField
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=hooks.js.map
|
|
41
|
+
//#endregion
|
|
42
|
+
export { useFieldError, useForm$1 as useForm, useFormConfig, useFormField };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../src/components/Form/hooks.ts"],"sourcesContent":["'use client';\n\nimport { useContext } from \"react\";\r\nimport {\r\n useFormContext as useRHFFormContext,\r\n useController,\r\n type FieldValues,\r\n type FieldPath,\r\n type UseControllerProps,\r\n type UseControllerReturn,\r\n} from \"react-hook-form\";\r\nimport { FormConfigContext, type FormContextValue, type FormConfig } from \"./context\";\r\n\r\n/**\r\n * Hook to access form configuration context\r\n */\r\nexport function useFormConfig<TFieldValues extends FieldValues = FieldValues>(): FormContextValue<TFieldValues> {\r\n const context = useContext(FormConfigContext) as FormContextValue<TFieldValues> | null;\r\n if (!context) {\r\n throw new Error(\"useFormConfig must be used within a Form component\");\r\n }\r\n return context;\r\n}\r\n\r\n/**\r\n * Hook to access react-hook-form context directly\r\n */\r\nexport function useForm<TFieldValues extends FieldValues = FieldValues>() {\r\n return useRHFFormContext<TFieldValues>();\r\n}\r\n\r\n/**\r\n * Hook to create a controlled field with form context awareness\r\n */\r\nexport function useFormField<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: UseControllerProps<TFieldValues, TName>\r\n): UseControllerReturn<TFieldValues, TName> & { config: FormConfig } {\r\n const { form, ...config } = useFormConfig<TFieldValues>();\r\n const controller = useController<TFieldValues, TName>({\r\n ...props,\r\n control: form.control,\r\n });\r\n\r\n return {\r\n ...controller,\r\n config,\r\n };\r\n}\r\n\r\n/**\r\n * Hook to get field error\r\n */\r\nexport function useFieldError<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(name: TName): string | undefined {\r\n const { form } = useFormConfig<TFieldValues>();\r\n const error = form.formState.errors[name];\r\n return error?.message as string | undefined;\r\n}\r\n"],"
|
|
1
|
+
{"version":3,"file":"hooks.js","names":[],"sources":["../../../src/components/Form/hooks.ts"],"sourcesContent":["'use client';\n\nimport { useContext } from \"react\";\r\nimport {\r\n useFormContext as useRHFFormContext,\r\n useController,\r\n type FieldValues,\r\n type FieldPath,\r\n type UseControllerProps,\r\n type UseControllerReturn,\r\n} from \"react-hook-form\";\r\nimport { FormConfigContext, type FormContextValue, type FormConfig } from \"./context\";\r\n\r\n/**\r\n * Hook to access form configuration context\r\n */\r\nexport function useFormConfig<TFieldValues extends FieldValues = FieldValues>(): FormContextValue<TFieldValues> {\r\n const context = useContext(FormConfigContext) as FormContextValue<TFieldValues> | null;\r\n if (!context) {\r\n throw new Error(\"useFormConfig must be used within a Form component\");\r\n }\r\n return context;\r\n}\r\n\r\n/**\r\n * Hook to access react-hook-form context directly\r\n */\r\nexport function useForm<TFieldValues extends FieldValues = FieldValues>() {\r\n return useRHFFormContext<TFieldValues>();\r\n}\r\n\r\n/**\r\n * Hook to create a controlled field with form context awareness\r\n */\r\nexport function useFormField<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: UseControllerProps<TFieldValues, TName>\r\n): UseControllerReturn<TFieldValues, TName> & { config: FormConfig } {\r\n const { form, ...config } = useFormConfig<TFieldValues>();\r\n const controller = useController<TFieldValues, TName>({\r\n ...props,\r\n control: form.control,\r\n });\r\n\r\n return {\r\n ...controller,\r\n config,\r\n };\r\n}\r\n\r\n/**\r\n * Hook to get field error\r\n */\r\nexport function useFieldError<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(name: TName): string | undefined {\r\n const { form } = useFormConfig<TFieldValues>();\r\n const error = form.formState.errors[name];\r\n return error?.message as string | undefined;\r\n}\r\n"],"mappings":";;;;;;;;;AAgBA,SAAgB,gBAAgG;CAC9G,MAAM,UAAU,WAAW,iBAAiB;CAC5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,oDAAoD;CAEtE,OAAO;AACT;;;;AAKA,SAAgB,YAA0D;CACxE,OAAO,eAAgC;AACzC;;;;AAKA,SAAgB,aAId,OACmE;CACnE,MAAM,EAAE,MAAM,GAAG,WAAW,cAA4B;CAMxD,OAAO;EACL,GANiB,cAAmC;GACpD,GAAG;GACH,SAAS,KAAK;EAChB,CAGK;EACH;CACF;AACF;;;;AAKA,SAAgB,cAGd,MAAiC;CACjC,MAAM,EAAE,SAAS,cAA4B;CAE7C,OADc,KAAK,UAAU,OAAO,KAC7B,EAAO;AAChB"}
|
|
@@ -4,14 +4,14 @@ export { TextBox } from './TextBox';
|
|
|
4
4
|
export type { TextBoxProps } from './TextBox';
|
|
5
5
|
export { TextArea } from './TextArea';
|
|
6
6
|
export type { TextAreaProps } from './TextArea';
|
|
7
|
-
export { Select } from './Select';
|
|
8
|
-
export type { SelectProps, SelectOption } from './Select';
|
|
7
|
+
export { Select, Select as FormSelect } from './Select';
|
|
8
|
+
export type { SelectProps, SelectProps as FormSelectProps, SelectOption } from './Select';
|
|
9
9
|
export { Checkbox, Checkbox as FormCheckbox } from './Checkbox';
|
|
10
10
|
export type { CheckboxProps } from './Checkbox';
|
|
11
11
|
export { RadioGroup, RadioItem } from './Radio';
|
|
12
12
|
export type { RadioGroupProps, RadioItemProps, RadioOption } from './Radio';
|
|
13
|
-
export {
|
|
14
|
-
export type {
|
|
13
|
+
export { FormSwitch } from './FormSwitch';
|
|
14
|
+
export type { FormSwitchProps } from './FormSwitch';
|
|
15
15
|
export { FormConfigContext, defaultFormConfig, buildZodSchemaFromRules, useFieldValidationRegistry, } from './context';
|
|
16
16
|
export type { FormConfig, FormContextValue, FieldValidationRules, FieldRegistration, } from './context';
|
|
17
17
|
export { useFormConfig, useForm, useFormField, useFieldError } from './hooks';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Form/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Form/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,UAAU,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,WAAW,IAAI,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE1F,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { FormConfigContext, buildZodSchemaFromRules, defaultFormConfig, useFieldValidationRegistry } from "./context.js";
|
|
3
|
+
import { Form } from "./Form.js";
|
|
4
|
+
import { TextBox } from "./TextBox.js";
|
|
5
|
+
import { TextArea } from "./TextArea.js";
|
|
6
|
+
import { Select } from "./Select.js";
|
|
7
|
+
import { Checkbox } from "./Checkbox.js";
|
|
8
|
+
import { RadioGroup, RadioItem } from "./Radio.js";
|
|
9
|
+
import { FormSwitch } from "./FormSwitch.js";
|
|
10
|
+
import { useFieldError, useForm, useFormConfig, useFormField } from "./hooks.js";
|
|
11
|
+
export { Checkbox, Form, Checkbox as FormCheckbox, FormConfigContext, Select as FormSelect, FormSwitch, RadioGroup, RadioItem, Select, TextArea, TextBox, buildZodSchemaFromRules, defaultFormConfig, useFieldError, useFieldValidationRegistry, useForm, useFormConfig, useFormField };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cva } from "class-variance-authority";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
//#region src/components/Form/variants.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shared label variant for all form field components.
|
|
6
|
+
* Shows a required asterisk when required=true.
|
|
7
|
+
*/
|
|
8
|
+
var labelVariants = cva("block text-sm font-medium mb-1.5", {
|
|
9
|
+
variants: { required: {
|
|
10
|
+
true: "after:content-['*'] after:ml-0.5 after:text-destructive",
|
|
11
|
+
false: ""
|
|
12
|
+
} },
|
|
13
|
+
defaultVariants: { required: false }
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=variants.js.map
|
|
15
|
+
//#endregion
|
|
16
|
+
export { labelVariants };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=variants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.js","sources":["../../../src/components/Form/variants.ts"],"sourcesContent":["import { cva } from \"class-variance-authority\";\r\n\r\n/**\r\n * Shared label variant for all form field components.\r\n * Shows a required asterisk when required=true.\r\n */\r\nexport const labelVariants = cva(\"block text-sm font-medium mb-1.5\", {\r\n variants: {\r\n required: {\r\n true: \"after:content-['*'] after:ml-0.5 after:text-destructive\",\r\n false: \"\",\r\n },\r\n },\r\n defaultVariants: {\r\n required: false,\r\n },\r\n});\r\n"],"
|
|
1
|
+
{"version":3,"file":"variants.js","names":[],"sources":["../../../src/components/Form/variants.ts"],"sourcesContent":["import { cva } from \"class-variance-authority\";\r\n\r\n/**\r\n * Shared label variant for all form field components.\r\n * Shows a required asterisk when required=true.\r\n */\r\nexport const labelVariants = cva(\"block text-sm font-medium mb-1.5\", {\r\n variants: {\r\n required: {\r\n true: \"after:content-['*'] after:ml-0.5 after:text-destructive\",\r\n false: \"\",\r\n },\r\n },\r\n defaultVariants: {\r\n required: false,\r\n },\r\n});\r\n"],"mappings":";;;;;;;AAMA,IAAa,gBAAgB,IAAI,oCAAoC;CACnE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef } from "react";
|
|
4
2
|
import { Input as Input$1 } from "../../primitives/input.js";
|
|
5
|
-
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/Input/Input.tsx
|
|
6
|
+
var Input = forwardRef((props, ref) => /* @__PURE__ */ jsx(Input$1, {
|
|
7
|
+
ref,
|
|
8
|
+
...props
|
|
9
|
+
}));
|
|
6
10
|
Input.displayName = "Input";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=Input.js.map
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Input };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=Input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import { forwardRef } from \"react\"\nimport type { ComponentPropsWithoutRef, ElementRef } from \"react\"\nimport { Input as InputPrimitive } from \"../../primitives/input\"\n\nexport type InputProps = ComponentPropsWithoutRef<typeof InputPrimitive>\n\nexport const Input = forwardRef<\n ElementRef<typeof InputPrimitive>,\n InputProps\n>((props, ref) => <InputPrimitive ref={ref} {...props} />)\nInput.displayName = \"Input\"\n"],"
|
|
1
|
+
{"version":3,"file":"Input.js","names":[],"sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import { forwardRef } from \"react\"\nimport type { ComponentPropsWithoutRef, ElementRef } from \"react\"\nimport { Input as InputPrimitive } from \"../../primitives/input\"\n\nexport type InputProps = ComponentPropsWithoutRef<typeof InputPrimitive>\n\nexport const Input = forwardRef<\n ElementRef<typeof InputPrimitive>,\n InputProps\n>((props, ref) => <InputPrimitive ref={ref} {...props} />)\nInput.displayName = \"Input\"\n"],"mappings":";;;;;AAMA,IAAa,QAAQ,YAGlB,OAAO,QAAQ,oBAAC,SAAD;CAAqB;CAAK,GAAI;AAAQ,CAAA,CAAC;AACzD,MAAM,cAAc"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef } from "react";
|
|
4
2
|
import { Label as Label$1 } from "../../primitives/label.js";
|
|
5
|
-
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/Label/Label.tsx
|
|
6
|
+
var Label = forwardRef((props, ref) => /* @__PURE__ */ jsx(Label$1, {
|
|
7
|
+
ref,
|
|
8
|
+
...props
|
|
9
|
+
}));
|
|
6
10
|
Label.displayName = "Label";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=Label.js.map
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Label };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=Label.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","sources":["../../../src/components/Label/Label.tsx"],"sourcesContent":["import { forwardRef } from \"react\"\nimport type { ComponentPropsWithoutRef, ElementRef } from \"react\"\nimport { Label as LabelPrimitive } from \"../../primitives/label\"\n\nexport type LabelProps = ComponentPropsWithoutRef<typeof LabelPrimitive>\n\nexport const Label = forwardRef<\n ElementRef<typeof LabelPrimitive>,\n LabelProps\n>((props, ref) => <LabelPrimitive ref={ref} {...props} />)\nLabel.displayName = \"Label\"\n"],"
|
|
1
|
+
{"version":3,"file":"Label.js","names":[],"sources":["../../../src/components/Label/Label.tsx"],"sourcesContent":["import { forwardRef } from \"react\"\nimport type { ComponentPropsWithoutRef, ElementRef } from \"react\"\nimport { Label as LabelPrimitive } from \"../../primitives/label\"\n\nexport type LabelProps = ComponentPropsWithoutRef<typeof LabelPrimitive>\n\nexport const Label = forwardRef<\n ElementRef<typeof LabelPrimitive>,\n LabelProps\n>((props, ref) => <LabelPrimitive ref={ref} {...props} />)\nLabel.displayName = \"Label\"\n"],"mappings":";;;;;AAMA,IAAa,QAAQ,YAGlB,OAAO,QAAQ,oBAAC,SAAD;CAAqB;CAAK,GAAI;AAAQ,CAAA,CAAC;AACzD,MAAM,cAAc"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ButtonPrimitive } from '../../primitives/button';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
declare const Pagination: {
|
|
4
|
-
({ className, ...props }: React.ComponentProps<"nav">):
|
|
4
|
+
({ className, ...props }: React.ComponentProps<"nav">): React.JSX.Element;
|
|
5
5
|
displayName: string;
|
|
6
6
|
};
|
|
7
7
|
declare const PaginationContent: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & React.RefAttributes<HTMLUListElement>>;
|
|
@@ -10,19 +10,19 @@ type PaginationLinkProps = {
|
|
|
10
10
|
isActive?: boolean;
|
|
11
11
|
} & Pick<React.ComponentProps<typeof ButtonPrimitive>, "size"> & React.ComponentProps<"a">;
|
|
12
12
|
declare const PaginationLink: {
|
|
13
|
-
({ className, isActive, size, ...props }: PaginationLinkProps):
|
|
13
|
+
({ className, isActive, size, ...props }: PaginationLinkProps): React.JSX.Element;
|
|
14
14
|
displayName: string;
|
|
15
15
|
};
|
|
16
16
|
declare const PaginationPrevious: {
|
|
17
|
-
({ className, ...props }: React.ComponentProps<typeof PaginationLink>):
|
|
17
|
+
({ className, ...props }: React.ComponentProps<typeof PaginationLink>): React.JSX.Element;
|
|
18
18
|
displayName: string;
|
|
19
19
|
};
|
|
20
20
|
declare const PaginationNext: {
|
|
21
|
-
({ className, ...props }: React.ComponentProps<typeof PaginationLink>):
|
|
21
|
+
({ className, ...props }: React.ComponentProps<typeof PaginationLink>): React.JSX.Element;
|
|
22
22
|
displayName: string;
|
|
23
23
|
};
|
|
24
24
|
declare const PaginationEllipsis: {
|
|
25
|
-
({ className, ...props }: React.ComponentProps<"span">):
|
|
25
|
+
({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
|
|
26
26
|
displayName: string;
|
|
27
27
|
};
|
|
28
28
|
export { Pagination, PaginationContent, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, PaginationEllipsis, };
|