@forgedevstack/bear 1.0.4 → 1.0.6

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 (133) hide show
  1. package/dist/components/AppBar/AppBar.cjs +1 -1
  2. package/dist/components/AppBar/AppBar.js +8 -8
  3. package/dist/components/Button/Button.constants.cjs +1 -1
  4. package/dist/components/Button/Button.constants.js +1 -1
  5. package/dist/components/Button/Button.d.ts +5 -3
  6. package/dist/components/Calendar/Calendar.cjs +1 -1
  7. package/dist/components/Calendar/Calendar.const.cjs +1 -1
  8. package/dist/components/Calendar/Calendar.const.d.ts +1 -0
  9. package/dist/components/Calendar/Calendar.const.js +6 -5
  10. package/dist/components/Calendar/Calendar.helpers.cjs +1 -1
  11. package/dist/components/Calendar/Calendar.helpers.js +4 -4
  12. package/dist/components/Calendar/Calendar.js +128 -128
  13. package/dist/components/Cascader/Cascader.cjs +1 -0
  14. package/dist/components/Cascader/Cascader.const.cjs +1 -0
  15. package/dist/components/Cascader/Cascader.const.d.ts +33 -0
  16. package/dist/components/Cascader/Cascader.const.js +21 -0
  17. package/dist/components/Cascader/Cascader.d.ts +17 -0
  18. package/dist/components/Cascader/Cascader.js +227 -0
  19. package/dist/components/Cascader/Cascader.types.d.ts +94 -0
  20. package/dist/components/Cascader/index.d.ts +2 -0
  21. package/dist/components/CommandPalette/CommandPalette.cjs +1 -0
  22. package/dist/components/CommandPalette/CommandPalette.const.cjs +1 -0
  23. package/dist/components/CommandPalette/CommandPalette.const.d.ts +25 -0
  24. package/dist/components/CommandPalette/CommandPalette.const.js +13 -0
  25. package/dist/components/CommandPalette/CommandPalette.d.ts +18 -0
  26. package/dist/components/CommandPalette/CommandPalette.js +190 -0
  27. package/dist/components/CommandPalette/CommandPalette.types.d.ts +90 -0
  28. package/dist/components/CommandPalette/CommandPalette.utils.cjs +1 -0
  29. package/dist/components/CommandPalette/CommandPalette.utils.d.ts +17 -0
  30. package/dist/components/CommandPalette/CommandPalette.utils.js +63 -0
  31. package/dist/components/CommandPalette/index.d.ts +2 -0
  32. package/dist/components/CreditInput/CreditInput.cjs +1 -0
  33. package/dist/components/CreditInput/CreditInput.const.cjs +1 -0
  34. package/dist/components/CreditInput/CreditInput.const.d.ts +37 -0
  35. package/dist/components/CreditInput/CreditInput.const.js +66 -0
  36. package/dist/components/CreditInput/CreditInput.d.ts +15 -0
  37. package/dist/components/CreditInput/CreditInput.js +214 -0
  38. package/dist/components/CreditInput/CreditInput.types.d.ts +93 -0
  39. package/dist/components/CreditInput/CreditInput.utils.cjs +1 -0
  40. package/dist/components/CreditInput/CreditInput.utils.d.ts +48 -0
  41. package/dist/components/CreditInput/CreditInput.utils.js +79 -0
  42. package/dist/components/CreditInput/index.d.ts +2 -0
  43. package/dist/components/DatePicker/DatePicker.cjs +1 -1
  44. package/dist/components/DatePicker/DatePicker.js +108 -84
  45. package/dist/components/DatePicker/DatePicker.types.d.ts +2 -1
  46. package/dist/components/Drawer/Drawer.cjs +1 -1
  47. package/dist/components/Drawer/Drawer.js +75 -44
  48. package/dist/components/Form/Form.cjs +1 -0
  49. package/dist/components/Form/Form.const.cjs +1 -0
  50. package/dist/components/Form/Form.const.d.ts +33 -0
  51. package/dist/components/Form/Form.const.js +27 -0
  52. package/dist/components/Form/Form.context.cjs +1 -0
  53. package/dist/components/Form/Form.context.d.ts +13 -0
  54. package/dist/components/Form/Form.context.js +12 -0
  55. package/dist/components/Form/Form.d.ts +18 -0
  56. package/dist/components/Form/Form.js +230 -0
  57. package/dist/components/Form/Form.types.d.ts +166 -0
  58. package/dist/components/Form/Form.utils.cjs +1 -0
  59. package/dist/components/Form/Form.utils.d.ts +17 -0
  60. package/dist/components/Form/Form.utils.js +31 -0
  61. package/dist/components/Form/index.d.ts +3 -0
  62. package/dist/components/Input/Input.cjs +1 -1
  63. package/dist/components/Input/Input.js +36 -36
  64. package/dist/components/NotificationCenter/NotificationCenter.cjs +1 -0
  65. package/dist/components/NotificationCenter/NotificationCenter.const.cjs +1 -0
  66. package/dist/components/NotificationCenter/NotificationCenter.const.d.ts +25 -0
  67. package/dist/components/NotificationCenter/NotificationCenter.const.js +28 -0
  68. package/dist/components/NotificationCenter/NotificationCenter.d.ts +15 -0
  69. package/dist/components/NotificationCenter/NotificationCenter.js +223 -0
  70. package/dist/components/NotificationCenter/NotificationCenter.types.d.ts +117 -0
  71. package/dist/components/NotificationCenter/NotificationCenter.utils.cjs +1 -0
  72. package/dist/components/NotificationCenter/NotificationCenter.utils.d.ts +11 -0
  73. package/dist/components/NotificationCenter/NotificationCenter.utils.js +19 -0
  74. package/dist/components/NotificationCenter/index.d.ts +2 -0
  75. package/dist/components/PhoneInput/PhoneInput.cjs +1 -0
  76. package/dist/components/PhoneInput/PhoneInput.const.cjs +1 -0
  77. package/dist/components/PhoneInput/PhoneInput.const.d.ts +33 -0
  78. package/dist/components/PhoneInput/PhoneInput.const.js +82 -0
  79. package/dist/components/PhoneInput/PhoneInput.d.ts +16 -0
  80. package/dist/components/PhoneInput/PhoneInput.js +194 -0
  81. package/dist/components/PhoneInput/PhoneInput.types.d.ts +108 -0
  82. package/dist/components/PhoneInput/PhoneInput.utils.cjs +1 -0
  83. package/dist/components/PhoneInput/PhoneInput.utils.d.ts +25 -0
  84. package/dist/components/PhoneInput/PhoneInput.utils.js +39 -0
  85. package/dist/components/PhoneInput/index.d.ts +2 -0
  86. package/dist/components/Select/Select.cjs +1 -1
  87. package/dist/components/Select/Select.js +37 -37
  88. package/dist/components/Sidebar/Sidebar.cjs +1 -1
  89. package/dist/components/Sidebar/Sidebar.const.cjs +1 -1
  90. package/dist/components/Sidebar/Sidebar.const.d.ts +6 -2
  91. package/dist/components/Sidebar/Sidebar.const.js +24 -17
  92. package/dist/components/Sidebar/Sidebar.js +36 -31
  93. package/dist/components/Sidebar/Sidebar.types.d.ts +9 -0
  94. package/dist/components/Sidebar/components/SidebarItem/SidebarItem.cjs +1 -1
  95. package/dist/components/Sidebar/components/SidebarItem/SidebarItem.js +30 -29
  96. package/dist/components/SignPad/SignPad.cjs +1 -1
  97. package/dist/components/SignPad/SignPad.js +56 -56
  98. package/dist/components/TimePicker/TimePicker.cjs +1 -1
  99. package/dist/components/TimePicker/TimePicker.constants.cjs +1 -1
  100. package/dist/components/TimePicker/TimePicker.constants.d.ts +22 -1
  101. package/dist/components/TimePicker/TimePicker.constants.js +36 -19
  102. package/dist/components/TimePicker/TimePicker.js +97 -131
  103. package/dist/components/TimePicker/TimePicker.types.d.ts +47 -6
  104. package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.cjs +1 -0
  105. package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.d.ts +3 -0
  106. package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.js +81 -0
  107. package/dist/components/TimePicker/components/TimePickerColumnsDropdown/index.d.ts +1 -0
  108. package/dist/components/TimePicker/components/TimePickerDialDropdown/TimePickerDialDropdown.cjs +1 -0
  109. package/dist/components/TimePicker/components/TimePickerDialDropdown/TimePickerDialDropdown.d.ts +3 -0
  110. package/dist/components/TimePicker/components/TimePickerDialDropdown/TimePickerDialDropdown.js +84 -0
  111. package/dist/components/TimePicker/components/TimePickerDialDropdown/index.d.ts +1 -0
  112. package/dist/components/TimePicker/helpers/ClockFaceSvg.cjs +1 -0
  113. package/dist/components/TimePicker/helpers/ClockFaceSvg.d.ts +18 -0
  114. package/dist/components/TimePicker/helpers/ClockFaceSvg.js +67 -0
  115. package/dist/components/TimePicker/helpers/index.d.ts +2 -0
  116. package/dist/components/TimePicker/index.d.ts +1 -1
  117. package/dist/components/index.cjs +1 -1
  118. package/dist/components/index.d.ts +13 -3
  119. package/dist/components/index.js +139 -126
  120. package/dist/context/BearProvider.cjs +1 -1
  121. package/dist/context/BearProvider.js +25 -25
  122. package/dist/index.cjs +1 -1
  123. package/dist/index.js +247 -234
  124. package/dist/styles.css +1 -1
  125. package/package.json +1 -1
  126. package/dist/components/DateTimePicker/DateTimePicker.cjs +0 -1
  127. package/dist/components/DateTimePicker/DateTimePicker.d.ts +0 -3
  128. package/dist/components/DateTimePicker/DateTimePicker.js +0 -178
  129. package/dist/components/DateTimePicker/DateTimePicker.types.d.ts +0 -26
  130. package/dist/components/DateTimePicker/DateTimePicker.utils.cjs +0 -1
  131. package/dist/components/DateTimePicker/DateTimePicker.utils.d.ts +0 -2
  132. package/dist/components/DateTimePicker/DateTimePicker.utils.js +0 -16
  133. package/dist/components/DateTimePicker/index.d.ts +0 -2
