config-driven-form 1.1.1 → 1.2.0

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/dist/index.mjs CHANGED
@@ -1,20 +1,30 @@
1
1
  import { useForm, FormProvider, useFormContext } from 'react-hook-form';
2
2
  import { ajvResolver } from '@hookform/resolvers/ajv';
3
- import { EyeOff, Eye, AlertCircle, Bold, Italic, Heading2, List, ListOrdered } from 'lucide-react';
3
+ import { createContext, useState, useEffect, useContext } from 'react';
4
4
  import { jsx, jsxs } from 'react/jsx-runtime';
5
- import { useState, useEffect } from 'react';
5
+ import { EyeOff, Eye, AlertCircle, Bold, Italic, Heading2, List, ListOrdered } from 'lucide-react';
6
6
  import { useEditor, EditorContent } from '@tiptap/react';
7
7
  import StarterKit from '@tiptap/starter-kit';
8
8
 
9
9
  // src/components/SchemaForm.tsx
10
- var TextField = ({ name, schema, isRequired }) => {
10
+ var ClassNamesContext = createContext({});
11
+ var ClassNamesProvider = ({ value = {}, children }) => {
12
+ return /* @__PURE__ */ jsx(ClassNamesContext.Provider, { value, children });
13
+ };
14
+ var useClassNames = () => useContext(ClassNamesContext);
15
+ var cx = (...classes) => {
16
+ return classes.filter(Boolean).join(" ").trim();
17
+ };
18
+ var TextField = ({ name, schema, uiSchema, isRequired }) => {
19
+ const globalClasses = useClassNames();
20
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
11
21
  const {
12
22
  register,
13
23
  formState: { errors }
14
24
  } = useFormContext();
15
25
  const error = errors[name];
16
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
17
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", htmlFor: name, children: [
26
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
27
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), htmlFor: name, children: [
18
28
  schema.title || name,
19
29
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
20
30
  ] }),
@@ -23,26 +33,40 @@ var TextField = ({ name, schema, isRequired }) => {
23
33
  {
24
34
  id: name,
25
35
  type: schema.format === "email" ? "email" : "text",
26
- className: `cdf-input ${error ? "cdf-input--error" : ""}`,
36
+ className: cx(
37
+ "cdf-input",
38
+ globalClasses.input,
39
+ localClasses.input,
40
+ error && "cdf-input--error",
41
+ error && globalClasses.inputError,
42
+ error && localClasses.inputError
43
+ ),
27
44
  placeholder: `Enter ${schema.title || name}`,
28
45
  ...register(name)
29
46
  }
30
47
  ) }),
31
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
48
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
32
49
  /* @__PURE__ */ jsx(AlertCircle, { size: 14 }),
33
50
  error.message
34
51
  ] })
35
52
  ] });
36
53
  };
37
- var PasswordField = ({ name, schema, isRequired }) => {
54
+ var PasswordField = ({
55
+ name,
56
+ schema,
57
+ uiSchema,
58
+ isRequired
59
+ }) => {
60
+ const globalClasses = useClassNames();
61
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
38
62
  const {
39
63
  register,
40
64
  formState: { errors }
41
65
  } = useFormContext();
42
66
  const [showPassword, setShowPassword] = useState(false);
43
67
  const error = errors[name];
44
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
45
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", htmlFor: name, children: [
68
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
69
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), htmlFor: name, children: [
46
70
  schema.title || name,
47
71
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
48
72
  ] }),
@@ -52,7 +76,14 @@ var PasswordField = ({ name, schema, isRequired }) => {
52
76
  {
53
77
  id: name,
54
78
  type: showPassword ? "text" : "password",
55
- className: `cdf-input ${error ? "cdf-input--error" : ""}`,
79
+ className: cx(
80
+ "cdf-input",
81
+ globalClasses.input,
82
+ localClasses.input,
83
+ error && "cdf-input--error",
84
+ error && globalClasses.inputError,
85
+ error && localClasses.inputError
86
+ ),
56
87
  style: { paddingRight: "2.5rem" },
57
88
  placeholder: `Enter ${schema.title || name}`,
58
89
  ...register(name)
@@ -69,20 +100,22 @@ var PasswordField = ({ name, schema, isRequired }) => {
69
100
  }
70
101
  )
71
102
  ] }),
