@edux-design/forms 0.0.1
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.js +241 -0
- package/dist/index.mjs +209 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
Feedback: () => Feedback,
|
|
33
|
+
Field: () => Field,
|
|
34
|
+
Input: () => Input,
|
|
35
|
+
Label: () => Label
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/elements/Label.jsx
|
|
40
|
+
var import_react2 = __toESM(require("react"));
|
|
41
|
+
var import_react3 = require("react");
|
|
42
|
+
|
|
43
|
+
// src/utils/useFieldContext.jsx
|
|
44
|
+
var import_react = __toESM(require("react"));
|
|
45
|
+
var FieldContext = (0, import_react.createContext)(null);
|
|
46
|
+
var FieldProvider = ({ children }) => {
|
|
47
|
+
const baseId = (0, import_react.useId)();
|
|
48
|
+
const [type, setType] = (0, import_react.useState)("");
|
|
49
|
+
const [describedByIds, setDescribedByIds] = (0, import_react.useState)([]);
|
|
50
|
+
const registerDescription = (0, import_react.useCallback)((id) => {
|
|
51
|
+
if (!id) return;
|
|
52
|
+
setDescribedByIds((prev) => prev.includes(id) ? prev : [...prev, id]);
|
|
53
|
+
}, []);
|
|
54
|
+
const unregisterDescription = (0, import_react.useCallback)((id) => {
|
|
55
|
+
if (!id) return;
|
|
56
|
+
setDescribedByIds((prev) => prev.filter((x) => x !== id));
|
|
57
|
+
}, []);
|
|
58
|
+
const value = (0, import_react.useMemo)(
|
|
59
|
+
() => ({
|
|
60
|
+
labelHTMLForId: baseId,
|
|
61
|
+
type,
|
|
62
|
+
setType,
|
|
63
|
+
describedByIds,
|
|
64
|
+
registerDescription,
|
|
65
|
+
unregisterDescription
|
|
66
|
+
}),
|
|
67
|
+
[baseId, type, describedByIds, registerDescription, unregisterDescription]
|
|
68
|
+
);
|
|
69
|
+
return /* @__PURE__ */ import_react.default.createElement(FieldContext.Provider, { value }, children);
|
|
70
|
+
};
|
|
71
|
+
var useFieldContext = () => {
|
|
72
|
+
const context = (0, import_react.useContext)(FieldContext);
|
|
73
|
+
if (!context) {
|
|
74
|
+
throw new Error("useFieldContext must be used within a FieldProvider");
|
|
75
|
+
}
|
|
76
|
+
return context;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/elements/Label.jsx
|
|
80
|
+
var Label = ({ children, hint, description, ...props }) => {
|
|
81
|
+
const { labelHTMLForId } = useFieldContext();
|
|
82
|
+
const returnHintType = (0, import_react3.useCallback)((hint2) => {
|
|
83
|
+
switch (hint2 == null ? void 0 : hint2.toLowerCase()) {
|
|
84
|
+
case void 0:
|
|
85
|
+
return;
|
|
86
|
+
case "required":
|
|
87
|
+
return /* @__PURE__ */ import_react2.default.createElement("span", { className: "ml-2 text-fg-danger-base" }, "[required]");
|
|
88
|
+
case "optional":
|
|
89
|
+
return /* @__PURE__ */ import_react2.default.createElement("span", { className: "ml-2" }, "[optional]");
|
|
90
|
+
default:
|
|
91
|
+
console.warn(
|
|
92
|
+
"[Invalid prop arg] - The <Label> component only accepts 'Required' || 'Optional'. Nothing has been returned."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}, []);
|
|
96
|
+
const hintEl = returnHintType(hint);
|
|
97
|
+
return /* @__PURE__ */ import_react2.default.createElement(
|
|
98
|
+
"label",
|
|
99
|
+
{
|
|
100
|
+
hidden: props.hidden,
|
|
101
|
+
className: "tracking-normal leading-none flex flex-col gap-4",
|
|
102
|
+
htmlFor: labelHTMLForId
|
|
103
|
+
},
|
|
104
|
+
/* @__PURE__ */ import_react2.default.createElement("div", { className: "h-[21px]" }, children, hintEl),
|
|
105
|
+
description && /* @__PURE__ */ import_react2.default.createElement("div", { className: "h-[21px] text-sm font-light text-fg-base" }, description)
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/elements/Input.jsx
|
|
110
|
+
var import_react4 = __toESM(require("react"));
|
|
111
|
+
var import_utils = require("@edux-design/utils");
|
|
112
|
+
var import_icons = require("@edux-design/icons");
|
|
113
|
+
var Input = (0, import_react4.forwardRef)(
|
|
114
|
+
({
|
|
115
|
+
children,
|
|
116
|
+
autocomplete,
|
|
117
|
+
validation,
|
|
118
|
+
variant = "primary",
|
|
119
|
+
clearable = false,
|
|
120
|
+
startIcon,
|
|
121
|
+
endIcon,
|
|
122
|
+
...props
|
|
123
|
+
}, ref) => {
|
|
124
|
+
const { labelHTMLForId } = useFieldContext();
|
|
125
|
+
const hasValue = Boolean(props.value);
|
|
126
|
+
const defaults = "h-[44px] w-full border-2 rounded-md border-border-base focus:shadow-focus focus-visible:shadow-focus outline-none transition-all duration-300 ease-in-out";
|
|
127
|
+
const fonts = "font-normal text-base";
|
|
128
|
+
const variants = {
|
|
129
|
+
primary: "hover:border-2 hover:border-border-primary-base focus:border-2 focus:border-border-primary-base focus-within:border-2 focus-within:border-border-primary-base",
|
|
130
|
+
error: "border-border-danger-base bg-bg-danger-subtle",
|
|
131
|
+
corrective: "border-border-corrective-base",
|
|
132
|
+
success: "border-border-success-base",
|
|
133
|
+
inactive: "border-border-subtle bg-bg-subtle"
|
|
134
|
+
};
|
|
135
|
+
const INPUT_STYLES = (0, import_utils.cx)(
|
|
136
|
+
defaults,
|
|
137
|
+
fonts,
|
|
138
|
+
variants[variant],
|
|
139
|
+
startIcon && "pl-10",
|
|
140
|
+
(clearable || endIcon) && "pr-10"
|
|
141
|
+
);
|
|
142
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "w-full relative flex items-center" }, startIcon && /* @__PURE__ */ import_react4.default.createElement(
|
|
143
|
+
"span",
|
|
144
|
+
{
|
|
145
|
+
className: "absolute left-3 flex items-center pointer-events-none text-fg-subtle",
|
|
146
|
+
"aria-hidden": "true"
|
|
147
|
+
},
|
|
148
|
+
startIcon
|
|
149
|
+
), /* @__PURE__ */ import_react4.default.createElement(
|
|
150
|
+
"input",
|
|
151
|
+
{
|
|
152
|
+
id: labelHTMLForId,
|
|
153
|
+
ref,
|
|
154
|
+
className: INPUT_STYLES,
|
|
155
|
+
autoComplete: autocomplete || "",
|
|
156
|
+
"aria-disabled": props.disabled || variant === "inactive",
|
|
157
|
+
"aria-invalid": variant === "error" ? "true" : void 0,
|
|
158
|
+
disabled: props.disabled || variant === "inactive",
|
|
159
|
+
...props
|
|
160
|
+
}
|
|
161
|
+
), clearable && /* @__PURE__ */ import_react4.default.createElement(
|
|
162
|
+
"button",
|
|
163
|
+
{
|
|
164
|
+
type: "button",
|
|
165
|
+
"aria-label": "Clear input",
|
|
166
|
+
onClick: () => {
|
|
167
|
+
var _a;
|
|
168
|
+
return (_a = props.onChange) == null ? void 0 : _a.call(props, { target: { value: "" } });
|
|
169
|
+
},
|
|
170
|
+
className: (0, import_utils.cx)(
|
|
171
|
+
clearable && hasValue ? "right-9" : "right-3",
|
|
172
|
+
"absolute flex items-center p-1 rounded-full outline-none",
|
|
173
|
+
"transition-all duration-300 ease-in-out",
|
|
174
|
+
hasValue ? "opacity-100 scale-100" : "opacity-0 scale-90 pointer-events-none",
|
|
175
|
+
"focus:shadow-focus"
|
|
176
|
+
)
|
|
177
|
+
},
|
|
178
|
+
/* @__PURE__ */ import_react4.default.createElement(import_icons.Close, { "aria-hidden": "true", className: "text-fg-subtle" })
|
|
179
|
+
), endIcon && /* @__PURE__ */ import_react4.default.createElement(
|
|
180
|
+
"span",
|
|
181
|
+
{
|
|
182
|
+
className: (0, import_utils.cx)("absolute flex items-center right-3 text-fg-subtle"),
|
|
183
|
+
"aria-hidden": typeof endIcon === "string" ? void 0 : "true"
|
|
184
|
+
},
|
|
185
|
+
endIcon
|
|
186
|
+
));
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// src/elements/Field.jsx
|
|
191
|
+
var import_react5 = __toESM(require("react"));
|
|
192
|
+
var import_utils2 = require("@edux-design/utils");
|
|
193
|
+
var import_icons2 = require("@edux-design/icons");
|
|
194
|
+
var Field = ({ children }) => {
|
|
195
|
+
const FIELD_GROUP_WRAPPER_STYLES = (0, import_utils2.cx)(
|
|
196
|
+
"flex flex-col items-start relative gap-8"
|
|
197
|
+
);
|
|
198
|
+
return /* @__PURE__ */ import_react5.default.createElement(FieldProvider, null, /* @__PURE__ */ import_react5.default.createElement("div", { className: FIELD_GROUP_WRAPPER_STYLES }, children));
|
|
199
|
+
};
|
|
200
|
+
function Feedback({ id, tone = "help", children, className, ...rest }) {
|
|
201
|
+
const { labelHTMLForId, registerDescription, unregisterDescription } = useFieldContext();
|
|
202
|
+
const autoId = (0, import_react5.useId)();
|
|
203
|
+
const feedbackId = id ?? `${labelHTMLForId}-fb-${autoId}`;
|
|
204
|
+
(0, import_react5.useEffect)(() => {
|
|
205
|
+
registerDescription(feedbackId);
|
|
206
|
+
return () => unregisterDescription(feedbackId);
|
|
207
|
+
}, [feedbackId, registerDescription, unregisterDescription]);
|
|
208
|
+
const colorByTone = {
|
|
209
|
+
corrective: "bg-fg-corrective-base",
|
|
210
|
+
info: "bg-fg-info-base",
|
|
211
|
+
success: "bg-fg-success-base",
|
|
212
|
+
warning: "bg-fg-warning-base",
|
|
213
|
+
error: "bg-fg-danger-base"
|
|
214
|
+
}[tone];
|
|
215
|
+
const liveProps = tone === "error" ? { role: "alert", "aria-live": "assertive" } : { "aria-live": "polite" };
|
|
216
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
217
|
+
"div",
|
|
218
|
+
{
|
|
219
|
+
id: feedbackId,
|
|
220
|
+
className: (0, import_utils2.cx)("text-sm mt-1 flex gap-6", className),
|
|
221
|
+
...liveProps,
|
|
222
|
+
...rest
|
|
223
|
+
},
|
|
224
|
+
/* @__PURE__ */ import_react5.default.createElement(
|
|
225
|
+
"div",
|
|
226
|
+
{
|
|
227
|
+
className: `h-[20px] w-[20px] ${colorByTone} rounded-full flex flex-col justify-center items-center`
|
|
228
|
+
},
|
|
229
|
+
/* @__PURE__ */ import_react5.default.createElement(import_icons2.Close, { className: "text-white" })
|
|
230
|
+
),
|
|
231
|
+
children
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
Field.Feedback = Feedback;
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
Feedback,
|
|
238
|
+
Field,
|
|
239
|
+
Input,
|
|
240
|
+
Label
|
|
241
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// src/elements/Label.jsx
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import { useCallback as useCallback2 } from "react";
|
|
4
|
+
|
|
5
|
+
// src/utils/useFieldContext.jsx
|
|
6
|
+
import React, {
|
|
7
|
+
createContext,
|
|
8
|
+
useContext,
|
|
9
|
+
useId,
|
|
10
|
+
useMemo,
|
|
11
|
+
useState,
|
|
12
|
+
useCallback
|
|
13
|
+
} from "react";
|
|
14
|
+
var FieldContext = createContext(null);
|
|
15
|
+
var FieldProvider = ({ children }) => {
|
|
16
|
+
const baseId = useId();
|
|
17
|
+
const [type, setType] = useState("");
|
|
18
|
+
const [describedByIds, setDescribedByIds] = useState([]);
|
|
19
|
+
const registerDescription = useCallback((id) => {
|
|
20
|
+
if (!id) return;
|
|
21
|
+
setDescribedByIds((prev) => prev.includes(id) ? prev : [...prev, id]);
|
|
22
|
+
}, []);
|
|
23
|
+
const unregisterDescription = useCallback((id) => {
|
|
24
|
+
if (!id) return;
|
|
25
|
+
setDescribedByIds((prev) => prev.filter((x) => x !== id));
|
|
26
|
+
}, []);
|
|
27
|
+
const value = useMemo(
|
|
28
|
+
() => ({
|
|
29
|
+
labelHTMLForId: baseId,
|
|
30
|
+
type,
|
|
31
|
+
setType,
|
|
32
|
+
describedByIds,
|
|
33
|
+
registerDescription,
|
|
34
|
+
unregisterDescription
|
|
35
|
+
}),
|
|
36
|
+
[baseId, type, describedByIds, registerDescription, unregisterDescription]
|
|
37
|
+
);
|
|
38
|
+
return /* @__PURE__ */ React.createElement(FieldContext.Provider, { value }, children);
|
|
39
|
+
};
|
|
40
|
+
var useFieldContext = () => {
|
|
41
|
+
const context = useContext(FieldContext);
|
|
42
|
+
if (!context) {
|
|
43
|
+
throw new Error("useFieldContext must be used within a FieldProvider");
|
|
44
|
+
}
|
|
45
|
+
return context;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/elements/Label.jsx
|
|
49
|
+
var Label = ({ children, hint, description, ...props }) => {
|
|
50
|
+
const { labelHTMLForId } = useFieldContext();
|
|
51
|
+
const returnHintType = useCallback2((hint2) => {
|
|
52
|
+
switch (hint2 == null ? void 0 : hint2.toLowerCase()) {
|
|
53
|
+
case void 0:
|
|
54
|
+
return;
|
|
55
|
+
case "required":
|
|
56
|
+
return /* @__PURE__ */ React2.createElement("span", { className: "ml-2 text-fg-danger-base" }, "[required]");
|
|
57
|
+
case "optional":
|
|
58
|
+
return /* @__PURE__ */ React2.createElement("span", { className: "ml-2" }, "[optional]");
|
|
59
|
+
default:
|
|
60
|
+
console.warn(
|
|
61
|
+
"[Invalid prop arg] - The <Label> component only accepts 'Required' || 'Optional'. Nothing has been returned."
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}, []);
|
|
65
|
+
const hintEl = returnHintType(hint);
|
|
66
|
+
return /* @__PURE__ */ React2.createElement(
|
|
67
|
+
"label",
|
|
68
|
+
{
|
|
69
|
+
hidden: props.hidden,
|
|
70
|
+
className: "tracking-normal leading-none flex flex-col gap-4",
|
|
71
|
+
htmlFor: labelHTMLForId
|
|
72
|
+
},
|
|
73
|
+
/* @__PURE__ */ React2.createElement("div", { className: "h-[21px]" }, children, hintEl),
|
|
74
|
+
description && /* @__PURE__ */ React2.createElement("div", { className: "h-[21px] text-sm font-light text-fg-base" }, description)
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/elements/Input.jsx
|
|
79
|
+
import React3, { forwardRef } from "react";
|
|
80
|
+
import { cx } from "@edux-design/utils";
|
|
81
|
+
import { Close } from "@edux-design/icons";
|
|
82
|
+
var Input = forwardRef(
|
|
83
|
+
({
|
|
84
|
+
children,
|
|
85
|
+
autocomplete,
|
|
86
|
+
validation,
|
|
87
|
+
variant = "primary",
|
|
88
|
+
clearable = false,
|
|
89
|
+
startIcon,
|
|
90
|
+
endIcon,
|
|
91
|
+
...props
|
|
92
|
+
}, ref) => {
|
|
93
|
+
const { labelHTMLForId } = useFieldContext();
|
|
94
|
+
const hasValue = Boolean(props.value);
|
|
95
|
+
const defaults = "h-[44px] w-full border-2 rounded-md border-border-base focus:shadow-focus focus-visible:shadow-focus outline-none transition-all duration-300 ease-in-out";
|
|
96
|
+
const fonts = "font-normal text-base";
|
|
97
|
+
const variants = {
|
|
98
|
+
primary: "hover:border-2 hover:border-border-primary-base focus:border-2 focus:border-border-primary-base focus-within:border-2 focus-within:border-border-primary-base",
|
|
99
|
+
error: "border-border-danger-base bg-bg-danger-subtle",
|
|
100
|
+
corrective: "border-border-corrective-base",
|
|
101
|
+
success: "border-border-success-base",
|
|
102
|
+
inactive: "border-border-subtle bg-bg-subtle"
|
|
103
|
+
};
|
|
104
|
+
const INPUT_STYLES = cx(
|
|
105
|
+
defaults,
|
|
106
|
+
fonts,
|
|
107
|
+
variants[variant],
|
|
108
|
+
startIcon && "pl-10",
|
|
109
|
+
(clearable || endIcon) && "pr-10"
|
|
110
|
+
);
|
|
111
|
+
return /* @__PURE__ */ React3.createElement("div", { className: "w-full relative flex items-center" }, startIcon && /* @__PURE__ */ React3.createElement(
|
|
112
|
+
"span",
|
|
113
|
+
{
|
|
114
|
+
className: "absolute left-3 flex items-center pointer-events-none text-fg-subtle",
|
|
115
|
+
"aria-hidden": "true"
|
|
116
|
+
},
|
|
117
|
+
startIcon
|
|
118
|
+
), /* @__PURE__ */ React3.createElement(
|
|
119
|
+
"input",
|
|
120
|
+
{
|
|
121
|
+
id: labelHTMLForId,
|
|
122
|
+
ref,
|
|
123
|
+
className: INPUT_STYLES,
|
|
124
|
+
autoComplete: autocomplete || "",
|
|
125
|
+
"aria-disabled": props.disabled || variant === "inactive",
|
|
126
|
+
"aria-invalid": variant === "error" ? "true" : void 0,
|
|
127
|
+
disabled: props.disabled || variant === "inactive",
|
|
128
|
+
...props
|
|
129
|
+
}
|
|
130
|
+
), clearable && /* @__PURE__ */ React3.createElement(
|
|
131
|
+
"button",
|
|
132
|
+
{
|
|
133
|
+
type: "button",
|
|
134
|
+
"aria-label": "Clear input",
|
|
135
|
+
onClick: () => {
|
|
136
|
+
var _a;
|
|
137
|
+
return (_a = props.onChange) == null ? void 0 : _a.call(props, { target: { value: "" } });
|
|
138
|
+
},
|
|
139
|
+
className: cx(
|
|
140
|
+
clearable && hasValue ? "right-9" : "right-3",
|
|
141
|
+
"absolute flex items-center p-1 rounded-full outline-none",
|
|
142
|
+
"transition-all duration-300 ease-in-out",
|
|
143
|
+
hasValue ? "opacity-100 scale-100" : "opacity-0 scale-90 pointer-events-none",
|
|
144
|
+
"focus:shadow-focus"
|
|
145
|
+
)
|
|
146
|
+
},
|
|
147
|
+
/* @__PURE__ */ React3.createElement(Close, { "aria-hidden": "true", className: "text-fg-subtle" })
|
|
148
|
+
), endIcon && /* @__PURE__ */ React3.createElement(
|
|
149
|
+
"span",
|
|
150
|
+
{
|
|
151
|
+
className: cx("absolute flex items-center right-3 text-fg-subtle"),
|
|
152
|
+
"aria-hidden": typeof endIcon === "string" ? void 0 : "true"
|
|
153
|
+
},
|
|
154
|
+
endIcon
|
|
155
|
+
));
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// src/elements/Field.jsx
|
|
160
|
+
import React4, { useEffect, useId as useId2 } from "react";
|
|
161
|
+
import { cx as cx2 } from "@edux-design/utils";
|
|
162
|
+
import { Close as Close2 } from "@edux-design/icons";
|
|
163
|
+
var Field = ({ children }) => {
|
|
164
|
+
const FIELD_GROUP_WRAPPER_STYLES = cx2(
|
|
165
|
+
"flex flex-col items-start relative gap-8"
|
|
166
|
+
);
|
|
167
|
+
return /* @__PURE__ */ React4.createElement(FieldProvider, null, /* @__PURE__ */ React4.createElement("div", { className: FIELD_GROUP_WRAPPER_STYLES }, children));
|
|
168
|
+
};
|
|
169
|
+
function Feedback({ id, tone = "help", children, className, ...rest }) {
|
|
170
|
+
const { labelHTMLForId, registerDescription, unregisterDescription } = useFieldContext();
|
|
171
|
+
const autoId = useId2();
|
|
172
|
+
const feedbackId = id ?? `${labelHTMLForId}-fb-${autoId}`;
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
registerDescription(feedbackId);
|
|
175
|
+
return () => unregisterDescription(feedbackId);
|
|
176
|
+
}, [feedbackId, registerDescription, unregisterDescription]);
|
|
177
|
+
const colorByTone = {
|
|
178
|
+
corrective: "bg-fg-corrective-base",
|
|
179
|
+
info: "bg-fg-info-base",
|
|
180
|
+
success: "bg-fg-success-base",
|
|
181
|
+
warning: "bg-fg-warning-base",
|
|
182
|
+
error: "bg-fg-danger-base"
|
|
183
|
+
}[tone];
|
|
184
|
+
const liveProps = tone === "error" ? { role: "alert", "aria-live": "assertive" } : { "aria-live": "polite" };
|
|
185
|
+
return /* @__PURE__ */ React4.createElement(
|
|
186
|
+
"div",
|
|
187
|
+
{
|
|
188
|
+
id: feedbackId,
|
|
189
|
+
className: cx2("text-sm mt-1 flex gap-6", className),
|
|
190
|
+
...liveProps,
|
|
191
|
+
...rest
|
|
192
|
+
},
|
|
193
|
+
/* @__PURE__ */ React4.createElement(
|
|
194
|
+
"div",
|
|
195
|
+
{
|
|
196
|
+
className: `h-[20px] w-[20px] ${colorByTone} rounded-full flex flex-col justify-center items-center`
|
|
197
|
+
},
|
|
198
|
+
/* @__PURE__ */ React4.createElement(Close2, { className: "text-white" })
|
|
199
|
+
),
|
|
200
|
+
children
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
Field.Feedback = Feedback;
|
|
204
|
+
export {
|
|
205
|
+
Feedback,
|
|
206
|
+
Field,
|
|
207
|
+
Input,
|
|
208
|
+
Label
|
|
209
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edux-design/forms",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"sideEffects": [
|
|
5
|
+
"**/*.css"
|
|
6
|
+
],
|
|
7
|
+
"private": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"lint": "eslint . --max-warnings 0",
|
|
19
|
+
"build": "tsup src/index.js --format esm,cjs",
|
|
20
|
+
"dev": "tsup src/index.js --watch --format esm,cjs",
|
|
21
|
+
"generate:component": "turbo gen react-component",
|
|
22
|
+
"check-types": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.9.2",
|
|
26
|
+
"tailwindcss": "^4.1.12",
|
|
27
|
+
"postcss": "^8.5.6",
|
|
28
|
+
"tsup": "^8.5.0",
|
|
29
|
+
"@tailwindcss/cli": "^4.1.12",
|
|
30
|
+
"@tailwindcss/postcss": "^4.1.12"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"react": "^19.1.0",
|
|
34
|
+
"react-dom": "^19.1.0",
|
|
35
|
+
"@edux-design/utils": "*",
|
|
36
|
+
"@edux-design/icons": "*"
|
|
37
|
+
}
|
|
38
|
+
}
|