@@ -0,0 +1,27 @@
1
+ const e = {
2
+ required: "This field is required",
3
+ email: "Please enter a valid email address",
4
+ pattern: "Invalid format"
5
+ }, r = {
6
+ fields: {},
7
+ isSubmitting: !1,
8
+ isValid: !0,
9
+ isSubmitted: !1,
10
+ errors: {}
11
+ }, a = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i, l = {
12
+ vertical: "Bear-Form--vertical bear-flex bear-flex-col bear-gap-4",
13
+ horizontal: "Bear-Form--horizontal bear-flex bear-flex-col bear-gap-4",
14
+ inline: "Bear-Form--inline bear-flex bear-flex-wrap bear-items-end bear-gap-4"
15
+ }, i = {
16
+ vertical: "Bear-FormItem--vertical bear-flex bear-flex-col bear-gap-1.5",
17
+ horizontal: "Bear-FormItem--horizontal bear-flex bear-flex-row bear-items-start bear-gap-4",
18
+ inline: "Bear-FormItem--inline bear-flex bear-flex-col bear-gap-1"
19
+ }, t = "bear-w-32 bear-shrink-0";
20
+ export {
21
+ a as EMAIL_REGEX,
22
+ e as FORM_DEFAULT_TRANSLATIONS,
23
+ r as FORM_INITIAL_STATE,
24
+ i as FORM_ITEM_LAYOUT_CLASSES,
25
+ t as FORM_LABEL_WIDTH_HORIZONTAL,
26
+ l as FORM_LAYOUT_CLASSES
27
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),e=t.createContext(null),n=()=>{const o=t.useContext(e);if(!o)throw new Error("useFormContext must be used within a Form component");return o},r=()=>t.useContext(e);exports.FormContext=e;exports.useFormContext=n;exports.useFormContextSafe=r;
@@ -0,0 +1,13 @@
1
+ import { FormContextValue } from './Form.types';
2
+ /**
3
+ * Form context
4
+ */
5
+ export declare const FormContext: import('react').Context<FormContextValue | null>;
6
+ /**
7
+ * Hook to access form context
8
+ */
9
+ export declare const useFormContext: () => FormContextValue;
10
+ /**
11
+ * Hook to safely access form context (returns null if not in Form)
12
+ */
13
+ export declare const useFormContextSafe: () => FormContextValue | null;
@@ -0,0 +1,12 @@
1
+ import { createContext as n, useContext as o } from "react";
2
+ const e = n(null), s = () => {
3
+ const t = o(e);
4
+ if (!t)
5
+ throw new Error("useFormContext must be used within a Form component");
6
+ return t;
7
+ }, m = () => o(e);
8
+ export {
9
+ e as FormContext,
10
+ s as useFormContext,
11
+ m as useFormContextSafe
12
+ };
@@ -0,0 +1,18 @@
1
+ import { FC } from 'react';
2
+ import { FormProps, FormItemProps } from './Form.types';
3
+ /**
4
+ * Form - Form management component with validation
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * <Form onSubmit={handleSubmit} initialValues={{ email: '' }}>
9
+ * <Form.Item name="email" label="Email" rules={{ required: true, email: true }}>
10
+ * <Input />
11
+ * </Form.Item>
12
+ * <Button type="submit">Submit</Button>
13
+ * </Form>
14
+ * ```
15
+ */
16
+ export declare const Form: FC<FormProps> & {
17
+ Item: FC<FormItemProps>;
18
+ };
@@ -0,0 +1,230 @@
1
+ import { jsx as g, jsxs as B } from "react/jsx-runtime";
2
+ import { useState as M, useRef as V, useCallback as u, useMemo as q, isValidElement as z, cloneElement as k } from "react";
3
+ import { cn as E } from "../../utils/cn.js";
4
+ import { FormContext as D, useFormContext as H } from "./Form.context.js";
5
+ import { validateFieldValue as P } from "./Form.utils.js";
6
+ import { FORM_INITIAL_STATE as w, FORM_LAYOUT_CLASSES as U, FORM_LABEL_WIDTH_HORIZONTAL as Y, FORM_ITEM_LAYOUT_CLASSES as p } from "./Form.const.js";
7
+ const W = ({
8
+ children: I,
9
+ initialValues: n = {},
10
+ onSubmit: x,
11
+ onError: l,
12
+ layout: F = "vertical",
13
+ validateOnChange: m = !0,
14
+ validateOnBlur: h = !0,
15
+ className: N,
16
+ testId: S,
17
+ ...v
18
+ }) => {
19
+ const [o, i] = M(() => ({
20
+ ...w,
21
+ fields: Object.fromEntries(
22
+ Object.entries(n).map(([e, t]) => [
23
+ e,
24
+ { value: t, error: void 0, touched: !1, validating: !1, dirty: !1 }
25
+ ])
26
+ )
27
+ })), a = V({}), b = u((e, t) => {
28
+ i((r) => ({
29
+ ...r,
30
+ fields: {
31
+ ...r.fields,
32
+ [e]: {
33
+ ...r.fields[e],
34
+ value: t,
35
+ dirty: !0
36
+ }
37
+ }
38
+ }));
39
+ }, []), c = u((e) => {
40
+ var t;
41
+ return (t = o.fields[e]) == null ? void 0 : t.value;
42
+ }, [o.fields]), y = u((e, t) => {
43
+ i((r) => ({
44
+ ...r,
45
+ fields: {
46
+ ...r.fields,
47
+ [e]: {
48
+ ...r.fields[e],
49
+ error: t
50
+ }
51
+ },
52
+ errors: { ...r.errors, [e]: t }
53
+ }));
54
+ }, []), A = u((e) => {
55
+ i((t) => {
56
+ const r = { ...t.errors };
57
+ return delete r[e], {
58
+ ...t,
59
+ fields: {
60
+ ...t.fields,
61
+ [e]: {
62
+ ...t.fields[e],
63
+ error: void 0
64
+ }
65
+ },
66
+ errors: r
67
+ };
68
+ });
69
+ }, []), _ = u(async (e) => {
70
+ var f;
71
+ const t = a.current[e];
72
+ if (!t) return !0;
73
+ i((d) => ({
74
+ ...d,
75
+ fields: {
76
+ ...d.fields,
77
+ [e]: {
78
+ ...d.fields[e],
79
+ validating: !0
80
+ }
81
+ }
82
+ }));
83
+ const r = (f = o.fields[e]) == null ? void 0 : f.value, s = await P(r, t);
84
+ return i((d) => ({
85
+ ...d,
86
+ fields: {
87
+ ...d.fields,
88
+ [e]: {
89
+ ...d.fields[e],
90
+ error: s ?? void 0,
91
+ validating: !1
92
+ }
93
+ },
94
+ errors: s ? { ...d.errors, [e]: s } : (() => {
95
+ const T = { ...d.errors };
96
+ return delete T[e], T;
97
+ })()
98
+ })), !s;
99
+ }, [o.fields]), O = u(async () => {
100
+ const e = Object.keys(a.current);
101
+ return (await Promise.all(e.map(_))).every(Boolean);
102
+ }, [_]), L = u((e) => {
103
+ i({
104
+ ...w,
105
+ fields: Object.fromEntries(
106
+ Object.entries(e ?? n).map(([r, s]) => [
107
+ r,
108
+ { value: s, error: void 0, touched: !1, validating: !1, dirty: !1 }
109
+ ])
110
+ )
111
+ });
112
+ }, [n]), R = u((e, t) => {
113
+ var r;
114
+ return t && (a.current[e] = t), o.fields[e] || i((s) => ({
115
+ ...s,
116
+ fields: {
117
+ ...s.fields,
118
+ [e]: {
119
+ value: n[e] ?? "",
120
+ error: void 0,
121
+ touched: !1,
122
+ validating: !1,
123
+ dirty: !1
124
+ }
125
+ }
126
+ })), {
127
+ name: e,
128
+ value: ((r = o.fields[e]) == null ? void 0 : r.value) ?? n[e] ?? "",
129
+ onChange: (s) => {
130
+ b(e, s), m && t && setTimeout(() => _(e), 0);
131
+ },
132
+ onBlur: () => {
133
+ i((s) => ({
134
+ ...s,
135
+ fields: {
136
+ ...s.fields,
137
+ [e]: {
138
+ ...s.fields[e],
139
+ touched: !0
140
+ }
141
+ }
142
+ })), h && t && _(e);
143
+ }
144
+ };
145
+ }, [o.fields, n, b, _, m, h]), j = u(
146
+ (e) => async (t) => {
147
+ if (t.preventDefault(), i((f) => ({ ...f, isSubmitting: !0, isSubmitted: !0 })), !await O()) {
148
+ i((f) => ({ ...f, isSubmitting: !1 })), l == null || l(o.errors);
149
+ return;
150
+ }
151
+ const s = Object.fromEntries(
152
+ Object.entries(o.fields).map(([f, d]) => [f, d.value])
153
+ );
154
+ try {
155
+ await e(s);
156
+ } finally {
157
+ i((f) => ({ ...f, isSubmitting: !1 }));
158
+ }
159
+ },
160
+ [O, o.fields, o.errors, l]
161
+ ), C = q(
162
+ () => ({
163
+ state: o,
164
+ register: R,
165
+ setValue: b,
166
+ getValue: c,
167
+ setError: y,
168
+ clearError: A,
169
+ validateField: _,
170
+ validateForm: O,
171
+ reset: L,
172
+ handleSubmit: j,
173
+ layout: F
174
+ }),
175
+ [o, R, b, c, y, A, _, O, L, j, F]
176
+ );
177
+ return /* @__PURE__ */ g(D.Provider, { value: C, children: /* @__PURE__ */ g(
178
+ "form",
179
+ {
180
+ className: E("Bear-Form", U[F], N),
181
+ onSubmit: x ? j(x) : void 0,
182
+ "data-testid": S,
183
+ ...v,
184
+ children: I
185
+ }
186
+ ) });
187
+ }, Z = ({
188
+ name: I,
189
+ label: n,
190
+ required: x,
191
+ rules: l,
192
+ helperText: F,
193
+ children: m,
194
+ className: h
195
+ }) => {
196
+ const { register: N, state: S, layout: v } = H(), o = {
197
+ ...l,
198
+ required: x ?? (l == null ? void 0 : l.required)
199
+ }, i = N(I, o), a = S.fields[I], b = (a == null ? void 0 : a.touched) && (a == null ? void 0 : a.error);
200
+ return /* @__PURE__ */ B("div", { className: E("Bear-FormItem", p[v], h), children: [
201
+ n && /* @__PURE__ */ B(
202
+ "label",
203
+ {
204
+ className: E(
205
+ "Bear-FormItem__label bear-text-sm bear-font-medium bear-text-zinc-300",
206
+ v === "horizontal" && Y
207
+ ),
208
+ children: [
209
+ n,
210
+ (x || (l == null ? void 0 : l.required)) && /* @__PURE__ */ g("span", { className: "Bear-FormItem__required bear-text-red-500 bear-ml-0.5", children: "*" })
211
+ ]
212
+ }
213
+ ),
214
+ /* @__PURE__ */ B("div", { className: "Bear-FormItem__content bear-flex-1", children: [
215
+ /* @__PURE__ */ g("div", { className: "Bear-FormItem__control", children: typeof m == "function" ? m(i) : z(m) ? k(m, {
216
+ ...i,
217
+ onChange: (c) => {
218
+ const y = c && typeof c == "object" && "target" in c && c.target && typeof c.target.value < "u" ? c.target.value : c;
219
+ i.onChange(y);
220
+ }
221
+ }) : m }),
222
+ b && /* @__PURE__ */ g("p", { className: "Bear-FormItem__error bear-mt-1 bear-text-xs bear-text-red-400", children: a.error }),
223
+ F && !b && /* @__PURE__ */ g("p", { className: "Bear-FormItem__helper bear-mt-1 bear-text-xs bear-text-zinc-500", children: F })
224
+ ] })
225
+ ] });
226
+ };
227
+ W.Item = Z;
228
+ export {
229
+ W as Form
230
+ };
@@ -0,0 +1,166 @@
1
+ import { ReactNode, FormHTMLAttributes } from 'react';
2
+ /**
3
+ * Validation rule types
4
+ */
5
+ export type ValidationRule = {
6
+ /** Required field validation */
7
+ required?: boolean | string;
8
+ /** Minimum length validation */
9
+ minLength?: {
10
+ value: number;
11
+ message: string;
12
+ };
13
+ /** Maximum length validation */
14
+ maxLength?: {
15
+ value: number;
16
+ message: string;
17
+ };
18
+ /** Minimum value validation (for numbers) */
19
+ min?: {
20
+ value: number;
21
+ message: string;
22
+ };
23
+ /** Maximum value validation (for numbers) */
24
+ max?: {
25
+ value: number;
26
+ message: string;
27
+ };
28
+ /** Pattern validation (regex) */
29
+ pattern?: {
30
+ value: RegExp;
31
+ message: string;
32
+ };
33
+ /** Custom validation function */
34
+ validate?: (value: unknown) => boolean | string | Promise<boolean | string>;
35
+ /** Email validation */
36
+ email?: boolean | string;
37
+ };
38
+ /**
39
+ * Form field state
40
+ */
41
+ export interface FormFieldState {
42
+ /** Current value */
43
+ value: unknown;
44
+ /** Error message if validation failed */
45
+ error?: string;
46
+ /** Whether field has been touched */
47
+ touched: boolean;
48
+ /** Whether field is currently being validated */
49
+ validating: boolean;
50
+ /** Whether field is dirty (value changed) */
51
+ dirty: boolean;
52
+ }
53
+ /**
54
+ * Form state
55
+ */
56
+ export interface FormState {
57
+ /** Field states by name */
58
+ fields: Record<string, FormFieldState>;
59
+ /** Whether form is currently submitting */
60
+ isSubmitting: boolean;
61
+ /** Whether form is valid */
62
+ isValid: boolean;
63
+ /** Whether form has been submitted */
64
+ isSubmitted: boolean;
65
+ /** Form-level errors */
66
+ errors: Record<string, string>;
67
+ }
68
+ /**
69
+ * Form context value
70
+ */
71
+ export interface FormContextValue {
72
+ /** Current form state */
73
+ state: FormState;
74
+ /** Register a field */
75
+ register: (name: string, rules?: ValidationRule) => {
76
+ name: string;
77
+ value: unknown;
78
+ onChange: (value: unknown) => void;
79
+ onBlur: () => void;
80
+ };
81
+ /** Set field value */
82
+ setValue: (name: string, value: unknown) => void;
83
+ /** Get field value */
84
+ getValue: (name: string) => unknown;
85
+ /** Set field error */
86
+ setError: (name: string, error: string) => void;
87
+ /** Clear field error */
88
+ clearError: (name: string) => void;
89
+ /** Validate a field */
90
+ validateField: (name: string) => Promise<boolean>;
91
+ /** Validate all fields */
92
+ validateForm: () => Promise<boolean>;
93
+ /** Reset form */
94
+ reset: (values?: Record<string, unknown>) => void;
95
+ /** Handle form submission */
96
+ handleSubmit: (onSubmit: (data: Record<string, unknown>) => void | Promise<void>) => (e: React.FormEvent) => void;
97
+ /** Form layout */
98
+ layout: FormLayout;
99
+ }
100
+ /**
101
+ * Form layout options
102
+ */
103
+ export type FormLayout = 'vertical' | 'horizontal' | 'inline';
104
+ /**
105
+ * Form component props
106
+ */
107
+ export interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'onError'> {
108
+ /** Child elements */
109
+ children: ReactNode;
110
+ /** Initial form values */
111
+ initialValues?: Record<string, unknown>;
112
+ /** Form submission handler */
113
+ onSubmit?: (data: Record<string, unknown>) => void | Promise<void>;
114
+ /** Form validation error handler */
115
+ onError?: (errors: Record<string, string>) => void;
116
+ /** Form layout */
117
+ layout?: FormLayout;
118
+ /** Whether to validate on change */
119
+ validateOnChange?: boolean;
120
+ /** Whether to validate on blur */
121
+ validateOnBlur?: boolean;
122
+ /** Custom class name */
123
+ className?: string;
124
+ /** Test ID */
125
+ testId?: string;
126
+ }
127
+ /**
128
+ * Field props from register
129
+ */
130
+ export interface FormFieldProps {
131
+ name: string;
132
+ value: unknown;
133
+ onChange: (value: unknown) => void;
134
+ onBlur: () => void;
135
+ }
136
+ /**
137
+ * Form.Item props
138
+ */
139
+ export interface FormItemProps {
140
+ /** Field name */
141
+ name: string;
142
+ /** Field label */
143
+ label?: string;
144
+ /** Required indicator */
145
+ required?: boolean;
146
+ /** Validation rules */
147
+ rules?: ValidationRule;
148
+ /** Helper text */
149
+ helperText?: string;
150
+ /** Children (form control or render prop) */
151
+ children: ReactNode | ((field: FormFieldProps) => ReactNode);
152
+ /** Custom class name */
153
+ className?: string;
154
+ }
155
+ /**
156
+ * Form translations
157
+ */
158
+ export interface FormTranslations {
159
+ required: string;
160
+ email: string;
161
+ minLength: string;
162
+ maxLength: string;
163
+ min: string;
164
+ max: string;
165
+ pattern: string;
166
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./Form.const.cjs"),r=async(i,t)=>{const n=typeof i=="string"?i:String(i??""),e=typeof i=="number"?i:Number(i);if(t.required&&(i==null||n.trim()===""))return typeof t.required=="string"?t.required:m.FORM_DEFAULT_TRANSLATIONS.required;if(i==null||n==="")return null;if(t.email&&!m.EMAIL_REGEX.test(n))return typeof t.email=="string"?t.email:m.FORM_DEFAULT_TRANSLATIONS.email;if(t.minLength&&n.length<t.minLength.value)return t.minLength.message;if(t.maxLength&&n.length>t.maxLength.value)return t.maxLength.message;if(t.min&&!isNaN(e)&&e<t.min.value)return t.min.message;if(t.max&&!isNaN(e)&&e>t.max.value)return t.max.message;if(t.pattern&&!t.pattern.value.test(n))return t.pattern.message;if(t.validate){const a=await t.validate(i);if(typeof a=="string")return a;if(a===!1)return m.FORM_DEFAULT_TRANSLATIONS.pattern}return null};exports.validateFieldValue=r;
@@ -0,0 +1,17 @@
1
+ import { ValidationRule } from './Form.types';
2
+ /**
3
+ * Validate a single field value against rules
4
+ */
5
+ export declare const validateFieldValue: (value: unknown, rules: ValidationRule) => Promise<string | null>;
6
+ /**
7
+ * Deep clone an object
8
+ */
9
+ export declare const deepClone: <T>(obj: T) => T;
10
+ /**
11
+ * Get nested value from object by path
12
+ */
13
+ export declare const getNestedValue: (obj: Record<string, unknown>, path: string) => unknown;
14
+ /**
15
+ * Set nested value in object by path
16
+ */
17
+ export declare const setNestedValue: (obj: Record<string, unknown>, path: string, value: unknown) => Record<string, unknown>;
@@ -0,0 +1,31 @@
1
+ import { FORM_DEFAULT_TRANSLATIONS as m, EMAIL_REGEX as f } from "./Form.const.js";
2
+ const g = async (i, t) => {
3
+ const n = typeof i == "string" ? i : String(i ?? ""), e = typeof i == "number" ? i : Number(i);
4
+ if (t.required && (i == null || n.trim() === ""))
5
+ return typeof t.required == "string" ? t.required : m.required;
6
+ if (i == null || n === "")
7
+ return null;
8
+ if (t.email && !f.test(n))
9
+ return typeof t.email == "string" ? t.email : m.email;
10
+ if (t.minLength && n.length < t.minLength.value)
11
+ return t.minLength.message;
12
+ if (t.maxLength && n.length > t.maxLength.value)
13
+ return t.maxLength.message;
14
+ if (t.min && !isNaN(e) && e < t.min.value)
15
+ return t.min.message;
16
+ if (t.max && !isNaN(e) && e > t.max.value)
17
+ return t.max.message;
18
+ if (t.pattern && !t.pattern.value.test(n))
19
+ return t.pattern.message;
20
+ if (t.validate) {
21
+ const a = await t.validate(i);
22
+ if (typeof a == "string")
23
+ return a;
24
+ if (a === !1)
25
+ return m.pattern;
26
+ }
27
+ return null;
28
+ };
29
+ export {
30
+ g as validateFieldValue
31
+ };
@@ -0,0 +1,3 @@
1
+ export { Form } from './Form';
2
+ export { useFormContext, useFormContextSafe } from './Form.context';
3
+ export type { FormProps, FormItemProps, FormState, FormFieldState, FormContextValue, FormLayout, ValidationRule, FormTranslations, } from './Form.types';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),f=require("react"),b=require("../../utils/cn.cjs"),_={sm:"bear-h-8 bear-text-sm bear-px-3",md:"bear-h-10 bear-text-base bear-px-4",lg:"bear-h-12 bear-text-lg bear-px-5"},u=f.forwardRef(({label:s,helperText:n,error:r,size:c="md",leftAddon:a,rightAddon:t,fullWidth:i=!1,className:d,disabled:l,...p},x)=>{const o=!!r;return e.jsxs("div",{className:b.cn("Bear-Input bear-flex bear-flex-col bear-gap-1.5",i&&"bear-w-full"),children:[s&&e.jsx("label",{className:"Bear-Input__label bear-text-sm bear-font-medium bear-text-gray-300",children:s}),e.jsxs("div",{className:"Bear-Input__wrapper bear-relative bear-flex bear-items-center",children:[a&&e.jsx("div",{className:"Bear-Input__addon Bear-Input__addon--left bear-absolute bear-left-3 bear-text-gray-400",children:a}),e.jsx("input",{ref:x,disabled:l,className:b.cn("Bear-Input__field","bear-w-full bear-rounded-lg bear-border bear-bg-gray-800","bear-text-white placeholder:bear-text-gray-500","bear-outline-none bear-transition-all bear-duration-200","focus:bear-ring-2 focus:bear-ring-offset-2 focus:bear-ring-offset-gray-900",o?"Bear-Input__field--error bear-border-red-500 focus:bear-ring-red-500":"bear-border-gray-600 focus:bear-border-bear-500 focus:bear-ring-bear-500",l&&"Bear-Input__field--disabled bear-opacity-50 bear-cursor-not-allowed",a&&"bear-pl-10",t&&"bear-pr-10",_[c],d),...p}),t&&e.jsx("div",{className:"Bear-Input__addon Bear-Input__addon--right bear-absolute bear-right-3 bear-text-gray-400",children:t})]}),(n||r)&&e.jsx("p",{className:b.cn("Bear-Input__helper bear-text-sm",o?"Bear-Input__helper--error bear-text-red-500":"bear-text-gray-400"),children:r||n})]})});u.displayName="Input";exports.Input=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),g=require("react"),b=require("../../utils/cn.cjs"),f={sm:"bear-h-8 bear-text-sm bear-px-3",md:"bear-h-10 bear-text-base bear-px-4",lg:"bear-h-12 bear-text-lg bear-px-5"},d=g.forwardRef(({label:s,helperText:n,error:r,size:u="md",leftAddon:a,rightAddon:t,fullWidth:c=!1,className:i,disabled:l,...p},x)=>{const o=!!r;return e.jsxs("div",{className:b.cn("Bear-Input bear-flex bear-flex-col bear-gap-1.5",c&&"bear-w-full"),children:[s&&e.jsx("label",{className:"Bear-Input__label bear-text-sm bear-font-medium bear-text-gray-700 dark:bear-text-gray-300",children:s}),e.jsxs("div",{className:"Bear-Input__wrapper bear-relative bear-flex bear-items-center",children:[a&&e.jsx("div",{className:"Bear-Input__addon Bear-Input__addon--left bear-absolute bear-left-3 bear-text-gray-500 dark:bear-text-gray-400",children:a}),e.jsx("input",{ref:x,disabled:l,className:b.cn("Bear-Input__field","bear-w-full bear-rounded-lg bear-border bear-outline-none bear-transition-all bear-duration-200","bear-bg-white bear-text-gray-900 placeholder:bear-text-gray-400","bear-border-gray-300 focus:bear-ring-2 focus:bear-ring-offset-2 focus:bear-ring-offset-white","dark:bear-bg-gray-800 dark:bear-text-white dark:placeholder:bear-text-gray-500 dark:bear-border-gray-600 dark:focus:bear-ring-offset-gray-900",o?"Bear-Input__field--error bear-border-red-500 focus:bear-ring-red-500":"focus:bear-border-bear-500 focus:bear-ring-bear-500 dark:focus:bear-border-bear-500 dark:focus:bear-ring-bear-500",l&&"Bear-Input__field--disabled bear-opacity-50 bear-cursor-not-allowed",a&&"bear-pl-10",t&&"bear-pr-10",f[u],i),...p}),t&&e.jsx("div",{className:"Bear-Input__addon Bear-Input__addon--right bear-absolute bear-right-3 bear-text-gray-500 dark:bear-text-gray-400",children:t})]}),(n||r)&&e.jsx("p",{className:b.cn("Bear-Input__helper bear-text-sm",o?"Bear-Input__helper--error bear-text-red-500":"bear-text-gray-500 dark:bear-text-gray-400"),children:r||n})]})});d.displayName="Input";exports.Input=d;
@@ -1,65 +1,65 @@
1
- import { jsxs as i, jsx as e } from "react/jsx-runtime";
2
- import { forwardRef as m } from "react";
3
- import { cn as b } from "../../utils/cn.js";
4
- const _ = {
1
+ import { jsxs as n, jsx as r } from "react/jsx-runtime";
2
+ import { forwardRef as g } from "react";
3
+ import { cn as t } from "../../utils/cn.js";
4
+ const x = {
5
5
  sm: "bear-h-8 bear-text-sm bear-px-3",
6
6
  md: "bear-h-10 bear-text-base bear-px-4",
7
7
  lg: "bear-h-12 bear-text-lg bear-px-5"
8
- }, x = m(
8
+ }, m = g(
9
9
  ({
10
- label: l,
11
- helperText: s,
12
- error: r,
13
- size: p = "md",
10
+ label: s,
11
+ helperText: l,
12
+ error: e,
13
+ size: i = "md",
14
14
  leftAddon: a,
15
- rightAddon: t,
15
+ rightAddon: b,
16
16
  fullWidth: u = !1,
17
- className: d,
18
- disabled: n,
17
+ className: p,
18
+ disabled: o,
19
19
  ...c
20
20
  }, f) => {
21
- const o = !!r;
22
- return /* @__PURE__ */ i("div", { className: b("Bear-Input bear-flex bear-flex-col bear-gap-1.5", u && "bear-w-full"), children: [
23
- l && /* @__PURE__ */ e("label", { className: "Bear-Input__label bear-text-sm bear-font-medium bear-text-gray-300", children: l }),
24
- /* @__PURE__ */ i("div", { className: "Bear-Input__wrapper bear-relative bear-flex bear-items-center", children: [
25
- a && /* @__PURE__ */ e("div", { className: "Bear-Input__addon Bear-Input__addon--left bear-absolute bear-left-3 bear-text-gray-400", children: a }),
26
- /* @__PURE__ */ e(
21
+ const d = !!e;
22
+ return /* @__PURE__ */ n("div", { className: t("Bear-Input bear-flex bear-flex-col bear-gap-1.5", u && "bear-w-full"), children: [
23
+ s && /* @__PURE__ */ r("label", { className: "Bear-Input__label bear-text-sm bear-font-medium bear-text-gray-700 dark:bear-text-gray-300", children: s }),
24
+ /* @__PURE__ */ n("div", { className: "Bear-Input__wrapper bear-relative bear-flex bear-items-center", children: [
25
+ a && /* @__PURE__ */ r("div", { className: "Bear-Input__addon Bear-Input__addon--left bear-absolute bear-left-3 bear-text-gray-500 dark:bear-text-gray-400", children: a }),
26
+ /* @__PURE__ */ r(
27
27
  "input",
28
28
  {
29
29
  ref: f,
30
- disabled: n,
31
- className: b(
30
+ disabled: o,
31
+ className: t(
32
32
  "Bear-Input__field",
33
- "bear-w-full bear-rounded-lg bear-border bear-bg-gray-800",
34
- "bear-text-white placeholder:bear-text-gray-500",
35
- "bear-outline-none bear-transition-all bear-duration-200",
36
- "focus:bear-ring-2 focus:bear-ring-offset-2 focus:bear-ring-offset-gray-900",
37
- o ? "Bear-Input__field--error bear-border-red-500 focus:bear-ring-red-500" : "bear-border-gray-600 focus:bear-border-bear-500 focus:bear-ring-bear-500",
38
- n && "Bear-Input__field--disabled bear-opacity-50 bear-cursor-not-allowed",
33
+ "bear-w-full bear-rounded-lg bear-border bear-outline-none bear-transition-all bear-duration-200",
34
+ "bear-bg-white bear-text-gray-900 placeholder:bear-text-gray-400",
35
+ "bear-border-gray-300 focus:bear-ring-2 focus:bear-ring-offset-2 focus:bear-ring-offset-white",
36
+ "dark:bear-bg-gray-800 dark:bear-text-white dark:placeholder:bear-text-gray-500 dark:bear-border-gray-600 dark:focus:bear-ring-offset-gray-900",
37
+ d ? "Bear-Input__field--error bear-border-red-500 focus:bear-ring-red-500" : "focus:bear-border-bear-500 focus:bear-ring-bear-500 dark:focus:bear-border-bear-500 dark:focus:bear-ring-bear-500",
38
+ o && "Bear-Input__field--disabled bear-opacity-50 bear-cursor-not-allowed",
39
39
  a && "bear-pl-10",
40
- t && "bear-pr-10",
41
- _[p],
42
- d
40
+ b && "bear-pr-10",
41
+ x[i],
42
+ p
43
43
  ),
44
44
  ...c
45
45
  }
46
46
  ),
47
- t && /* @__PURE__ */ e("div", { className: "Bear-Input__addon Bear-Input__addon--right bear-absolute bear-right-3 bear-text-gray-400", children: t })
47
+ b && /* @__PURE__ */ r("div", { className: "Bear-Input__addon Bear-Input__addon--right bear-absolute bear-right-3 bear-text-gray-500 dark:bear-text-gray-400", children: b })
48
48
  ] }),
49
- (s || r) && /* @__PURE__ */ e(
49
+ (l || e) && /* @__PURE__ */ r(
50
50
  "p",
51
51
  {
52
- className: b(
52
+ className: t(
53
53
  "Bear-Input__helper bear-text-sm",
54
- o ? "Bear-Input__helper--error bear-text-red-500" : "bear-text-gray-400"
54
+ d ? "Bear-Input__helper--error bear-text-red-500" : "bear-text-gray-500 dark:bear-text-gray-400"
55
55
  ),
56
- children: r || s
56
+ children: e || l
57
57
  }
58
58
  )
59
59
  ] });
60
60
  }
61
61
  );
62
- x.displayName = "Input";
62
+ m.displayName = "Input";
63
63
  export {
64
- x as Input
64
+ m as Input
65
65
  };