72
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
103
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
73
104
  /* @__PURE__ */ jsx(AlertCircle, { size: 14 }),
74
105
  error.message
75
106
  ] })
76
107
  ] });
77
108
  };
78
- var NumberField = ({ name, schema, isRequired }) => {
109
+ var NumberField = ({ name, schema, uiSchema, isRequired }) => {
110
+ const globalClasses = useClassNames();
111
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
79
112
  const {
80
113
  register,
81
114
  formState: { errors }
82
115
  } = useFormContext();
83
116
  const error = errors[name];
84
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
85
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", htmlFor: name, children: [
117
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
118
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), htmlFor: name, children: [
86
119
  schema.title || name,
87
120
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
88
121
  ] }),
@@ -91,20 +124,34 @@ var NumberField = ({ name, schema, isRequired }) => {
91
124
  {
92
125
  id: name,
93
126
  type: "number",
94
- className: `cdf-input ${error ? "cdf-input--error" : ""}`,
127
+ className: cx(
128
+ "cdf-input",
129
+ globalClasses.input,
130
+ localClasses.input,
131
+ error && "cdf-input--error",
132
+ error && globalClasses.inputError,
133
+ error && localClasses.inputError
134
+ ),
95
135
  placeholder: `Enter ${schema.title || name}`,
96
136
  ...register(name, {
97
137
  valueAsNumber: true
98
138
  })
99
139
  }
100
140
  ) }),
101
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
141
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
102
142
  /* @__PURE__ */ jsx(AlertCircle, { size: 14 }),
103
143
  error.message
104
144
  ] })
105
145
  ] });
106
146
  };
107
- var RichTextField = ({ name, schema, isRequired }) => {
147
+ var RichTextField = ({
148
+ name,
149
+ schema,
150
+ uiSchema,
151
+ isRequired
152
+ }) => {
153
+ const globalClasses = useClassNames();
154
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
108
155
  const {
109
156
  setValue,
110
157
  watch,
@@ -124,76 +171,89 @@ var RichTextField = ({ name, schema, isRequired }) => {
124
171
  editor.commands.setContent(value || "");
125
172
  }
126
173
  }, [value, editor]);
127
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
128
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", htmlFor: name, children: [
174
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
175
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), htmlFor: name, children: [
129
176
  schema.title || name,
130
177
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
131
178
  ] }),
