@jameskabz/nextcraft-ui 0.6.6 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/dist/components/craft-alert.cjs +69 -0
  2. package/dist/components/craft-alert.cjs.map +1 -0
  3. package/dist/components/craft-alert.d.cts +16 -0
  4. package/dist/components/craft-alert.d.ts +16 -0
  5. package/dist/components/craft-alert.js +45 -0
  6. package/dist/components/craft-alert.js.map +1 -0
  7. package/dist/components/craft-badge.cjs +54 -0
  8. package/dist/components/craft-badge.cjs.map +1 -0
  9. package/dist/components/craft-badge.d.cts +12 -0
  10. package/dist/components/craft-badge.d.ts +12 -0
  11. package/dist/components/craft-badge.js +30 -0
  12. package/dist/components/craft-badge.js.map +1 -0
  13. package/dist/components/craft-button.cjs +66 -0
  14. package/dist/components/craft-button.cjs.map +1 -0
  15. package/dist/components/craft-button.d.cts +15 -0
  16. package/dist/components/craft-button.d.ts +15 -0
  17. package/dist/components/craft-button.js +42 -0
  18. package/dist/components/craft-button.js.map +1 -0
  19. package/dist/components/craft-card.cjs +63 -0
  20. package/dist/components/craft-card.cjs.map +1 -0
  21. package/dist/components/craft-card.d.cts +13 -0
  22. package/dist/components/craft-card.d.ts +13 -0
  23. package/dist/components/craft-card.js +39 -0
  24. package/dist/components/craft-card.js.map +1 -0
  25. package/dist/components/craft-checkbox.cjs +103 -0
  26. package/dist/components/craft-checkbox.cjs.map +1 -0
  27. package/dist/components/craft-checkbox.d.cts +16 -0
  28. package/dist/components/craft-checkbox.d.ts +16 -0
  29. package/dist/components/craft-checkbox.js +69 -0
  30. package/dist/components/craft-checkbox.js.map +1 -0
  31. package/dist/components/craft-command-palette.cjs +134 -0
  32. package/dist/components/craft-command-palette.cjs.map +1 -0
  33. package/dist/components/craft-command-palette.d.cts +28 -0
  34. package/dist/components/craft-command-palette.d.ts +28 -0
  35. package/dist/components/craft-command-palette.js +100 -0
  36. package/dist/components/craft-command-palette.js.map +1 -0
  37. package/dist/components/craft-confirm-dialog.cjs +114 -0
  38. package/dist/components/craft-confirm-dialog.cjs.map +1 -0
  39. package/dist/components/craft-confirm-dialog.d.cts +21 -0
  40. package/dist/components/craft-confirm-dialog.d.ts +21 -0
  41. package/dist/components/craft-confirm-dialog.js +80 -0
  42. package/dist/components/craft-confirm-dialog.js.map +1 -0
  43. package/dist/components/craft-create-edit-drawer.cjs +112 -0
  44. package/dist/components/craft-create-edit-drawer.cjs.map +1 -0
  45. package/dist/components/craft-create-edit-drawer.d.cts +28 -0
  46. package/dist/components/craft-create-edit-drawer.d.ts +28 -0
  47. package/dist/components/craft-create-edit-drawer.js +78 -0
  48. package/dist/components/craft-create-edit-drawer.js.map +1 -0
  49. package/dist/components/craft-currency-input.cjs +68 -0
  50. package/dist/components/craft-currency-input.cjs.map +1 -0
  51. package/dist/components/craft-currency-input.d.cts +14 -0
  52. package/dist/components/craft-currency-input.d.ts +14 -0
  53. package/dist/components/craft-currency-input.js +34 -0
  54. package/dist/components/craft-currency-input.js.map +1 -0
  55. package/dist/components/craft-data-table.cjs +407 -0
  56. package/dist/components/craft-data-table.cjs.map +1 -0
  57. package/dist/components/craft-data-table.d.cts +58 -0
  58. package/dist/components/craft-data-table.d.ts +58 -0
  59. package/dist/components/craft-data-table.js +373 -0
  60. package/dist/components/craft-data-table.js.map +1 -0
  61. package/dist/components/craft-date-picker.cjs +226 -0
  62. package/dist/components/craft-date-picker.cjs.map +1 -0
  63. package/dist/components/craft-date-picker.d.cts +17 -0
  64. package/dist/components/craft-date-picker.d.ts +17 -0
  65. package/dist/components/craft-date-picker.js +192 -0
  66. package/dist/components/craft-date-picker.js.map +1 -0
  67. package/dist/components/craft-drawer.cjs +126 -0
  68. package/dist/components/craft-drawer.cjs.map +1 -0
  69. package/dist/components/craft-drawer.d.cts +19 -0
  70. package/dist/components/craft-drawer.d.ts +19 -0
  71. package/dist/components/craft-drawer.js +92 -0
  72. package/dist/components/craft-drawer.js.map +1 -0
  73. package/dist/components/craft-dropdown-menu.cjs +127 -0
  74. package/dist/components/craft-dropdown-menu.cjs.map +1 -0
  75. package/dist/components/craft-dropdown-menu.d.cts +28 -0
  76. package/dist/components/craft-dropdown-menu.d.ts +28 -0
  77. package/dist/components/craft-dropdown-menu.js +93 -0
  78. package/dist/components/craft-dropdown-menu.js.map +1 -0
  79. package/dist/components/craft-empty-state.cjs +58 -0
  80. package/dist/components/craft-empty-state.cjs.map +1 -0
  81. package/dist/components/craft-empty-state.d.cts +14 -0
  82. package/dist/components/craft-empty-state.d.ts +14 -0
  83. package/dist/components/craft-empty-state.js +34 -0
  84. package/dist/components/craft-empty-state.js.map +1 -0
  85. package/dist/components/craft-error-state.cjs +60 -0
  86. package/dist/components/craft-error-state.cjs.map +1 -0
  87. package/dist/components/craft-error-state.d.cts +15 -0
  88. package/dist/components/craft-error-state.d.ts +15 -0
  89. package/dist/components/craft-error-state.js +36 -0
  90. package/dist/components/craft-error-state.js.map +1 -0
  91. package/dist/components/craft-filter-bar.cjs +76 -0
  92. package/dist/components/craft-filter-bar.cjs.map +1 -0
  93. package/dist/components/craft-filter-bar.d.cts +18 -0
  94. package/dist/components/craft-filter-bar.d.ts +18 -0
  95. package/dist/components/craft-filter-bar.js +52 -0
  96. package/dist/components/craft-filter-bar.js.map +1 -0
  97. package/dist/components/craft-form-builder.cjs +330 -0
  98. package/dist/components/craft-form-builder.cjs.map +1 -0
  99. package/dist/components/craft-form-builder.d.cts +57 -0
  100. package/dist/components/craft-form-builder.d.ts +57 -0
  101. package/dist/components/craft-form-builder.js +301 -0
  102. package/dist/components/craft-form-builder.js.map +1 -0
  103. package/dist/components/craft-form-field.cjs +301 -0
  104. package/dist/components/craft-form-field.cjs.map +1 -0
  105. package/dist/components/craft-form-field.d.cts +30 -0
  106. package/dist/components/craft-form-field.d.ts +30 -0
  107. package/dist/components/craft-form-field.js +280 -0
  108. package/dist/components/craft-form-field.js.map +1 -0
  109. package/dist/components/craft-form.cjs +114 -0
  110. package/dist/components/craft-form.cjs.map +1 -0
  111. package/dist/components/craft-form.d.cts +27 -0
  112. package/dist/components/craft-form.d.ts +27 -0
  113. package/dist/components/craft-form.js +80 -0
  114. package/dist/components/craft-form.js.map +1 -0
  115. package/dist/components/craft-icon.cjs +102 -0
  116. package/dist/components/craft-icon.cjs.map +1 -0
  117. package/dist/components/craft-icon.d.cts +19 -0
  118. package/dist/components/craft-icon.d.ts +19 -0
  119. package/dist/components/craft-icon.js +67 -0
  120. package/dist/components/craft-icon.js.map +1 -0
  121. package/dist/components/craft-input.cjs +78 -0
  122. package/dist/components/craft-input.cjs.map +1 -0
  123. package/dist/components/craft-input.d.cts +19 -0
  124. package/dist/components/craft-input.d.ts +19 -0
  125. package/dist/components/craft-input.js +44 -0
  126. package/dist/components/craft-input.js.map +1 -0
  127. package/dist/components/craft-link.cjs +70 -0
  128. package/dist/components/craft-link.cjs.map +1 -0
  129. package/dist/components/craft-link.d.cts +14 -0
  130. package/dist/components/craft-link.d.ts +14 -0
  131. package/dist/components/craft-link.js +36 -0
  132. package/dist/components/craft-link.js.map +1 -0
  133. package/dist/components/craft-loading-state.cjs +64 -0
  134. package/dist/components/craft-loading-state.cjs.map +1 -0
  135. package/dist/components/craft-loading-state.d.cts +13 -0
  136. package/dist/components/craft-loading-state.d.ts +13 -0
  137. package/dist/components/craft-loading-state.js +40 -0
  138. package/dist/components/craft-loading-state.js.map +1 -0
  139. package/dist/components/craft-modal.cjs +174 -0
  140. package/dist/components/craft-modal.cjs.map +1 -0
  141. package/dist/components/craft-modal.d.cts +19 -0
  142. package/dist/components/craft-modal.d.ts +19 -0
  143. package/dist/components/craft-modal.js +140 -0
  144. package/dist/components/craft-modal.js.map +1 -0
  145. package/dist/components/craft-number-input.cjs +63 -0
  146. package/dist/components/craft-number-input.cjs.map +1 -0
  147. package/dist/components/craft-number-input.d.cts +12 -0
  148. package/dist/components/craft-number-input.d.ts +12 -0
  149. package/dist/components/craft-number-input.js +29 -0
  150. package/dist/components/craft-number-input.js.map +1 -0
  151. package/dist/components/craft-pagination.cjs +130 -0
  152. package/dist/components/craft-pagination.cjs.map +1 -0
  153. package/dist/components/craft-pagination.d.cts +19 -0
  154. package/dist/components/craft-pagination.d.ts +19 -0
  155. package/dist/components/craft-pagination.js +106 -0
  156. package/dist/components/craft-pagination.js.map +1 -0
  157. package/dist/components/craft-popover.cjs +123 -0
  158. package/dist/components/craft-popover.cjs.map +1 -0
  159. package/dist/components/craft-popover.d.cts +20 -0
  160. package/dist/components/craft-popover.d.ts +20 -0
  161. package/dist/components/craft-popover.js +89 -0
  162. package/dist/components/craft-popover.js.map +1 -0
  163. package/dist/components/craft-select.cjs +84 -0
  164. package/dist/components/craft-select.cjs.map +1 -0
  165. package/dist/components/craft-select.d.cts +12 -0
  166. package/dist/components/craft-select.d.ts +12 -0
  167. package/dist/components/craft-select.js +50 -0
  168. package/dist/components/craft-select.js.map +1 -0
  169. package/dist/components/craft-skeleton.cjs +45 -0
  170. package/dist/components/craft-skeleton.cjs.map +1 -0
  171. package/dist/components/craft-skeleton.d.cts +10 -0
  172. package/dist/components/craft-skeleton.d.ts +10 -0
  173. package/dist/components/craft-skeleton.js +21 -0
  174. package/dist/components/craft-skeleton.js.map +1 -0
  175. package/dist/components/craft-stat-card.cjs +67 -0
  176. package/dist/components/craft-stat-card.cjs.map +1 -0
  177. package/dist/components/craft-stat-card.d.cts +17 -0
  178. package/dist/components/craft-stat-card.d.ts +17 -0
  179. package/dist/components/craft-stat-card.js +43 -0
  180. package/dist/components/craft-stat-card.js.map +1 -0
  181. package/dist/components/craft-submit-button.cjs +71 -0
  182. package/dist/components/craft-submit-button.cjs.map +1 -0
  183. package/dist/components/craft-submit-button.d.cts +13 -0
  184. package/dist/components/craft-submit-button.d.ts +13 -0
  185. package/dist/components/craft-submit-button.js +47 -0
  186. package/dist/components/craft-submit-button.js.map +1 -0
  187. package/dist/components/craft-switch.cjs +82 -0
  188. package/dist/components/craft-switch.cjs.map +1 -0
  189. package/dist/components/craft-switch.d.cts +14 -0
  190. package/dist/components/craft-switch.d.ts +14 -0
  191. package/dist/components/craft-switch.js +48 -0
  192. package/dist/components/craft-switch.js.map +1 -0
  193. package/dist/components/craft-table-toolbar.cjs +79 -0
  194. package/dist/components/craft-table-toolbar.cjs.map +1 -0
  195. package/dist/components/craft-table-toolbar.d.cts +19 -0
  196. package/dist/components/craft-table-toolbar.d.ts +19 -0
  197. package/dist/components/craft-table-toolbar.js +55 -0
  198. package/dist/components/craft-table-toolbar.js.map +1 -0
  199. package/dist/components/craft-tabs.cjs +105 -0
  200. package/dist/components/craft-tabs.cjs.map +1 -0
  201. package/dist/components/craft-tabs.d.cts +19 -0
  202. package/dist/components/craft-tabs.d.ts +19 -0
  203. package/dist/components/craft-tabs.js +71 -0
  204. package/dist/components/craft-tabs.js.map +1 -0
  205. package/dist/components/craft-textarea.cjs +69 -0
  206. package/dist/components/craft-textarea.cjs.map +1 -0
  207. package/dist/components/craft-textarea.d.cts +12 -0
  208. package/dist/components/craft-textarea.d.ts +12 -0
  209. package/dist/components/craft-textarea.js +35 -0
  210. package/dist/components/craft-textarea.js.map +1 -0
  211. package/dist/components/craft-toast.cjs +98 -0
  212. package/dist/components/craft-toast.cjs.map +1 -0
  213. package/dist/components/craft-toast.d.cts +24 -0
  214. package/dist/components/craft-toast.d.ts +24 -0
  215. package/dist/components/craft-toast.js +63 -0
  216. package/dist/components/craft-toast.js.map +1 -0
  217. package/dist/components/craft-tooltip.cjs +75 -0
  218. package/dist/components/craft-tooltip.cjs.map +1 -0
  219. package/dist/components/craft-tooltip.d.cts +13 -0
  220. package/dist/components/craft-tooltip.d.ts +13 -0
  221. package/dist/components/craft-tooltip.js +41 -0
  222. package/dist/components/craft-tooltip.js.map +1 -0
  223. package/dist/components/glass-card.cjs +64 -0
  224. package/dist/components/glass-card.cjs.map +1 -0
  225. package/dist/components/glass-card.d.cts +12 -0
  226. package/dist/components/glass-card.d.ts +12 -0
  227. package/dist/components/glass-card.js +40 -0
  228. package/dist/components/glass-card.js.map +1 -0
  229. package/dist/components/layout/app-shell.cjs +49 -0
  230. package/dist/components/layout/app-shell.cjs.map +1 -0
  231. package/dist/components/layout/app-shell.d.cts +10 -0
  232. package/dist/components/layout/app-shell.d.ts +10 -0
  233. package/dist/components/layout/app-shell.js +25 -0
  234. package/dist/components/layout/app-shell.js.map +1 -0
  235. package/dist/components/layout/app-template.cjs +104 -0
  236. package/dist/components/layout/app-template.cjs.map +1 -0
  237. package/dist/components/layout/app-template.d.cts +19 -0
  238. package/dist/components/layout/app-template.d.ts +19 -0
  239. package/dist/components/layout/app-template.js +70 -0
  240. package/dist/components/layout/app-template.js.map +1 -0
  241. package/dist/components/layout/auth-layout.cjs +65 -0
  242. package/dist/components/layout/auth-layout.cjs.map +1 -0
  243. package/dist/components/layout/auth-layout.d.cts +12 -0
  244. package/dist/components/layout/auth-layout.d.ts +12 -0
  245. package/dist/components/layout/auth-layout.js +41 -0
  246. package/dist/components/layout/auth-layout.js.map +1 -0
  247. package/dist/components/layout/breadcrumbs.cjs +39 -0
  248. package/dist/components/layout/breadcrumbs.cjs.map +1 -0
  249. package/dist/components/layout/breadcrumbs.d.cts +13 -0
  250. package/dist/components/layout/breadcrumbs.d.ts +13 -0
  251. package/dist/components/layout/breadcrumbs.js +15 -0
  252. package/dist/components/layout/breadcrumbs.js.map +1 -0
  253. package/dist/components/layout/container.cjs +45 -0
  254. package/dist/components/layout/container.cjs.map +1 -0
  255. package/dist/components/layout/container.d.cts +9 -0
  256. package/dist/components/layout/container.d.ts +9 -0
  257. package/dist/components/layout/container.js +21 -0
  258. package/dist/components/layout/container.js.map +1 -0
  259. package/dist/components/layout/grid.cjs +47 -0
  260. package/dist/components/layout/grid.cjs.map +1 -0
  261. package/dist/components/layout/grid.d.cts +10 -0
  262. package/dist/components/layout/grid.d.ts +10 -0
  263. package/dist/components/layout/grid.js +23 -0
  264. package/dist/components/layout/grid.js.map +1 -0
  265. package/dist/components/layout/layout-config.cjs +78 -0
  266. package/dist/components/layout/layout-config.cjs.map +1 -0
  267. package/dist/components/layout/layout-config.d.cts +92 -0
  268. package/dist/components/layout/layout-config.d.ts +92 -0
  269. package/dist/components/layout/layout-config.js +54 -0
  270. package/dist/components/layout/layout-config.js.map +1 -0
  271. package/dist/components/layout/page-header.cjs +52 -0
  272. package/dist/components/layout/page-header.cjs.map +1 -0
  273. package/dist/components/layout/page-header.d.cts +11 -0
  274. package/dist/components/layout/page-header.d.ts +11 -0
  275. package/dist/components/layout/page-header.js +28 -0
  276. package/dist/components/layout/page-header.js.map +1 -0
  277. package/dist/components/layout/sidebar.cjs +64 -0
  278. package/dist/components/layout/sidebar.cjs.map +1 -0
  279. package/dist/components/layout/sidebar.d.cts +17 -0
  280. package/dist/components/layout/sidebar.d.ts +17 -0
  281. package/dist/components/layout/sidebar.js +40 -0
  282. package/dist/components/layout/sidebar.js.map +1 -0
  283. package/dist/components/layout/top-nav.cjs +49 -0
  284. package/dist/components/layout/top-nav.cjs.map +1 -0
  285. package/dist/components/layout/top-nav.d.cts +11 -0
  286. package/dist/components/layout/top-nav.d.ts +11 -0
  287. package/dist/components/layout/top-nav.js +25 -0
  288. package/dist/components/layout/top-nav.js.map +1 -0
  289. package/dist/components/theme-switcher.cjs +72 -0
  290. package/dist/components/theme-switcher.cjs.map +1 -0
  291. package/dist/components/theme-switcher.d.cts +9 -0
  292. package/dist/components/theme-switcher.d.ts +9 -0
  293. package/dist/components/theme-switcher.js +48 -0
  294. package/dist/components/theme-switcher.js.map +1 -0
  295. package/dist/index.cjs +103 -3448
  296. package/dist/index.cjs.map +1 -1
  297. package/dist/index.d.cts +54 -746
  298. package/dist/index.d.ts +54 -746
  299. package/dist/index.js +50 -3388
  300. package/dist/index.js.map +1 -1
  301. package/dist/theme-context-EVI9PfKv.d.cts +22 -0
  302. package/dist/theme-context-EVI9PfKv.d.ts +22 -0
  303. package/dist/utils/cn.cjs +31 -0
  304. package/dist/utils/cn.cjs.map +1 -0
  305. package/dist/utils/cn.d.cts +3 -0
  306. package/dist/utils/cn.d.ts +3 -0
  307. package/dist/utils/cn.js +7 -0
  308. package/dist/utils/cn.js.map +1 -0
  309. package/package.json +3 -2
