react-smart-fields 2.1.0 → 2.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.cjs +66 -65
- package/dist/index.js +66 -65
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -113,82 +113,82 @@ var buildInitialValues = (fields, defaultValues, controlledValues) => {
|
|
|
113
113
|
};
|
|
114
114
|
var baseTheme = {
|
|
115
115
|
default: {
|
|
116
|
-
wrapper: "w-full max-w-2xl mx-auto p-6 bg-white dark:bg-
|
|
117
|
-
title: "text-2xl font-semibold tracking-tight text-
|
|
118
|
-
description: "text-sm text-
|
|
119
|
-
fieldsContainer: "space-y-
|
|
120
|
-
field: "w-full",
|
|
121
|
-
label: "
|
|
122
|
-
help: "text-
|
|
123
|
-
control: "w-full rounded-
|
|
124
|
-
textarea: "w-full rounded-
|
|
125
|
-
select: "w-full rounded-
|
|
126
|
-
option: "text-
|
|
127
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
128
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
129
|
-
error: "text-
|
|
116
|
+
wrapper: "w-full max-w-2xl mx-auto p-6 bg-white dark:bg-zinc-950 rounded-lg border border-zinc-200 dark:border-zinc-800 shadow-sm",
|
|
117
|
+
title: "text-2xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
118
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
119
|
+
fieldsContainer: "space-y-4",
|
|
120
|
+
field: "w-full space-y-2",
|
|
121
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
122
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
123
|
+
control: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
124
|
+
textarea: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 transition-colors min-h-[80px] resize-none",
|
|
125
|
+
select: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
126
|
+
option: "text-zinc-950 dark:text-zinc-50 bg-white dark:bg-zinc-950",
|
|
127
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-900 dark:border-zinc-50 bg-white dark:bg-zinc-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50",
|
|
128
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-900 dark:border-zinc-50 bg-white dark:bg-zinc-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50",
|
|
129
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
130
130
|
},
|
|
131
131
|
minimal: {
|
|
132
132
|
wrapper: "w-full max-w-2xl mx-auto",
|
|
133
|
-
title: "text-xl font-semibold text-
|
|
134
|
-
description: "text-sm text-
|
|
135
|
-
fieldsContainer: "space-y-
|
|
136
|
-
field: "w-full",
|
|
137
|
-
label: "text-sm font-medium text-
|
|
138
|
-
help: "text-
|
|
139
|
-
control: "w-full rounded-md border border-
|
|
140
|
-
textarea: "w-full rounded-md border border-
|
|
141
|
-
select: "w-full rounded-md border border-
|
|
142
|
-
option: "text-
|
|
143
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
144
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
145
|
-
error: "text-
|
|
133
|
+
title: "text-xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
134
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
135
|
+
fieldsContainer: "space-y-4",
|
|
136
|
+
field: "w-full space-y-2",
|
|
137
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
138
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
139
|
+
control: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
140
|
+
textarea: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors min-h-[80px] resize-none",
|
|
141
|
+
select: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-transparent text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
142
|
+
option: "text-zinc-950 dark:text-zinc-50",
|
|
143
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-200 dark:border-zinc-800 bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
144
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-200 dark:border-zinc-800 bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
145
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
146
146
|
},
|
|
147
147
|
filled: {
|
|
148
|
-
wrapper: "w-full max-w-2xl mx-auto p-6 bg-
|
|
149
|
-
title: "text-2xl font-semibold text-
|
|
150
|
-
description: "text-sm text-
|
|
151
|
-
fieldsContainer: "space-y-
|
|
152
|
-
field: "w-full",
|
|
153
|
-
label: "text-sm font-medium text-
|
|
154
|
-
help: "text-
|
|
155
|
-
control: "w-full rounded-
|
|
156
|
-
textarea: "w-full rounded-
|
|
157
|
-
select: "w-full rounded-
|
|
158
|
-
option: "text-
|
|
159
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
160
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
161
|
-
error: "text-
|
|
148
|
+
wrapper: "w-full max-w-2xl mx-auto p-6 bg-zinc-50 dark:bg-zinc-900 rounded-lg border border-zinc-100 dark:border-zinc-800",
|
|
149
|
+
title: "text-2xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
150
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
151
|
+
fieldsContainer: "space-y-4",
|
|
152
|
+
field: "w-full space-y-2",
|
|
153
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
154
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
155
|
+
control: "w-full rounded-md border border-zinc-100 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-800 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
156
|
+
textarea: "w-full rounded-md border border-zinc-100 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-800 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50 transition-colors min-h-[80px] resize-none",
|
|
157
|
+
select: "w-full rounded-md border border-zinc-100 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-800 text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
158
|
+
option: "text-zinc-950 dark:text-zinc-50 bg-white dark:bg-zinc-900",
|
|
159
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50",
|
|
160
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50",
|
|
161
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
162
162
|
},
|
|
163
163
|
underline: {
|
|
164
|
-
wrapper: "w-full max-w-2xl mx-auto
|
|
165
|
-
title: "text-xl font-semibold text-
|
|
166
|
-
description: "text-sm text-
|
|
164
|
+
wrapper: "w-full max-w-2xl mx-auto py-4",
|
|
165
|
+
title: "text-xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
166
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
167
167
|
fieldsContainer: "space-y-4",
|
|
168
|
-
field: "w-full",
|
|
169
|
-
label: "text-sm font-medium text-
|
|
170
|
-
help: "text-
|
|
171
|
-
control: "w-full border-0 border-b border-
|
|
172
|
-
textarea: "w-full border-0 border-b border-
|
|
173
|
-
select: "w-full border-0 border-b border-
|
|
174
|
-
option: "text-
|
|
175
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
176
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
177
|
-
error: "text-
|
|
168
|
+
field: "w-full space-y-2",
|
|
169
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
170
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
171
|
+
control: "w-full border-0 border-b border-zinc-200 dark:border-zinc-700 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 rounded-none focus-visible:outline-none focus-visible:ring-0 focus-visible:border-zinc-950 dark:focus-visible:border-zinc-300 disabled:cursor-not-allowed disabled:opacity-50 transition-colors px-0",
|
|
172
|
+
textarea: "w-full border-0 border-b border-zinc-200 dark:border-zinc-700 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 rounded-none focus-visible:outline-none focus-visible:ring-0 focus-visible:border-zinc-950 dark:focus-visible:border-zinc-300 disabled:cursor-not-allowed disabled:opacity-50 transition-colors px-0 min-h-[80px] resize-none",
|
|
173
|
+
select: "w-full border-0 border-b border-zinc-200 dark:border-zinc-700 bg-transparent text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-0 focus-visible:border-zinc-950 dark:focus-visible:border-zinc-300 disabled:cursor-not-allowed disabled:opacity-50 transition-colors rounded-none px-0",
|
|
174
|
+
option: "text-zinc-950 dark:text-zinc-50",
|
|
175
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-200 dark:border-zinc-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
176
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-200 dark:border-zinc-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
177
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
180
|
var sizeMap = {
|
|
181
181
|
sm: {
|
|
182
182
|
control: "px-3 py-1.5 text-xs",
|
|
183
183
|
label: "text-xs",
|
|
184
|
-
help: "text-[
|
|
184
|
+
help: "text-[0.7rem]",
|
|
185
185
|
error: "text-xs"
|
|
186
186
|
},
|
|
187
187
|
md: {
|
|
188
|
-
control: "px-3
|
|
188
|
+
control: "px-3 py-2 text-sm",
|
|
189
189
|
label: "text-sm",
|
|
190
|
-
help: "text-
|
|
191
|
-
error: "text-
|
|
190
|
+
help: "text-[0.8rem]",
|
|
191
|
+
error: "text-[0.8rem]"
|
|
192
192
|
},
|
|
193
193
|
lg: {
|
|
194
194
|
control: "px-4 py-2.5 text-base",
|
|
@@ -417,7 +417,7 @@ var DynamicFields = ({
|
|
|
417
417
|
error: cn(defaultUi.error, sizeClasses.error, errorClassName, field?.errorClassName, ui?.error, field?.ui?.error)
|
|
418
418
|
});
|
|
419
419
|
const buildStateClassName = (field, hasError, disabled, readOnly) => cn(
|
|
420
|
-
hasError && stateClassNames?.invalid,
|
|
420
|
+
hasError && (stateClassNames?.invalid ?? "border-red-500 dark:border-red-500 focus-visible:ring-red-500 dark:focus-visible:ring-red-500"),
|
|
421
421
|
disabled && stateClassNames?.disabled,
|
|
422
422
|
readOnly && stateClassNames?.readonly,
|
|
423
423
|
dirtyMap[field.name] && stateClassNames?.dirty,
|
|
@@ -434,7 +434,8 @@ var DynamicFields = ({
|
|
|
434
434
|
};
|
|
435
435
|
const renderDefaultControl = (context) => {
|
|
436
436
|
const { field, value: value2, options, isLoadingOptions, classes, handleChange, handleBlur, disabled, readOnly, error } = context;
|
|
437
|
-
const
|
|
437
|
+
const showsError = Boolean(error) && shouldShowError(field.name);
|
|
438
|
+
const controlStateClass = buildStateClassName(field, showsError, disabled, readOnly);
|
|
438
439
|
if (field.type === "textarea") {
|
|
439
440
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
440
441
|
"textarea",
|
|
@@ -482,7 +483,7 @@ var DynamicFields = ({
|
|
|
482
483
|
{
|
|
483
484
|
key: `${field.name}-${String(option.value)}`,
|
|
484
485
|
htmlFor: `${field.name}-${String(option.value)}`,
|
|
485
|
-
className: "flex items-center gap-2 cursor-pointer"
|
|
486
|
+
className: "flex items-center gap-2 cursor-pointer select-none"
|
|
486
487
|
},
|
|
487
488
|
/* @__PURE__ */ import_react.default.createElement(
|
|
488
489
|
"input",
|
|
@@ -499,7 +500,7 @@ var DynamicFields = ({
|
|
|
499
500
|
className: cn(classes.radio, controlStateClass)
|
|
500
501
|
}
|
|
501
502
|
),
|
|
502
|
-
/* @__PURE__ */ import_react.default.createElement("span", { className: "text-sm text-
|
|
503
|
+
/* @__PURE__ */ import_react.default.createElement("span", { className: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-70" }, option.label)
|
|
503
504
|
)));
|
|
504
505
|
}
|
|
505
506
|
if (field.type === "checkbox") {
|
|
@@ -541,7 +542,7 @@ var DynamicFields = ({
|
|
|
541
542
|
}
|
|
542
543
|
);
|
|
543
544
|
};
|
|
544
|
-
return /* @__PURE__ */ import_react.default.createElement("div", { className: resolveUi().wrapper }, title && /* @__PURE__ */ import_react.default.createElement("div", { className: "mb-
|
|
545
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: resolveUi().wrapper }, title && /* @__PURE__ */ import_react.default.createElement("div", { className: "flex flex-col space-y-1.5 pb-6 mb-6 border-b border-zinc-200 dark:border-zinc-800" }, /* @__PURE__ */ import_react.default.createElement("h2", { className: resolveUi().title }, title), description && /* @__PURE__ */ import_react.default.createElement("p", { className: resolveUi().description }, description)), /* @__PURE__ */ import_react.default.createElement("div", { className: resolveUi().fieldsContainer }, visibleFields.map((field) => {
|
|
545
546
|
const classes = resolveUi(field);
|
|
546
547
|
const storedValue = getIn(values, field.name);
|
|
547
548
|
const renderedValue = field.transformIn ? field.transformIn(storedValue, values) : storedValue;
|
|
@@ -569,7 +570,7 @@ var DynamicFields = ({
|
|
|
569
570
|
handleBlur: () => handleFieldBlur(field)
|
|
570
571
|
};
|
|
571
572
|
const requiredMark = field.required || field.requiredWhen?.(values);
|
|
572
|
-
const labelNode = field.type === "checkbox" ? null : renderLabel ? renderLabel(context) : field.label ? /* @__PURE__ */ import_react.default.createElement("label", { htmlFor: field.name, className: classes.label }, field.label, requiredMark && /* @__PURE__ */ import_react.default.createElement("span", { className: "text-red-500
|
|
573
|
+
const labelNode = field.type === "checkbox" ? null : renderLabel ? renderLabel(context) : field.label ? /* @__PURE__ */ import_react.default.createElement("label", { htmlFor: field.name, className: classes.label }, field.label, requiredMark && /* @__PURE__ */ import_react.default.createElement("span", { className: "text-red-500 ml-1" }, "*")) : null;
|
|
573
574
|
const helpNode = renderDescription ? renderDescription(context) : field.description ? /* @__PURE__ */ import_react.default.createElement("p", { className: classes.help }, field.description) : null;
|
|
574
575
|
const errorNode = canShowError ? renderError ? renderError(context) : /* @__PURE__ */ import_react.default.createElement("p", { className: classes.error, role: "alert" }, error) : null;
|
|
575
576
|
const controlNode = field.renderControl?.(context) ?? renderControl?.(context) ?? renderDefaultControl(context);
|
|
@@ -583,7 +584,7 @@ var DynamicFields = ({
|
|
|
583
584
|
}));
|
|
584
585
|
}
|
|
585
586
|
if (field.type === "checkbox") {
|
|
586
|
-
return /* @__PURE__ */ import_react.default.createElement("div", { key: field.name, className: classes.field }, /* @__PURE__ */ import_react.default.createElement("label", { htmlFor: field.name, className: "inline-flex items-start gap-2 cursor-pointer" }, controlNode, /* @__PURE__ */ import_react.default.createElement("span", { className: "text-sm text-
|
|
587
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { key: field.name, className: classes.field }, /* @__PURE__ */ import_react.default.createElement("label", { htmlFor: field.name, className: "inline-flex items-start gap-2 cursor-pointer select-none" }, controlNode, /* @__PURE__ */ import_react.default.createElement("span", { className: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-70" }, field.label, requiredMark && /* @__PURE__ */ import_react.default.createElement("span", { className: "text-red-500 ml-1" }, "*"))), helpNode, errorNode);
|
|
587
588
|
}
|
|
588
589
|
return /* @__PURE__ */ import_react.default.createElement("div", { key: field.name, className: classes.field }, labelNode, helpNode, controlNode, errorNode);
|
|
589
590
|
})));
|
package/dist/index.js
CHANGED
|
@@ -77,82 +77,82 @@ var buildInitialValues = (fields, defaultValues, controlledValues) => {
|
|
|
77
77
|
};
|
|
78
78
|
var baseTheme = {
|
|
79
79
|
default: {
|
|
80
|
-
wrapper: "w-full max-w-2xl mx-auto p-6 bg-white dark:bg-
|
|
81
|
-
title: "text-2xl font-semibold tracking-tight text-
|
|
82
|
-
description: "text-sm text-
|
|
83
|
-
fieldsContainer: "space-y-
|
|
84
|
-
field: "w-full",
|
|
85
|
-
label: "
|
|
86
|
-
help: "text-
|
|
87
|
-
control: "w-full rounded-
|
|
88
|
-
textarea: "w-full rounded-
|
|
89
|
-
select: "w-full rounded-
|
|
90
|
-
option: "text-
|
|
91
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
92
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
93
|
-
error: "text-
|
|
80
|
+
wrapper: "w-full max-w-2xl mx-auto p-6 bg-white dark:bg-zinc-950 rounded-lg border border-zinc-200 dark:border-zinc-800 shadow-sm",
|
|
81
|
+
title: "text-2xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
82
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
83
|
+
fieldsContainer: "space-y-4",
|
|
84
|
+
field: "w-full space-y-2",
|
|
85
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
86
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
87
|
+
control: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
88
|
+
textarea: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 transition-colors min-h-[80px] resize-none",
|
|
89
|
+
select: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
90
|
+
option: "text-zinc-950 dark:text-zinc-50 bg-white dark:bg-zinc-950",
|
|
91
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-900 dark:border-zinc-50 bg-white dark:bg-zinc-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50",
|
|
92
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-900 dark:border-zinc-50 bg-white dark:bg-zinc-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-white dark:ring-offset-zinc-950 disabled:cursor-not-allowed disabled:opacity-50",
|
|
93
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
94
94
|
},
|
|
95
95
|
minimal: {
|
|
96
96
|
wrapper: "w-full max-w-2xl mx-auto",
|
|
97
|
-
title: "text-xl font-semibold text-
|
|
98
|
-
description: "text-sm text-
|
|
99
|
-
fieldsContainer: "space-y-
|
|
100
|
-
field: "w-full",
|
|
101
|
-
label: "text-sm font-medium text-
|
|
102
|
-
help: "text-
|
|
103
|
-
control: "w-full rounded-md border border-
|
|
104
|
-
textarea: "w-full rounded-md border border-
|
|
105
|
-
select: "w-full rounded-md border border-
|
|
106
|
-
option: "text-
|
|
107
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
108
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
109
|
-
error: "text-
|
|
97
|
+
title: "text-xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
98
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
99
|
+
fieldsContainer: "space-y-4",
|
|
100
|
+
field: "w-full space-y-2",
|
|
101
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
102
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
103
|
+
control: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
104
|
+
textarea: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors min-h-[80px] resize-none",
|
|
105
|
+
select: "w-full rounded-md border border-zinc-200 dark:border-zinc-800 bg-transparent text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
106
|
+
option: "text-zinc-950 dark:text-zinc-50",
|
|
107
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-200 dark:border-zinc-800 bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
108
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-200 dark:border-zinc-800 bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
109
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
110
110
|
},
|
|
111
111
|
filled: {
|
|
112
|
-
wrapper: "w-full max-w-2xl mx-auto p-6 bg-
|
|
113
|
-
title: "text-2xl font-semibold text-
|
|
114
|
-
description: "text-sm text-
|
|
115
|
-
fieldsContainer: "space-y-
|
|
116
|
-
field: "w-full",
|
|
117
|
-
label: "text-sm font-medium text-
|
|
118
|
-
help: "text-
|
|
119
|
-
control: "w-full rounded-
|
|
120
|
-
textarea: "w-full rounded-
|
|
121
|
-
select: "w-full rounded-
|
|
122
|
-
option: "text-
|
|
123
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
124
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
125
|
-
error: "text-
|
|
112
|
+
wrapper: "w-full max-w-2xl mx-auto p-6 bg-zinc-50 dark:bg-zinc-900 rounded-lg border border-zinc-100 dark:border-zinc-800",
|
|
113
|
+
title: "text-2xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
114
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
115
|
+
fieldsContainer: "space-y-4",
|
|
116
|
+
field: "w-full space-y-2",
|
|
117
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
118
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
119
|
+
control: "w-full rounded-md border border-zinc-100 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-800 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
120
|
+
textarea: "w-full rounded-md border border-zinc-100 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-800 text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50 transition-colors min-h-[80px] resize-none",
|
|
121
|
+
select: "w-full rounded-md border border-zinc-100 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-800 text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50 transition-colors",
|
|
122
|
+
option: "text-zinc-950 dark:text-zinc-50 bg-white dark:bg-zinc-900",
|
|
123
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50",
|
|
124
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 ring-offset-zinc-50 dark:ring-offset-zinc-900 disabled:cursor-not-allowed disabled:opacity-50",
|
|
125
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
126
126
|
},
|
|
127
127
|
underline: {
|
|
128
|
-
wrapper: "w-full max-w-2xl mx-auto
|
|
129
|
-
title: "text-xl font-semibold text-
|
|
130
|
-
description: "text-sm text-
|
|
128
|
+
wrapper: "w-full max-w-2xl mx-auto py-4",
|
|
129
|
+
title: "text-xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-50",
|
|
130
|
+
description: "text-sm text-zinc-500 dark:text-zinc-400",
|
|
131
131
|
fieldsContainer: "space-y-4",
|
|
132
|
-
field: "w-full",
|
|
133
|
-
label: "text-sm font-medium text-
|
|
134
|
-
help: "text-
|
|
135
|
-
control: "w-full border-0 border-b border-
|
|
136
|
-
textarea: "w-full border-0 border-b border-
|
|
137
|
-
select: "w-full border-0 border-b border-
|
|
138
|
-
option: "text-
|
|
139
|
-
checkbox: "h-4 w-4 rounded border border-
|
|
140
|
-
radio: "h-4 w-4 rounded-full border border-
|
|
141
|
-
error: "text-
|
|
132
|
+
field: "w-full space-y-2",
|
|
133
|
+
label: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50",
|
|
134
|
+
help: "text-[0.8rem] text-zinc-500 dark:text-zinc-400",
|
|
135
|
+
control: "w-full border-0 border-b border-zinc-200 dark:border-zinc-700 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 rounded-none focus-visible:outline-none focus-visible:ring-0 focus-visible:border-zinc-950 dark:focus-visible:border-zinc-300 disabled:cursor-not-allowed disabled:opacity-50 transition-colors px-0",
|
|
136
|
+
textarea: "w-full border-0 border-b border-zinc-200 dark:border-zinc-700 bg-transparent text-zinc-950 dark:text-zinc-50 placeholder:text-zinc-400 dark:placeholder:text-zinc-500 rounded-none focus-visible:outline-none focus-visible:ring-0 focus-visible:border-zinc-950 dark:focus-visible:border-zinc-300 disabled:cursor-not-allowed disabled:opacity-50 transition-colors px-0 min-h-[80px] resize-none",
|
|
137
|
+
select: "w-full border-0 border-b border-zinc-200 dark:border-zinc-700 bg-transparent text-zinc-950 dark:text-zinc-50 focus-visible:outline-none focus-visible:ring-0 focus-visible:border-zinc-950 dark:focus-visible:border-zinc-300 disabled:cursor-not-allowed disabled:opacity-50 transition-colors rounded-none px-0",
|
|
138
|
+
option: "text-zinc-950 dark:text-zinc-50",
|
|
139
|
+
checkbox: "h-4 w-4 shrink-0 rounded-sm border border-zinc-200 dark:border-zinc-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
140
|
+
radio: "h-4 w-4 shrink-0 rounded-full border border-zinc-200 dark:border-zinc-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 dark:focus-visible:ring-zinc-300 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
141
|
+
error: "text-[0.8rem] font-medium text-red-500 dark:text-red-400"
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
var sizeMap = {
|
|
145
145
|
sm: {
|
|
146
146
|
control: "px-3 py-1.5 text-xs",
|
|
147
147
|
label: "text-xs",
|
|
148
|
-
help: "text-[
|
|
148
|
+
help: "text-[0.7rem]",
|
|
149
149
|
error: "text-xs"
|
|
150
150
|
},
|
|
151
151
|
md: {
|
|
152
|
-
control: "px-3
|
|
152
|
+
control: "px-3 py-2 text-sm",
|
|
153
153
|
label: "text-sm",
|
|
154
|
-
help: "text-
|
|
155
|
-
error: "text-
|
|
154
|
+
help: "text-[0.8rem]",
|
|
155
|
+
error: "text-[0.8rem]"
|
|
156
156
|
},
|
|
157
157
|
lg: {
|
|
158
158
|
control: "px-4 py-2.5 text-base",
|
|
@@ -381,7 +381,7 @@ var DynamicFields = ({
|
|
|
381
381
|
error: cn(defaultUi.error, sizeClasses.error, errorClassName, field?.errorClassName, ui?.error, field?.ui?.error)
|
|
382
382
|
});
|
|
383
383
|
const buildStateClassName = (field, hasError, disabled, readOnly) => cn(
|
|
384
|
-
hasError && stateClassNames?.invalid,
|
|
384
|
+
hasError && (stateClassNames?.invalid ?? "border-red-500 dark:border-red-500 focus-visible:ring-red-500 dark:focus-visible:ring-red-500"),
|
|
385
385
|
disabled && stateClassNames?.disabled,
|
|
386
386
|
readOnly && stateClassNames?.readonly,
|
|
387
387
|
dirtyMap[field.name] && stateClassNames?.dirty,
|
|
@@ -398,7 +398,8 @@ var DynamicFields = ({
|
|
|
398
398
|
};
|
|
399
399
|
const renderDefaultControl = (context) => {
|
|
400
400
|
const { field, value: value2, options, isLoadingOptions, classes, handleChange, handleBlur, disabled, readOnly, error } = context;
|
|
401
|
-
const
|
|
401
|
+
const showsError = Boolean(error) && shouldShowError(field.name);
|
|
402
|
+
const controlStateClass = buildStateClassName(field, showsError, disabled, readOnly);
|
|
402
403
|
if (field.type === "textarea") {
|
|
403
404
|
return /* @__PURE__ */ React.createElement(
|
|
404
405
|
"textarea",
|
|
@@ -446,7 +447,7 @@ var DynamicFields = ({
|
|
|
446
447
|
{
|
|
447
448
|
key: `${field.name}-${String(option.value)}`,
|
|
448
449
|
htmlFor: `${field.name}-${String(option.value)}`,
|
|
449
|
-
className: "flex items-center gap-2 cursor-pointer"
|
|
450
|
+
className: "flex items-center gap-2 cursor-pointer select-none"
|
|
450
451
|
},
|
|
451
452
|
/* @__PURE__ */ React.createElement(
|
|
452
453
|
"input",
|
|
@@ -463,7 +464,7 @@ var DynamicFields = ({
|
|
|
463
464
|
className: cn(classes.radio, controlStateClass)
|
|
464
465
|
}
|
|
465
466
|
),
|
|
466
|
-
/* @__PURE__ */ React.createElement("span", { className: "text-sm text-
|
|
467
|
+
/* @__PURE__ */ React.createElement("span", { className: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-70" }, option.label)
|
|
467
468
|
)));
|
|
468
469
|
}
|
|
469
470
|
if (field.type === "checkbox") {
|
|
@@ -505,7 +506,7 @@ var DynamicFields = ({
|
|
|
505
506
|
}
|
|
506
507
|
);
|
|
507
508
|
};
|
|
508
|
-
return /* @__PURE__ */ React.createElement("div", { className: resolveUi().wrapper }, title && /* @__PURE__ */ React.createElement("div", { className: "mb-
|
|
509
|
+
return /* @__PURE__ */ React.createElement("div", { className: resolveUi().wrapper }, title && /* @__PURE__ */ React.createElement("div", { className: "flex flex-col space-y-1.5 pb-6 mb-6 border-b border-zinc-200 dark:border-zinc-800" }, /* @__PURE__ */ React.createElement("h2", { className: resolveUi().title }, title), description && /* @__PURE__ */ React.createElement("p", { className: resolveUi().description }, description)), /* @__PURE__ */ React.createElement("div", { className: resolveUi().fieldsContainer }, visibleFields.map((field) => {
|
|
509
510
|
const classes = resolveUi(field);
|
|
510
511
|
const storedValue = getIn(values, field.name);
|
|
511
512
|
const renderedValue = field.transformIn ? field.transformIn(storedValue, values) : storedValue;
|
|
@@ -533,7 +534,7 @@ var DynamicFields = ({
|
|
|
533
534
|
handleBlur: () => handleFieldBlur(field)
|
|
534
535
|
};
|
|
535
536
|
const requiredMark = field.required || field.requiredWhen?.(values);
|
|
536
|
-
const labelNode = field.type === "checkbox" ? null : renderLabel ? renderLabel(context) : field.label ? /* @__PURE__ */ React.createElement("label", { htmlFor: field.name, className: classes.label }, field.label, requiredMark && /* @__PURE__ */ React.createElement("span", { className: "text-red-500
|
|
537
|
+
const labelNode = field.type === "checkbox" ? null : renderLabel ? renderLabel(context) : field.label ? /* @__PURE__ */ React.createElement("label", { htmlFor: field.name, className: classes.label }, field.label, requiredMark && /* @__PURE__ */ React.createElement("span", { className: "text-red-500 ml-1" }, "*")) : null;
|
|
537
538
|
const helpNode = renderDescription ? renderDescription(context) : field.description ? /* @__PURE__ */ React.createElement("p", { className: classes.help }, field.description) : null;
|
|
538
539
|
const errorNode = canShowError ? renderError ? renderError(context) : /* @__PURE__ */ React.createElement("p", { className: classes.error, role: "alert" }, error) : null;
|
|
539
540
|
const controlNode = field.renderControl?.(context) ?? renderControl?.(context) ?? renderDefaultControl(context);
|
|
@@ -547,7 +548,7 @@ var DynamicFields = ({
|
|
|
547
548
|
}));
|
|
548
549
|
}
|
|
549
550
|
if (field.type === "checkbox") {
|
|
550
|
-
return /* @__PURE__ */ React.createElement("div", { key: field.name, className: classes.field }, /* @__PURE__ */ React.createElement("label", { htmlFor: field.name, className: "inline-flex items-start gap-2 cursor-pointer" }, controlNode, /* @__PURE__ */ React.createElement("span", { className: "text-sm text-
|
|
551
|
+
return /* @__PURE__ */ React.createElement("div", { key: field.name, className: classes.field }, /* @__PURE__ */ React.createElement("label", { htmlFor: field.name, className: "inline-flex items-start gap-2 cursor-pointer select-none" }, controlNode, /* @__PURE__ */ React.createElement("span", { className: "text-sm font-medium leading-none text-zinc-950 dark:text-zinc-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-70" }, field.label, requiredMark && /* @__PURE__ */ React.createElement("span", { className: "text-red-500 ml-1" }, "*"))), helpNode, errorNode);
|
|
551
552
|
}
|
|
552
553
|
return /* @__PURE__ */ React.createElement("div", { key: field.name, className: classes.field }, labelNode, helpNode, controlNode, errorNode);
|
|
553
554
|
})));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-smart-fields",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A flexible and highly customizable dynamic form builder for React with validation, conditional fields, theming, and headless rendering.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Pratik Panchal",
|