132
- /* @__PURE__ */ jsxs("div", { className: `cdf-rich-text-wrapper ${error ? "cdf-input--error" : ""}`, children: [
133
- /* @__PURE__ */ jsxs("div", { className: "cdf-rich-text-toolbar", children: [
134
- /* @__PURE__ */ jsx(
135
- "button",
136
- {
137
- type: "button",
138
- onClick: () => editor == null ? void 0 : editor.chain().focus().toggleBold().run(),
139
- className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("bold")) ? "is-active" : ""}`,
140
- children: /* @__PURE__ */ jsx(Bold, { size: 16 })
141
- }
142
- ),
143
- /* @__PURE__ */ jsx(
144
- "button",
145
- {
146
- type: "button",
147
- onClick: () => editor == null ? void 0 : editor.chain().focus().toggleItalic().run(),
148
- className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("italic")) ? "is-active" : ""}`,
149
- children: /* @__PURE__ */ jsx(Italic, { size: 16 })
150
- }
151
- ),
152
- /* @__PURE__ */ jsx(
153
- "button",
154
- {
155
- type: "button",
156
- onClick: () => editor == null ? void 0 : editor.chain().focus().toggleHeading({ level: 2 }).run(),
157
- className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("heading", { level: 2 })) ? "is-active" : ""}`,
158
- children: /* @__PURE__ */ jsx(Heading2, { size: 16 })
159
- }
160
- ),
161
- /* @__PURE__ */ jsx(
162
- "button",
163
- {
164
- type: "button",
165
- onClick: () => editor == null ? void 0 : editor.chain().focus().toggleBulletList().run(),
166
- className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("bulletList")) ? "is-active" : ""}`,
167
- children: /* @__PURE__ */ jsx(List, { size: 16 })
168
- }
179
+ /* @__PURE__ */ jsxs(
180
+ "div",
181
+ {
182
+ className: cx(
183
+ "cdf-rich-text-wrapper",
184
+ error && "cdf-input--error",
185
+ error && globalClasses.inputError,
186
+ error && localClasses.inputError
169
187
  ),
170
- /* @__PURE__ */ jsx(
171
- "button",
172
- {
173
- type: "button",
174
- onClick: () => editor == null ? void 0 : editor.chain().focus().toggleOrderedList().run(),
175
- className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("orderedList")) ? "is-active" : ""}`,
176
- children: /* @__PURE__ */ jsx(ListOrdered, { size: 16 })
177
- }
178
- )
179
- ] }),
180
- /* @__PURE__ */ jsx(EditorContent, { editor, className: "cdf-rich-text-content" })
181
- ] }),
182
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
188
+ children: [
189
+ /* @__PURE__ */ jsxs("div", { className: "cdf-rich-text-toolbar", children: [
190
+ /* @__PURE__ */ jsx(
191
+ "button",
192
+ {
193
+ type: "button",
194
+ onClick: () => editor == null ? void 0 : editor.chain().focus().toggleBold().run(),
195
+ className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("bold")) ? "is-active" : ""}`,
196
+ children: /* @__PURE__ */ jsx(Bold, { size: 16 })
197
+ }
198
+ ),
199
+ /* @__PURE__ */ jsx(
200
+ "button",
201
+ {
202
+ type: "button",
203
+ onClick: () => editor == null ? void 0 : editor.chain().focus().toggleItalic().run(),
204
+ className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("italic")) ? "is-active" : ""}`,
205
+ children: /* @__PURE__ */ jsx(Italic, { size: 16 })
206
+ }
207
+ ),
208
+ /* @__PURE__ */ jsx(
209
+ "button",
210
+ {
211
+ type: "button",
212
+ onClick: () => editor == null ? void 0 : editor.chain().focus().toggleHeading({ level: 2 }).run(),
213
+ className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("heading", { level: 2 })) ? "is-active" : ""}`,
214
+ children: /* @__PURE__ */ jsx(Heading2, { size: 16 })
215
+ }
216
+ ),
217
+ /* @__PURE__ */ jsx(
218
+ "button",
219
+ {
220
+ type: "button",
221
+ onClick: () => editor == null ? void 0 : editor.chain().focus().toggleBulletList().run(),
222
+ className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("bulletList")) ? "is-active" : ""}`,
223
+ children: /* @__PURE__ */ jsx(List, { size: 16 })
224
+ }
225
+ ),
226
+ /* @__PURE__ */ jsx(
227
+ "button",
228
+ {
229
+ type: "button",
230
+ onClick: () => editor == null ? void 0 : editor.chain().focus().toggleOrderedList().run(),
231
+ className: `cdf-toolbar-btn ${(editor == null ? void 0 : editor.isActive("orderedList")) ? "is-active" : ""}`,
232
+ children: /* @__PURE__ */ jsx(ListOrdered, { size: 16 })
233
+ }
234
+ )
235
+ ] }),
236
+ /* @__PURE__ */ jsx(EditorContent, { editor, className: "cdf-rich-text-content" })
237
+ ]
238
+ }
239
+ ),
240
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
183
241
  /* @__PURE__ */ jsx(AlertCircle, { size: 14 }),
184
242
  error.message
185
243
  ] })
186
244
  ] });
187
245
  };
188
- var SelectField = ({ name, schema, isRequired }) => {
246
+ var SelectField = ({ name, schema, uiSchema, isRequired }) => {
189
247
  var _a;
248
+ const globalClasses = useClassNames();
249
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
190
250
  const {
191
251
  register,
192
252
  formState: { errors }
193
253
  } = useFormContext();
194
254
  const error = errors[name];
195
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
196
- /* @__PURE__ */ jsxs("label", { htmlFor: name, className: "cdf-label", children: [
255
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
256
+ /* @__PURE__ */ jsxs("label", { htmlFor: name, className: cx("cdf-label", globalClasses.label, localClasses.label), children: [
197
257
  schema.title || name,
198
258
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
199
259
  ] }),
@@ -202,14 +262,22 @@ var SelectField = ({ name, schema, isRequired }) => {
202
262
  {
203
263
  id: name,
204
264
  ...register(name),
205
- className: `cdf-input cdf-select ${error ? "cdf-input--error" : ""}`,
265
+ className: cx(
266
+ "cdf-input",
267
+ "cdf-select",
268
+ globalClasses.input,
269
+ localClasses.input,
270
+ error && "cdf-input--error",
271
+ error && globalClasses.inputError,
272
+ error && localClasses.inputError
273
+ ),
206
274
  children: [
207
275
  /* @__PURE__ */ jsx("option", { value: "", children: "Select an option..." }),
208
276
  (_a = schema.enum) == null ? void 0 : _a.map((option) => /* @__PURE__ */ jsx("option", { value: option, children: option }, option))
209
277
  ]
210
278
  }
211
279
  ) }),
212
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
280
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
213
281
  /* @__PURE__ */ jsxs(
214
282
  "svg",
215
283
  {
@@ -230,23 +298,40 @@ var SelectField = ({ name, schema, isRequired }) => {
230
298
  ] })
231
299
  ] });
232
300
  };
233
- var RadioField = ({ name, schema, isRequired }) => {
301
+ var RadioField = ({ name, schema, uiSchema, isRequired }) => {
234
302
  var _a;
303
+ const globalClasses = useClassNames();
304
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
235
305
  const {
236
306
  register,
237
307
  formState: { errors }
238
308
  } = useFormContext();
239
309
  const error = errors[name];
240
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
241
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", children: [
310
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
311
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), children: [
242
312
  schema.title || name,
243
313
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
244
314
  ] }),
245
- /* @__PURE__ */ jsx("div", { className: "cdf-radio-group", children: (_a = schema.enum) == null ? void 0 : _a.map((option) => /* @__PURE__ */ jsxs("label", { className: "cdf-radio-label", children: [
246
- /* @__PURE__ */ jsx("input", { type: "radio", value: option, ...register(name), className: "cdf-radio-input" }),
315
+ /* @__PURE__ */ jsx("div", { className: cx("cdf-radio-group", globalClasses.radioGroup, localClasses.radioGroup), children: (_a = schema.enum) == null ? void 0 : _a.map((option) => /* @__PURE__ */ jsxs(
316
+ "label",
317
+ {
318
+ className: cx("cdf-radio-label", globalClasses.radioLabel, localClasses.radioLabel),
319
+ children: [
320
+ /* @__PURE__ */ jsx(
321
+ "input",
322
+ {
323
+ type: "radio",
324
+ value: option,
325
+ ...register(name),
326
+ className: cx("cdf-radio-input", globalClasses.radioInput, localClasses.radioInput)
327
+ }
328
+ ),
329
+ option
330
+ ]
331
+ },
247
332
  option
248
- ] }, option)) }),
249
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
333
+ )) }),
334
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
250
335
  /* @__PURE__ */ jsxs(
251
336
  "svg",
252
337
  {
@@ -267,20 +352,58 @@ var RadioField = ({ name, schema, isRequired }) => {
267
352
  ] })
268
353
  ] });
269
354
  };
270
- var CheckboxField = ({ name, schema, isRequired }) => {
355
+ var CheckboxField = ({
356
+ name,
357
+ schema,
358
+ uiSchema,
359
+ isRequired
360
+ }) => {
361
+ const globalClasses = useClassNames();
362
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
271
363
  const {
272
364
  register,
273
365
  formState: { errors }
274
366
  } = useFormContext();
275
367
  const error = errors[name];
276
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
277
- /* @__PURE__ */ jsx("div", { className: "cdf-checkbox-group", children: /* @__PURE__ */ jsxs("label", { className: "cdf-checkbox-label", children: [
278
- /* @__PURE__ */ jsx("input", { type: "checkbox", ...register(name), className: "cdf-checkbox-input" }),
279
- schema.title || name,
280
- isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
281
- ] }) }),
368
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
369
+ /* @__PURE__ */ jsx(
370
+ "div",
371
+ {
372
+ className: cx(
373
+ "cdf-checkbox-group",
374
+ globalClasses.checkboxGroup,
375
+ localClasses.checkboxGroup
376
+ ),
377
+ children: /* @__PURE__ */ jsxs(
378
+ "label",
379
+ {
380
+ className: cx(
381
+ "cdf-checkbox-label",
382
+ globalClasses.checkboxLabel,
383
+ localClasses.checkboxLabel
384
+ ),
385
+ children: [
386
+ /* @__PURE__ */ jsx(
387
+ "input",
388
+ {
389
+ type: "checkbox",
390
+ ...register(name),
391
+ className: cx(
392
+ "cdf-checkbox-input",
393
+ globalClasses.checkboxInput,
394
+ localClasses.checkboxInput
395
+ )
396
+ }
397
+ ),
398
+ schema.title || name,
399
+ isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
400
+ ]
401
+ }
402
+ )
403
+ }
404
+ ),
282
405
  schema.description && /* @__PURE__ */ jsx("p", { style: { fontSize: "0.875rem", color: "var(--cdf-text-muted)", marginTop: "0.25rem" }, children: schema.description }),
283
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
406
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
284
407
  /* @__PURE__ */ jsxs(
285
408
  "svg",
286
409
  {
@@ -304,8 +427,11 @@ var CheckboxField = ({ name, schema, isRequired }) => {
304
427
  var CheckboxGroupField = ({
305
428
  name,
306
429
  schema,
430
+ uiSchema,
307
431
  isRequired
308
432
  }) => {
433
+ const globalClasses = useClassNames();
434
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
309
435
  const {
310
436
  register,
311
437
  formState: { errors }
@@ -315,24 +441,49 @@ var CheckboxGroupField = ({
315
441
  if (schema.items && !Array.isArray(schema.items) && schema.items.enum) {
316
442
  options = schema.items.enum;
317
443
  }
318
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
319
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", children: [
444
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
445
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), children: [
320
446
  schema.title || name,
321
447
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
322
448
  ] }),
323
- /* @__PURE__ */ jsx("div", { className: "cdf-checkbox-group", children: options.map((option) => /* @__PURE__ */ jsxs("label", { className: "cdf-checkbox-label", children: [
324
- /* @__PURE__ */ jsx(
325
- "input",
326
- {
327
- type: "checkbox",
328
- value: option,
329
- ...register(name),
330
- className: "cdf-checkbox-input"
331
- }
332
- ),
333
- option
334
- ] }, option)) }),
335
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
449
+ /* @__PURE__ */ jsx(
450
+ "div",
451
+ {
452
+ className: cx(
453
+ "cdf-checkbox-group",
454
+ globalClasses.checkboxGroup,
455
+ localClasses.checkboxGroup
456
+ ),
457
+ children: options.map((option) => /* @__PURE__ */ jsxs(
458
+ "label",
459
+ {
460
+ className: cx(
461
+ "cdf-checkbox-label",
462
+ globalClasses.checkboxLabel,
463
+ localClasses.checkboxLabel
464
+ ),
465
+ children: [
466
+ /* @__PURE__ */ jsx(
467
+ "input",
468
+ {
469
+ type: "checkbox",
470
+ value: option,
471
+ ...register(name),
472
+ className: cx(
473
+ "cdf-checkbox-input",
474
+ globalClasses.checkboxInput,
475
+ localClasses.checkboxInput
476
+ )
477
+ }
478
+ ),
479
+ option
480
+ ]
481
+ },
482
+ option
483
+ ))
484
+ }
485
+ ),
486
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
336
487
  /* @__PURE__ */ jsxs(
337
488
  "svg",
338
489
  {
@@ -353,7 +504,9 @@ var CheckboxGroupField = ({
353
504
  ] })
354
505
  ] });
355
506
  };
356
- var FileField = ({ name, schema, isRequired }) => {
507
+ var FileField = ({ name, schema, uiSchema, isRequired }) => {
508
+ const globalClasses = useClassNames();
509
+ const localClasses = (uiSchema == null ? void 0 : uiSchema["ui:classNames"]) || {};
357
510
  const {
358
511
  setValue,
359
512
  formState: { errors }
@@ -376,23 +529,36 @@ var FileField = ({ name, schema, isRequired }) => {
376
529
  };
377
530
  reader.readAsDataURL(file);
378
531
  };
379
- return /* @__PURE__ */ jsxs("div", { className: "cdf-field-group", children: [
380
- /* @__PURE__ */ jsxs("label", { className: "cdf-label", children: [
532
+ return /* @__PURE__ */ jsxs("div", { className: cx("cdf-field-group", globalClasses.fieldGroup, localClasses.fieldGroup), children: [
533
+ /* @__PURE__ */ jsxs("label", { className: cx("cdf-label", globalClasses.label, localClasses.label), children: [
381
534
  schema.title || name,
382
535
  isRequired && /* @__PURE__ */ jsx("span", { className: "cdf-required-mark", children: "*" })
383
536
  ] }),
384
- /* @__PURE__ */ jsxs("div", { className: `cdf-file-wrapper ${error ? "cdf-input--error" : ""}`, children: [
385
- /* @__PURE__ */ jsx("input", { type: "file", className: "cdf-file-input", onChange: handleFileChange }),
386
- /* @__PURE__ */ jsxs("div", { className: "cdf-file-text", children: [
387
- /* @__PURE__ */ jsx("span", { children: "Click to upload" }),
388
- " or drag and drop"
389
- ] }),
390
- fileName && /* @__PURE__ */ jsxs("div", { className: "cdf-file-preview", children: [
391
- "Selected: ",
392
- /* @__PURE__ */ jsx("strong", { children: fileName })
393
- ] })
394
- ] }),
395
- error && /* @__PURE__ */ jsxs("span", { className: "cdf-error-message", children: [
537
+ /* @__PURE__ */ jsxs(
538
+ "div",
539
+ {
540
+ className: cx(
541
+ "cdf-file-wrapper",
542
+ globalClasses.fileWrapper,
543
+ localClasses.fileWrapper,
544
+ error && "cdf-input--error",
545
+ error && globalClasses.inputError,
546
+ error && localClasses.inputError
547
+ ),
548
+ children: [
549
+ /* @__PURE__ */ jsx("input", { type: "file", className: "cdf-file-input", onChange: handleFileChange }),
550
+ /* @__PURE__ */ jsxs("div", { className: cx("cdf-file-text", globalClasses.fileText, localClasses.fileText), children: [
551
+ /* @__PURE__ */ jsx("span", { children: "Click to upload" }),
552
+ " or drag and drop"
553
+ ] }),
554
+ fileName && /* @__PURE__ */ jsxs("div", { className: "cdf-file-preview", children: [
555
+ "Selected: ",
556
+ /* @__PURE__ */ jsx("strong", { children: fileName })
557
+ ] })
558
+ ]
559
+ }
560
+ ),
561
+ error && /* @__PURE__ */ jsxs("span", { className: cx("cdf-error-message", globalClasses.errorText, localClasses.errorText), children: [
396
562
  /* @__PURE__ */ jsxs(
397
563
  "svg",
398
564
  {
@@ -423,31 +589,39 @@ var FieldRenderer = ({
423
589
  const widget = uiSchema == null ? void 0 : uiSchema["ui:widget"];
424
590
  const renderField = () => {
425
591
  if (schema.type === "array") {
426
- return /* @__PURE__ */ jsx(CheckboxGroupField, { name, schema, isRequired });
592
+ return /* @__PURE__ */ jsx(
593
+ CheckboxGroupField,
594
+ {
595
+ name,
596
+ schema,
597
+ uiSchema,
598
+ isRequired
599
+ }
600
+ );
427
601
  }
428
602
  if (schema.type === "boolean") {
429
- return /* @__PURE__ */ jsx(CheckboxField, { name, schema, isRequired });
603
+ return /* @__PURE__ */ jsx(CheckboxField, { name, schema, uiSchema, isRequired });
430
604
  }
431
605
  if (schema.enum) {
432
606
  if (widget === "radio") {
433
- return /* @__PURE__ */ jsx(RadioField, { name, schema, isRequired });
607
+ return /* @__PURE__ */ jsx(RadioField, { name, schema, uiSchema, isRequired });
434
608
  }
435
- return /* @__PURE__ */ jsx(SelectField, { name, schema, isRequired });
609
+ return /* @__PURE__ */ jsx(SelectField, { name, schema, uiSchema, isRequired });
436
610
  }
437
611
  if (schema.type === "string") {
438
612
  if (schema.format === "data-url") {
439
- return /* @__PURE__ */ jsx(FileField, { name, schema, isRequired });
613
+ return /* @__PURE__ */ jsx(FileField, { name, schema, uiSchema, isRequired });
440
614
  }
441
615
  if (schema.format === "password") {
442
- return /* @__PURE__ */ jsx(PasswordField, { name, schema, isRequired });
616
+ return /* @__PURE__ */ jsx(PasswordField, { name, schema, uiSchema, isRequired });
443
617
  }
444
618
  if (schema.format === "rich-text") {
445
- return /* @__PURE__ */ jsx(RichTextField, { name, schema, isRequired });
619
+ return /* @__PURE__ */ jsx(RichTextField, { name, schema, uiSchema, isRequired });
446
620
  }
447
- return /* @__PURE__ */ jsx(TextField, { name, schema, isRequired });
621
+ return /* @__PURE__ */ jsx(TextField, { name, schema, uiSchema, isRequired });
448
622
  }
449
623
  if (schema.type === "number" || schema.type === "integer") {
450
- return /* @__PURE__ */ jsx(NumberField, { name, schema, isRequired });
624
+ return /* @__PURE__ */ jsx(NumberField, { name, schema, uiSchema, isRequired });
451
625
  }
452
626
  return /* @__PURE__ */ jsx("div", { className: "cdf-field-group", children: /* @__PURE__ */ jsxs("p", { className: "cdf-error-message", children: [
453
627
  "Unsupported field type: ",
@@ -462,7 +636,8 @@ var SchemaForm = ({
462
636
  onSubmit,
463
637
  defaultValues,
464
638
  columns = 1,
465
- theme
639
+ theme,
640
+ classNames = {}
466
641
  }) => {
467
642
  const methods = useForm({
468
643
  resolver: ajvResolver(schema, {
@@ -486,10 +661,17 @@ var SchemaForm = ({
486
661
  "--cdf-surface": theme.surface,
487
662
  "--cdf-border": theme.border
488
663
  } : {};
489
- return /* @__PURE__ */ jsxs("div", { className: "cdf-form-container", style: themeStyles, children: [
490
- schema.title && /* @__PURE__ */ jsx("h2", { className: "cdf-form-title", children: schema.title }),
491
- schema.description && /* @__PURE__ */ jsx("p", { style: { color: "var(--cdf-text-muted)", marginBottom: "1.5rem" }, children: schema.description }),
492
- /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs("form", { onSubmit: methods.handleSubmit(onSubmit), noValidate: true, children: [
664
+ return /* @__PURE__ */ jsx(ClassNamesProvider, { value: classNames, children: /* @__PURE__ */ jsxs("div", { className: cx("cdf-form-container", classNames.container), style: themeStyles, children: [
665
+ schema.title && /* @__PURE__ */ jsx("h2", { className: cx("cdf-form-title", classNames.title), children: schema.title }),
666
+ schema.description && /* @__PURE__ */ jsx(
667
+ "p",
668
+ {
669
+ className: classNames.description,
670
+ style: { color: "var(--cdf-text-muted)", marginBottom: "1.5rem" },
671
+ children: schema.description
672
+ }
673
+ ),
674
+ /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs("form", { className: classNames.form, onSubmit: methods.handleSubmit(onSubmit), noValidate: true, children: [
493
675
  /* @__PURE__ */ jsx("div", { className: `cdf-form-grid-${columns}`, children: Object.entries(schema.properties).map(([key, propSchema]) => {
494
676
  var _a;
495
677
  return /* @__PURE__ */ jsx(
@@ -503,9 +685,9 @@ var SchemaForm = ({
503
685
  key
504
686
  );
505
687
  }) }),
506
- /* @__PURE__ */ jsx("button", { type: "submit", className: "cdf-submit-btn", children: "Submit" })
688
+ /* @__PURE__ */ jsx("button", { type: "submit", className: cx("cdf-submit-btn", classNames.submitButton), children: "Submit" })
507
689
  ] }) })
508
- ] });
690
+ ] }) });
509
691
  };
510
692
 
511
693
  export { FieldRenderer, SchemaForm };