@@ -0,0 +1,301 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import {
5
+ FormProvider,
6
+ useForm
7
+ } from "react-hook-form";
8
+ import { cn } from "../utils/cn";
9
+ import { CraftModal } from "../components/craft-modal";
10
+ import { CraftButton } from "../components/craft-button";
11
+ import { CraftSubmitButton } from "../components/craft-submit-button";
12
+ import {
13
+ CraftFormField
14
+ } from "../components/craft-form-field";
15
+ function defaultValueForField(field) {
16
+ var _a, _b, _c, _d;
17
+ if (field.defaultValue !== void 0) return field.defaultValue;
18
+ switch (field.type) {
19
+ case "checkbox":
20
+ case "switch":
21
+ return false;
22
+ case "number":
23
+ case "slider":
24
+ case "range":
25
+ return (_a = field.min) != null ? _a : 0;
26
+ case "multifile":
27
+ return [];
28
+ case "file":
29
+ return null;
30
+ case "multiselect":
31
+ return [];
32
+ case "radio":
33
+ return (_d = (_c = (_b = field.options) == null ? void 0 : _b[0]) == null ? void 0 : _c.value) != null ? _d : "";
34
+ default:
35
+ return "";
36
+ }
37
+ }
38
+ function buildDefaultValues(fields, initialData) {
39
+ const values = {};
40
+ fields.forEach((field) => {
41
+ const initialValue = initialData == null ? void 0 : initialData[field.name];
42
+ if (initialValue !== void 0 && initialValue !== null) {
43
+ values[field.name] = initialValue;
44
+ } else {
45
+ values[field.name] = defaultValueForField(field);
46
+ }
47
+ });
48
+ return values;
49
+ }
50
+ function buildRules(field, getValues) {
51
+ var _a;
52
+ const rules = { ...field.rules };
53
+ const mergeValidate = (current, next) => {
54
+ if (!current) return next;
55
+ if (typeof current === "function") {
56
+ return (value) => {
57
+ const result = current(
58
+ value,
59
+ getValues()
60
+ );
61
+ if (result !== true) return result;
62
+ return next(value);
63
+ };
64
+ }
65
+ if (typeof current === "object") {
66
+ return (value) => {
67
+ const entries = Object.entries(current);
68
+ for (const [, validator] of entries) {
69
+ const result = validator(
70
+ value,
71
+ getValues()
72
+ );
73
+ if (result !== true) return result;
74
+ }
75
+ return next(value);
76
+ };
77
+ }
78
+ return next;
79
+ };
80
+ if (field.required && field.type !== "hidden") {
81
+ if (field.type === "checkbox" || field.type === "switch") {
82
+ rules.validate = mergeValidate(
83
+ rules.validate,
84
+ (value) => {
85
+ var _a2;
86
+ return value ? true : `${String((_a2 = field.label) != null ? _a2 : field.name)} is required`;
87
+ }
88
+ );
89
+ } else if (field.type === "multiselect") {
90
+ rules.validate = mergeValidate(
91
+ rules.validate,
92
+ (value) => {
93
+ var _a2;
94
+ return Array.isArray(value) && value.length > 0 ? true : `${String((_a2 = field.label) != null ? _a2 : field.name)} is required`;
95
+ }
96
+ );
97
+ } else if (field.type === "file") {
98
+ rules.validate = mergeValidate(
99
+ rules.validate,
100
+ (value) => {
101
+ var _a2;
102
+ return value instanceof FileList && value.length > 0 ? true : `${String((_a2 = field.label) != null ? _a2 : field.name)} is required`;
103
+ }
104
+ );
105
+ } else if (field.type === "multifile") {
106
+ rules.validate = mergeValidate(
107
+ rules.validate,
108
+ (value) => {
109
+ var _a2;
110
+ return Array.isArray(value) && value.length > 0 ? true : `${String((_a2 = field.label) != null ? _a2 : field.name)} is required`;
111
+ }
112
+ );
113
+ } else {
114
+ rules.required = `${String((_a = field.label) != null ? _a : field.name)} is required`;
115
+ }
116
+ }
117
+ if (field.min !== void 0) {
118
+ rules.min = { value: field.min, message: `Min ${field.min}` };
119
+ }
120
+ if (field.max !== void 0) {
121
+ rules.max = { value: field.max, message: `Max ${field.max}` };
122
+ }
123
+ if (field.type === "email") {
124
+ rules.pattern = {
125
+ value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
126
+ message: "Please enter a valid email address"
127
+ };
128
+ }
129
+ if (field.type === "url") {
130
+ rules.pattern = {
131
+ value: /^https?:\/\/.+/,
132
+ message: "Please enter a valid URL"
133
+ };
134
+ }
135
+ if (field.validate) {
136
+ rules.validate = mergeValidate(
137
+ rules.validate,
138
+ (value) => {
139
+ var _a2;
140
+ return (_a2 = field.validate) == null ? void 0 : _a2.call(field, value, getValues());
141
+ }
142
+ );
143
+ }
144
+ return rules;
145
+ }
146
+ function CraftFormBuilder({
147
+ title = "Form",
148
+ description,
149
+ fields,
150
+ initialData = null,
151
+ open,
152
+ defaultOpen = false,
153
+ onOpenChange,
154
+ trigger,
155
+ submitLabel = "Submit",
156
+ cancelLabel = "Cancel",
157
+ resetLabel = "Reset",
158
+ showReset = true,
159
+ showCancel = true,
160
+ tone,
161
+ className,
162
+ formClassName,
163
+ loading = false,
164
+ disableSubmitWhenInvalid = true,
165
+ closeOnSubmit = true,
166
+ closeOnCancel = true,
167
+ onSubmit,
168
+ onReset,
169
+ onCancel,
170
+ customValidation
171
+ }) {
172
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
173
+ const isControlled = typeof open === "boolean";
174
+ const isOpen = isControlled ? open : uncontrolledOpen;
175
+ const setOpen = React.useCallback(
176
+ (next) => {
177
+ if (!isControlled) setUncontrolledOpen(next);
178
+ onOpenChange == null ? void 0 : onOpenChange(next);
179
+ },
180
+ [isControlled, onOpenChange]
181
+ );
182
+ const defaultValues = React.useMemo(
183
+ () => buildDefaultValues(fields, initialData),
184
+ [fields, initialData]
185
+ );
186
+ const form = useForm({
187
+ mode: "onChange",
188
+ defaultValues
189
+ });
190
+ const formId = React.useId();
191
+ React.useEffect(() => {
192
+ form.reset(defaultValues);
193
+ }, [defaultValues, form]);
194
+ const handleSubmit = form.handleSubmit(async (values) => {
195
+ if (customValidation) {
196
+ const customErrors = customValidation(values);
197
+ if (customErrors && Object.keys(customErrors).length > 0) {
198
+ Object.entries(customErrors).forEach(([key, message]) => {
199
+ if (message) {
200
+ form.setError(key, {
201
+ type: "custom",
202
+ message: String(message)
203
+ });
204
+ }
205
+ });
206
+ return;
207
+ }
208
+ }
209
+ await onSubmit(values);
210
+ if (closeOnSubmit) setOpen(false);
211
+ });
212
+ const handleReset = () => {
213
+ form.reset(defaultValues);
214
+ onReset == null ? void 0 : onReset();
215
+ };
216
+ const handleCancel = () => {
217
+ onCancel == null ? void 0 : onCancel();
218
+ if (closeOnCancel) setOpen(false);
219
+ };
220
+ return /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */ jsx(
221
+ CraftModal,
222
+ {
223
+ open: isOpen,
224
+ onOpenChange: setOpen,
225
+ trigger,
226
+ title,
227
+ description,
228
+ tone,
229
+ className,
230
+ footer: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-end gap-3", children: [
231
+ showReset && /* @__PURE__ */ jsx(
232
+ CraftButton,
233
+ {
234
+ type: "button",
235
+ variant: "outline",
236
+ onClick: handleReset,
237
+ disabled: loading,
238
+ children: resetLabel
239
+ }
240
+ ),
241
+ showCancel && /* @__PURE__ */ jsx(
242
+ CraftButton,
243
+ {
244
+ type: "button",
245
+ variant: "ghost",
246
+ onClick: handleCancel,
247
+ disabled: loading,
248
+ children: cancelLabel
249
+ }
250
+ ),
251
+ /* @__PURE__ */ jsx(
252
+ CraftSubmitButton,
253
+ {
254
+ loading,
255
+ disableWhenInvalid: disableSubmitWhenInvalid,
256
+ form: formId,
257
+ children: submitLabel
258
+ }
259
+ )
260
+ ] }),
261
+ children: /* @__PURE__ */ jsx(
262
+ "form",
263
+ {
264
+ id: formId,
265
+ onSubmit: handleSubmit,
266
+ className: cn("space-y-5", formClassName),
267
+ children: fields.map((field) => /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
268
+ field.helpText && /* @__PURE__ */ jsx("p", { className: "text-xs text-[rgb(var(--nc-fg-muted))]", children: field.helpText }),
269
+ /* @__PURE__ */ jsx(
270
+ CraftFormField,
271
+ {
272
+ name: field.name,
273
+ label: field.label,
274
+ description: field.description,
275
+ type: field.type,
276
+ placeholder: field.placeholder,
277
+ options: field.options,
278
+ tone,
279
+ disabled: field.disabled || loading,
280
+ rules: buildRules(field, form.getValues),
281
+ fieldProps: {
282
+ min: field.min,
283
+ max: field.max,
284
+ step: field.step,
285
+ rows: field.rows,
286
+ accept: field.accept,
287
+ multiple: field.type === "multifile",
288
+ ...field.fieldProps
289
+ }
290
+ }
291
+ )
292
+ ] }, field.name))
293
+ }
294
+ )
295
+ }
296
+ ) });
297
+ }
298
+ export {
299
+ CraftFormBuilder
300
+ };
301
+ //# sourceMappingURL=craft-form-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/craft-form-builder.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n FormProvider,\n type DefaultValues,\n type FieldValues,\n type Path,\n type RegisterOptions,\n useForm,\n} from \"react-hook-form\";\n\nimport { cn } from \"@/utils/cn\";\nimport type { ThemeName } from \"@/theme/theme-context\";\nimport { CraftModal } from \"@/components/craft-modal\";\nimport { CraftButton } from \"@/components/craft-button\";\nimport { CraftSubmitButton } from \"@/components/craft-submit-button\";\nimport {\n CraftFormField,\n type CraftFormFieldOption,\n type CraftFormFieldType,\n} from \"@/components/craft-form-field\";\n\nexport type CraftFormBuilderField<TValues extends FieldValues> = {\n name: Path<TValues>;\n label?: React.ReactNode;\n description?: React.ReactNode;\n type: CraftFormFieldType;\n placeholder?: string;\n options?: CraftFormFieldOption[];\n required?: boolean;\n disabled?: boolean;\n rules?: RegisterOptions<TValues>;\n defaultValue?: unknown;\n min?: number;\n max?: number;\n step?: number;\n rows?: number;\n accept?: string;\n minFiles?: number;\n maxFiles?: number;\n helpText?: React.ReactNode;\n fieldProps?: Record<string, unknown>;\n validate?: (value: unknown, values: TValues) => string | boolean | undefined;\n};\n\nexport type CraftFormBuilderProps<TValues extends FieldValues> = {\n title?: React.ReactNode;\n description?: React.ReactNode;\n fields: Array<CraftFormBuilderField<TValues>>;\n initialData?: Partial<TValues> | null;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n trigger?: React.ReactNode;\n submitLabel?: React.ReactNode;\n cancelLabel?: React.ReactNode;\n resetLabel?: React.ReactNode;\n showReset?: boolean;\n showCancel?: boolean;\n tone?: ThemeName;\n className?: string;\n formClassName?: string;\n loading?: boolean;\n disableSubmitWhenInvalid?: boolean;\n closeOnSubmit?: boolean;\n closeOnCancel?: boolean;\n onSubmit: (values: TValues) => void | Promise<void>;\n onReset?: () => void;\n onCancel?: () => void;\n customValidation?: (values: TValues) => Partial<Record<Path<TValues>, string>>;\n};\n\nfunction defaultValueForField<TValues extends FieldValues>(\n field: CraftFormBuilderField<TValues>\n) {\n if (field.defaultValue !== undefined) return field.defaultValue;\n switch (field.type) {\n case \"checkbox\":\n case \"switch\":\n return false;\n case \"number\":\n case \"slider\":\n case \"range\":\n return field.min ?? 0;\n case \"multifile\":\n return [];\n case \"file\":\n return null;\n case \"multiselect\":\n return [];\n case \"radio\":\n return field.options?.[0]?.value ?? \"\";\n default:\n return \"\";\n }\n}\n\nfunction buildDefaultValues<TValues extends FieldValues>(\n fields: Array<CraftFormBuilderField<TValues>>,\n initialData?: Partial<TValues> | null\n): DefaultValues<TValues> {\n const values = {} as Record<string, unknown>;\n fields.forEach((field) => {\n const initialValue = initialData?.[field.name as keyof TValues];\n if (initialValue !== undefined && initialValue !== null) {\n values[field.name] = initialValue;\n } else {\n values[field.name] = defaultValueForField(field);\n }\n });\n return values as DefaultValues<TValues>;\n}\n\nfunction buildRules<TValues extends FieldValues>(\n field: CraftFormBuilderField<TValues>,\n getValues: () => TValues\n): RegisterOptions<TValues> {\n const rules: RegisterOptions<TValues> = { ...field.rules };\n const mergeValidate = (\n current: RegisterOptions<TValues>[\"validate\"],\n next: (value: unknown) => string | boolean | undefined\n ) => {\n if (!current) return next;\n if (typeof current === \"function\") {\n return (value: unknown): string | boolean | undefined => {\n const result = (current as (value: unknown, values: TValues) => string | boolean | undefined)(\n value,\n getValues()\n );\n if (result !== true) return result as string | undefined;\n return next(value);\n };\n }\n if (typeof current === \"object\") {\n return (value: unknown): string | boolean | undefined => {\n const entries = Object.entries(current);\n for (const [, validator] of entries) {\n const result = (validator as (value: unknown, values: TValues) => string | boolean | undefined)(\n value,\n getValues()\n );\n if (result !== true) return result as string | undefined;\n }\n return next(value);\n };\n }\n return next;\n };\n\n if (field.required && field.type !== \"hidden\") {\n if (field.type === \"checkbox\" || field.type === \"switch\") {\n rules.validate = mergeValidate(\n rules.validate,\n (value: unknown): string | boolean | undefined =>\n value ? true : `${String(field.label ?? field.name)} is required`\n );\n } else if (field.type === \"multiselect\") {\n rules.validate = mergeValidate(\n rules.validate,\n (value: unknown): string | boolean | undefined =>\n Array.isArray(value) && value.length > 0\n ? true\n : `${String(field.label ?? field.name)} is required`\n );\n } else if (field.type === \"file\") {\n rules.validate = mergeValidate(\n rules.validate,\n (value: unknown): string | boolean | undefined =>\n value instanceof FileList && value.length > 0\n ? true\n : `${String(field.label ?? field.name)} is required`\n );\n } else if (field.type === \"multifile\") {\n rules.validate = mergeValidate(\n rules.validate,\n (value: unknown): string | boolean | undefined =>\n Array.isArray(value) && value.length > 0\n ? true\n : `${String(field.label ?? field.name)} is required`\n );\n } else {\n rules.required = `${String(field.label ?? field.name)} is required`;\n }\n }\n\n if (field.min !== undefined) {\n rules.min = { value: field.min, message: `Min ${field.min}` };\n }\n if (field.max !== undefined) {\n rules.max = { value: field.max, message: `Max ${field.max}` };\n }\n\n if (field.type === \"email\") {\n rules.pattern = {\n value: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n message: \"Please enter a valid email address\",\n };\n }\n\n if (field.type === \"url\") {\n rules.pattern = {\n value: /^https?:\\/\\/.+/,\n message: \"Please enter a valid URL\",\n };\n }\n\n if (field.validate) {\n rules.validate = mergeValidate(\n rules.validate,\n (value: unknown): string | boolean | undefined =>\n field.validate?.(value, getValues())\n );\n }\n\n return rules;\n}\n\nexport function CraftFormBuilder<TValues extends FieldValues>({\n title = \"Form\",\n description,\n fields,\n initialData = null,\n open,\n defaultOpen = false,\n onOpenChange,\n trigger,\n submitLabel = \"Submit\",\n cancelLabel = \"Cancel\",\n resetLabel = \"Reset\",\n showReset = true,\n showCancel = true,\n tone,\n className,\n formClassName,\n loading = false,\n disableSubmitWhenInvalid = true,\n closeOnSubmit = true,\n closeOnCancel = true,\n onSubmit,\n onReset,\n onCancel,\n customValidation,\n}: CraftFormBuilderProps<TValues>) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n const isControlled = typeof open === \"boolean\";\n const isOpen = isControlled ? open : uncontrolledOpen;\n\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (!isControlled) setUncontrolledOpen(next);\n onOpenChange?.(next);\n },\n [isControlled, onOpenChange]\n );\n\n const defaultValues = React.useMemo(\n () => buildDefaultValues(fields, initialData),\n [fields, initialData]\n );\n\n const form = useForm<TValues>({\n mode: \"onChange\",\n defaultValues,\n });\n\n const formId = React.useId();\n\n React.useEffect(() => {\n form.reset(defaultValues);\n }, [defaultValues, form]);\n\n const handleSubmit = form.handleSubmit(async (values) => {\n if (customValidation) {\n const customErrors = customValidation(values);\n if (customErrors && Object.keys(customErrors).length > 0) {\n Object.entries(customErrors).forEach(([key, message]) => {\n if (message) {\n form.setError(key as Path<TValues>, {\n type: \"custom\",\n message: String(message),\n });\n }\n });\n return;\n }\n }\n\n await onSubmit(values);\n if (closeOnSubmit) setOpen(false);\n });\n\n const handleReset = () => {\n form.reset(defaultValues);\n onReset?.();\n };\n\n const handleCancel = () => {\n onCancel?.();\n if (closeOnCancel) setOpen(false);\n };\n\n return (\n <FormProvider {...form}>\n <CraftModal\n open={isOpen}\n onOpenChange={setOpen}\n trigger={trigger}\n title={title}\n description={description}\n tone={tone}\n className={className}\n footer={\n <div className=\"flex flex-wrap items-center justify-end gap-3\">\n {showReset && (\n <CraftButton\n type=\"button\"\n variant=\"outline\"\n onClick={handleReset}\n disabled={loading}\n >\n {resetLabel}\n </CraftButton>\n )}\n {showCancel && (\n <CraftButton\n type=\"button\"\n variant=\"ghost\"\n onClick={handleCancel}\n disabled={loading}\n >\n {cancelLabel}\n </CraftButton>\n )}\n <CraftSubmitButton\n loading={loading}\n disableWhenInvalid={disableSubmitWhenInvalid}\n form={formId}\n >\n {submitLabel}\n </CraftSubmitButton>\n </div>\n }\n >\n <form\n id={formId}\n onSubmit={handleSubmit}\n className={cn(\"space-y-5\", formClassName)}\n >\n {fields.map((field) => (\n <div key={field.name} className=\"space-y-2\">\n {field.helpText && (\n <p className=\"text-xs text-[rgb(var(--nc-fg-muted))]\">\n {field.helpText}\n </p>\n )}\n <CraftFormField\n name={field.name}\n label={field.label}\n description={field.description}\n type={field.type}\n placeholder={field.placeholder}\n options={field.options}\n tone={tone}\n disabled={field.disabled || loading}\n rules={buildRules(field, form.getValues)}\n fieldProps={{\n min: field.min,\n max: field.max,\n step: field.step,\n rows: field.rows,\n accept: field.accept,\n multiple: field.type === \"multifile\",\n ...field.fieldProps,\n }}\n />\n </div>\n ))}\n </form>\n </CraftModal>\n </FormProvider>\n );\n}"],"mappings":";AAyTU,SAEI,KAFJ;AAvTV,YAAY,WAAW;AACvB;AAAA,EACE;AAAA,EAKA;AAAA,OACK;AAEP,SAAS,UAAU;AAEnB,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,OAGK;AAoDP,SAAS,qBACP,OACA;AA3EF;AA4EE,MAAI,MAAM,iBAAiB,OAAW,QAAO,MAAM;AACnD,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,cAAO,WAAM,QAAN,YAAa;AAAA,IACtB,KAAK;AACH,aAAO,CAAC;AAAA,IACV,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,CAAC;AAAA,IACV,KAAK;AACH,cAAO,uBAAM,YAAN,mBAAgB,OAAhB,mBAAoB,UAApB,YAA6B;AAAA,IACtC;AACE,aAAO;AAAA,EACX;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iBAAO,IAAI,CAAC,UACX,qBAAC,SAAqB,WAAU,aAC7B;AAAA,kBAAM,YACL,oBAAC,OAAE,WAAU,0CACV,gBAAM,UACT;AAAA,YAEF;AAAA,cAAC;AAAA;AAAA,gBACC,MAAM,MAAM;AAAA,gBACZ,OAAO,MAAM;AAAA,gBACb,aAAa,MAAM;AAAA,gBACnB,MAAM,MAAM;AAAA,gBACZ,aAAa,MAAM;AAAA,gBACnB,SAAS,MAAM;AAAA,gBACf;AAAA,gBACA,UAAU,MAAM,YAAY;AAAA,gBAC5B,OAAO,WAAW,OAAO,KAAK,SAAS;AAAA,gBACvC,YAAY;AAAA,kBACV,KAAK,MAAM;AAAA,kBACX,KAAK,MAAM;AAAA,kBACX,MAAM,MAAM;AAAA,kBACZ,MAAM,MAAM;AAAA,kBACZ,QAAQ,MAAM;AAAA,kBACd,UAAU,MAAM,SAAS;AAAA,kBACzB,GAAG,MAAM;AAAA,gBACX;AAAA;AAAA,YACF;AAAA,eAzBQ,MAAM,IA0BhB,CACD;AAAA;AAAA,MACH;AAAA;AAAA,EACF,GACF;AAEJ;","names":["_a"]}
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var craft_form_field_exports = {};
21
+ __export(craft_form_field_exports, {
22
+ CraftFormField: () => CraftFormField
23
+ });
24
+ module.exports = __toCommonJS(craft_form_field_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react_hook_form = require("react-hook-form");
27
+ var import_cn = require("../utils/cn");
28
+ var import_craft_input = require("../components/craft-input");
29
+ var import_craft_textarea = require("../components/craft-textarea");
30
+ var import_craft_select = require("../components/craft-select");
31
+ var import_craft_checkbox = require("../components/craft-checkbox");
32
+ var import_craft_switch = require("../components/craft-switch");
33
+ var import_craft_date_picker = require("../components/craft-date-picker");
34
+ var import_craft_number_input = require("../components/craft-number-input");
35
+ var import_craft_currency_input = require("../components/craft-currency-input");
36
+ function getFieldError(errors, name) {
37
+ if (!errors || typeof errors !== "object") return void 0;
38
+ const segments = name.split(".");
39
+ let current = errors;
40
+ for (const segment of segments) {
41
+ if (!current || typeof current !== "object") return void 0;
42
+ current = current[segment];
43
+ }
44
+ return current;
45
+ }
46
+ const baseInputClass = "w-full rounded-2xl border-2 bg-[rgb(var(--nc-surface)/0.08)] text-[rgb(var(--nc-fg))] backdrop-blur-xl shadow-[inset_0_2px_8px_rgba(0,0,0,0.3)] focus:outline-none focus:ring-4 transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed border-[rgb(var(--nc-border)/0.35)] focus:border-[rgb(var(--nc-accent-1)/0.8)] focus:ring-[rgb(var(--nc-accent-1)/0.3)] px-5 py-3 text-base placeholder:text-[rgb(var(--nc-fg-soft))]";
47
+ function CraftFormField({
48
+ name,
49
+ label,
50
+ description,
51
+ type = "text",
52
+ options = [],
53
+ placeholder,
54
+ tone,
55
+ className,
56
+ inputClassName,
57
+ labelClassName,
58
+ descriptionClassName,
59
+ rules,
60
+ disabled,
61
+ fieldProps
62
+ }) {
63
+ const { register, control, formState } = (0, import_react_hook_form.useFormContext)();
64
+ const error = getFieldError(formState.errors, name);
65
+ const errorMessage = typeof (error == null ? void 0 : error.message) === "string" ? error.message : void 0;
66
+ if (type === "hidden") {
67
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "hidden", ...register(name, rules) });
68
+ }
69
+ const labelNode = label ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
70
+ "label",
71
+ {
72
+ htmlFor: name,
73
+ className: (0, import_cn.cn)(
74
+ "text-sm font-semibold text-[rgb(var(--nc-fg))]",
75
+ labelClassName
76
+ ),
77
+ children: label
78
+ }
79
+ ) : null;
80
+ const descriptionNode = description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
81
+ "p",
82
+ {
83
+ className: (0, import_cn.cn)(
84
+ "text-xs text-[rgb(var(--nc-fg-muted))]",
85
+ descriptionClassName
86
+ ),
87
+ children: description
88
+ }
89
+ ) : null;
90
+ const errorNode = errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-[rgb(var(--nc-accent-3))]", children: errorMessage }) : null;
91
+ const renderInput = () => {
92
+ if (type === "textarea") {
93
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
94
+ import_craft_textarea.CraftTextarea,
95
+ {
96
+ id: name,
97
+ placeholder,
98
+ tone,
99
+ className: inputClassName,
100
+ disabled,
101
+ ...fieldProps,
102
+ ...register(name, rules)
103
+ }
104
+ );
105
+ }
106
+ if (type === "select" || type === "multiselect") {
107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
108
+ import_craft_select.CraftSelect,
109
+ {
110
+ id: name,
111
+ tone,
112
+ className: inputClassName,
113
+ multiple: type === "multiselect",
114
+ disabled,
115
+ ...fieldProps,
116
+ ...register(name, rules),
117
+ children: [
118
+ placeholder && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", disabled: true, children: placeholder }),
119
+ options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
120
+ "option",
121
+ {
122
+ value: option.value,
123
+ disabled: option.disabled,
124
+ children: option.label
125
+ },
126
+ option.value
127
+ ))
128
+ ]
129
+ }
130
+ );
131
+ }
132
+ if (type === "checkbox") {
133
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
134
+ import_craft_checkbox.CraftCheckbox,
135
+ {
136
+ tone,
137
+ label,
138
+ description,
139
+ disabled,
140
+ ...fieldProps,
141
+ ...register(name, rules)
142
+ }
143
+ );
144
+ }
145
+ if (type === "switch") {
146
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
147
+ import_craft_switch.CraftSwitch,
148
+ {
149
+ tone,
150
+ label,
151
+ disabled,
152
+ ...fieldProps,
153
+ ...register(name, rules)
154
+ }
155
+ );
156
+ }
157
+ if (type === "date") {
158
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
+ import_react_hook_form.Controller,
160
+ {
161
+ control,
162
+ name,
163
+ rules,
164
+ render: ({ field }) => {
165
+ var _a;
166
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
167
+ import_craft_date_picker.CraftDatePicker,
168
+ {
169
+ value: (_a = field.value) != null ? _a : "",
170
+ onChange: field.onChange,
171
+ tone,
172
+ placeholder,
173
+ ...fieldProps
174
+ }
175
+ );
176
+ }
177
+ }
178
+ );
179
+ }
180
+ if (type === "number") {
181
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
182
+ import_craft_number_input.CraftNumberInput,
183
+ {
184
+ id: name,
185
+ tone,
186
+ placeholder,
187
+ className: inputClassName,
188
+ disabled,
189
+ ...fieldProps,
190
+ ...register(name, rules)
191
+ }
192
+ );
193
+ }
194
+ if (type === "currency") {
195
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
196
+ import_craft_currency_input.CraftCurrencyInput,
197
+ {
198
+ id: name,
199
+ tone,
200
+ placeholder,
201
+ className: inputClassName,
202
+ disabled,
203
+ ...fieldProps,
204
+ ...register(name, rules)
205
+ }
206
+ );
207
+ }
208
+ if (type === "radio") {
209
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "grid gap-3", children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
210
+ "label",
211
+ {
212
+ className: (0, import_cn.cn)(
213
+ "flex items-center gap-3 rounded-2xl border border-[rgb(var(--nc-border)/0.35)] bg-[rgb(var(--nc-surface)/0.08)] px-4 py-3 text-sm text-[rgb(var(--nc-fg))]",
214
+ "transition-all duration-200",
215
+ "focus-within:ring-2 focus-within:ring-[rgb(var(--nc-accent-1)/0.5)]",
216
+ option.disabled ? "opacity-60" : "cursor-pointer"
217
+ ),
218
+ "data-nc-theme": tone,
219
+ children: [
220
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
221
+ "input",
222
+ {
223
+ type: "radio",
224
+ value: option.value,
225
+ disabled: option.disabled || disabled,
226
+ className: "h-4 w-4 accent-[rgb(var(--nc-accent-1))]",
227
+ ...fieldProps,
228
+ ...register(name, rules)
229
+ }
230
+ ),
231
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: option.label })
232
+ ]
233
+ },
234
+ option.value
235
+ )) });
236
+ }
237
+ if (type === "range" || type === "slider") {
238
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
239
+ "input",
240
+ {
241
+ id: name,
242
+ type: "range",
243
+ className: (0, import_cn.cn)(
244
+ "w-full accent-[rgb(var(--nc-accent-1))]",
245
+ inputClassName
246
+ ),
247
+ disabled,
248
+ ...fieldProps,
249
+ ...register(name, rules)
250
+ }
251
+ );
252
+ }
253
+ if (type === "file" || type === "multifile") {
254
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
255
+ "input",
256
+ {
257
+ id: name,
258
+ type: "file",
259
+ multiple: type === "multifile",
260
+ className: (0, import_cn.cn)(
261
+ baseInputClass,
262
+ "file:mr-4 file:rounded-xl file:border-0 file:bg-[rgb(var(--nc-surface)/0.35)] file:px-4 file:py-2 file:text-sm file:font-semibold file:text-[rgb(var(--nc-fg))]",
263
+ inputClassName
264
+ ),
265
+ disabled,
266
+ ...fieldProps,
267
+ ...register(name, rules)
268
+ }
269
+ );
270
+ }
271
+ const inputType = type === "search" || type === "password" || type === "email" || type === "tel" || type === "url" || type === "time" || type === "datetime-local" || type === "month" || type === "week" || type === "color" ? type : "text";
272
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
273
+ import_craft_input.CraftInput,
274
+ {
275
+ id: name,
276
+ type: inputType,
277
+ placeholder,
278
+ tone,
279
+ className: inputClassName,
280
+ disabled,
281
+ ...fieldProps,
282
+ ...register(name, rules)
283
+ }
284
+ );
285
+ };
286
+ const showLabel = type !== "checkbox" && type !== "switch";
287
+ const showDescriptionAbove = type !== "checkbox" && type !== "switch";
288
+ const showDescriptionBelow = type === "switch";
289
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_cn.cn)("space-y-2", className), "data-nc-theme": tone, children: [
290
+ showLabel ? labelNode : null,
291
+ showDescriptionAbove ? descriptionNode : null,
292
+ renderInput(),
293
+ showDescriptionBelow ? descriptionNode : null,
294
+ errorNode
295
+ ] });
296
+ }
297
+ // Annotate the CommonJS export names for ESM import in node:
298
+ 0 && (module.exports = {
299
+ CraftFormField
300
+ });
301
+ //# sourceMappingURL=craft-form-field.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/craft-form-field.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Controller,\n type FieldValues,\n type Path,\n type RegisterOptions,\n useFormContext,\n} from \"react-hook-form\";\n\nimport { cn } from \"@/utils/cn\";\nimport type { ThemeName } from \"@/theme/theme-context\";\nimport { CraftInput } from \"@/components/craft-input\";\nimport { CraftTextarea } from \"@/components/craft-textarea\";\nimport { CraftSelect } from \"@/components/craft-select\";\nimport { CraftCheckbox } from \"@/components/craft-checkbox\";\nimport { CraftSwitch } from \"@/components/craft-switch\";\nimport { CraftDatePicker } from \"@/components/craft-date-picker\";\nimport { CraftNumberInput } from \"@/components/craft-number-input\";\nimport { CraftCurrencyInput } from \"@/components/craft-currency-input\";\n\nexport type CraftFormFieldOption = {\n label: React.ReactNode;\n value: string;\n disabled?: boolean;\n};\n\nexport type CraftFormFieldType =\n | \"text\"\n | \"number\"\n | \"password\"\n | \"textarea\"\n | \"select\"\n | \"checkbox\"\n | \"slider\"\n | \"date\"\n | \"color\"\n | \"email\"\n | \"tel\"\n | \"url\"\n | \"time\"\n | \"datetime-local\"\n | \"month\"\n | \"week\"\n | \"file\"\n | \"multifile\"\n | \"radio\"\n | \"switch\"\n | \"range\"\n | \"search\"\n | \"hidden\"\n | \"multiselect\"\n | \"currency\";\n\nexport type CraftFormFieldProps<TValues extends FieldValues = FieldValues> = {\n name: Path<TValues>;\n label?: React.ReactNode;\n description?: React.ReactNode;\n type?: CraftFormFieldType;\n options?: CraftFormFieldOption[];\n placeholder?: string;\n tone?: ThemeName;\n className?: string;\n inputClassName?: string;\n labelClassName?: string;\n descriptionClassName?: string;\n rules?: RegisterOptions<TValues>;\n disabled?: boolean;\n fieldProps?: Record<string, unknown>;\n};\n\nfunction getFieldError(errors: unknown, name: string) {\n if (!errors || typeof errors !== \"object\") return undefined;\n const segments = name.split(\".\");\n let current: unknown = errors;\n for (const segment of segments) {\n if (!current || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[segment];\n }\n return current;\n}\n\nconst baseInputClass =\n \"w-full rounded-2xl border-2 bg-[rgb(var(--nc-surface)/0.08)] text-[rgb(var(--nc-fg))] backdrop-blur-xl shadow-[inset_0_2px_8px_rgba(0,0,0,0.3)] focus:outline-none focus:ring-4 transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed border-[rgb(var(--nc-border)/0.35)] focus:border-[rgb(var(--nc-accent-1)/0.8)] focus:ring-[rgb(var(--nc-accent-1)/0.3)] px-5 py-3 text-base placeholder:text-[rgb(var(--nc-fg-soft))]\";\n\nexport function CraftFormField<TValues extends FieldValues = FieldValues>({\n name,\n label,\n description,\n type = \"text\",\n options = [],\n placeholder,\n tone,\n className,\n inputClassName,\n labelClassName,\n descriptionClassName,\n rules,\n disabled,\n fieldProps,\n}: CraftFormFieldProps<TValues>) {\n const { register, control, formState } = useFormContext<TValues>();\n const error = getFieldError(formState.errors, name);\n const errorMessage =\n typeof (error as { message?: unknown })?.message === \"string\"\n ? (error as { message: string }).message\n : undefined;\n\n if (type === \"hidden\") {\n return <input type=\"hidden\" {...register(name, rules)} />;\n }\n\n const labelNode = label ? (\n <label\n htmlFor={name}\n className={cn(\n \"text-sm font-semibold text-[rgb(var(--nc-fg))]\",\n labelClassName\n )}\n >\n {label}\n </label>\n ) : null;\n\n const descriptionNode = description ? (\n <p\n className={cn(\n \"text-xs text-[rgb(var(--nc-fg-muted))]\",\n descriptionClassName\n )}\n >\n {description}\n </p>\n ) : null;\n\n const errorNode = errorMessage ? (\n <p className=\"text-xs text-[rgb(var(--nc-accent-3))]\">{errorMessage}</p>\n ) : null;\n\n const renderInput = () => {\n if (type === \"textarea\") {\n return (\n <CraftTextarea\n id={name}\n placeholder={placeholder}\n tone={tone}\n className={inputClassName}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n if (type === \"select\" || type === \"multiselect\") {\n return (\n <CraftSelect\n id={name}\n tone={tone}\n className={inputClassName}\n multiple={type === \"multiselect\"}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n >\n {placeholder && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {options.map((option) => (\n <option\n key={option.value}\n value={option.value}\n disabled={option.disabled}\n >\n {option.label}\n </option>\n ))}\n </CraftSelect>\n );\n }\n\n if (type === \"checkbox\") {\n return (\n <CraftCheckbox\n tone={tone}\n label={label}\n description={description}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n if (type === \"switch\") {\n return (\n <CraftSwitch\n tone={tone}\n label={label}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n if (type === \"date\") {\n return (\n <Controller\n control={control}\n name={name}\n rules={rules}\n render={({ field }) => (\n <CraftDatePicker\n value={field.value ?? \"\"}\n onChange={field.onChange}\n tone={tone}\n placeholder={placeholder}\n {...(fieldProps as Record<string, unknown>)}\n />\n )}\n />\n );\n }\n\n if (type === \"number\") {\n return (\n <CraftNumberInput\n id={name}\n tone={tone}\n placeholder={placeholder}\n className={inputClassName}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n if (type === \"currency\") {\n return (\n <CraftCurrencyInput\n id={name}\n tone={tone}\n placeholder={placeholder}\n className={inputClassName}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n if (type === \"radio\") {\n return (\n <div className=\"grid gap-3\">\n {options.map((option) => (\n <label\n key={option.value}\n className={cn(\n \"flex items-center gap-3 rounded-2xl border border-[rgb(var(--nc-border)/0.35)] bg-[rgb(var(--nc-surface)/0.08)] px-4 py-3 text-sm text-[rgb(var(--nc-fg))]\",\n \"transition-all duration-200\",\n \"focus-within:ring-2 focus-within:ring-[rgb(var(--nc-accent-1)/0.5)]\",\n option.disabled ? \"opacity-60\" : \"cursor-pointer\"\n )}\n data-nc-theme={tone}\n >\n <input\n type=\"radio\"\n value={option.value}\n disabled={option.disabled || disabled}\n className=\"h-4 w-4 accent-[rgb(var(--nc-accent-1))]\"\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n <span>{option.label}</span>\n </label>\n ))}\n </div>\n );\n }\n\n if (type === \"range\" || type === \"slider\") {\n return (\n <input\n id={name}\n type=\"range\"\n className={cn(\n \"w-full accent-[rgb(var(--nc-accent-1))]\",\n inputClassName\n )}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n if (type === \"file\" || type === \"multifile\") {\n return (\n <input\n id={name}\n type=\"file\"\n multiple={type === \"multifile\"}\n className={cn(\n baseInputClass,\n \"file:mr-4 file:rounded-xl file:border-0 file:bg-[rgb(var(--nc-surface)/0.35)] file:px-4 file:py-2 file:text-sm file:font-semibold file:text-[rgb(var(--nc-fg))]\",\n inputClassName\n )}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n }\n\n const inputType =\n type === \"search\" ||\n type === \"password\" ||\n type === \"email\" ||\n type === \"tel\" ||\n type === \"url\" ||\n type === \"time\" ||\n type === \"datetime-local\" ||\n type === \"month\" ||\n type === \"week\" ||\n type === \"color\"\n ? type\n : \"text\";\n\n return (\n <CraftInput\n id={name}\n type={inputType}\n placeholder={placeholder}\n tone={tone}\n className={inputClassName}\n disabled={disabled}\n {...(fieldProps as Record<string, unknown>)}\n {...register(name, rules)}\n />\n );\n };\n\n const showLabel = type !== \"checkbox\" && type !== \"switch\";\n const showDescriptionAbove = type !== \"checkbox\" && type !== \"switch\";\n const showDescriptionBelow = type === \"switch\";\n\n return (\n <div className={cn(\"space-y-2\", className)} data-nc-theme={tone}>\n {showLabel ? labelNode : null}\n {showDescriptionAbove ? descriptionNode : null}\n {renderInput()}\n {showDescriptionBelow ? descriptionNode : null}\n {errorNode}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8GW;AA3GX,6BAMO;AAEP,gBAAmB;AAEnB,yBAA2B;AAC3B,4BAA8B;AAC9B,0BAA4B;AAC5B,4BAA8B;AAC9B,0BAA4B;AAC5B,+BAAgC;AAChC,gCAAiC;AACjC,kCAAmC;AAoDnC,SAAS,cAAc,QAAiB,MAAc;AACpD,MAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;AAClD,QAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,MAAI,UAAmB;AACvB,aAAW,WAAW,UAAU;AAC9B,QAAI,CAAC,WAAW,OAAO,YAAY,SAAU,QAAO;AACpD,cAAW,QAAoC,OAAO;AAAA,EACxD;AACA,SAAO;AACT;AAEA,M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