@sereno-ds/ui 0.24.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/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/_internal/CharCount.d.ts +9 -0
- package/dist/_internal/CharCount.js +25 -0
- package/dist/_internal/CharCount.js.map +1 -0
- package/dist/_internal/Field.d.ts +17 -0
- package/dist/_internal/Field.js +55 -0
- package/dist/_internal/Field.js.map +1 -0
- package/dist/_internal/mask.d.ts +12 -0
- package/dist/_internal/mask.js +56 -0
- package/dist/_internal/mask.js.map +1 -0
- package/dist/_internal/style.d.ts +12 -0
- package/dist/_internal/style.js +5 -0
- package/dist/_internal/style.js.map +1 -0
- package/dist/core/Avatar.d.ts +14 -0
- package/dist/core/Avatar.js +62 -0
- package/dist/core/Avatar.js.map +1 -0
- package/dist/core/Badge.d.ts +16 -0
- package/dist/core/Badge.js +49 -0
- package/dist/core/Badge.js.map +1 -0
- package/dist/core/Brand.d.ts +18 -0
- package/dist/core/Brand.js +58 -0
- package/dist/core/Brand.js.map +1 -0
- package/dist/core/Button.d.ts +31 -0
- package/dist/core/Button.js +100 -0
- package/dist/core/Button.js.map +1 -0
- package/dist/core/Card.d.ts +15 -0
- package/dist/core/Card.js +34 -0
- package/dist/core/Card.js.map +1 -0
- package/dist/core/IconButton.d.ts +18 -0
- package/dist/core/IconButton.js +64 -0
- package/dist/core/IconButton.js.map +1 -0
- package/dist/core/Menu.d.ts +69 -0
- package/dist/core/Menu.js +278 -0
- package/dist/core/Menu.js.map +1 -0
- package/dist/core/Table.d.ts +92 -0
- package/dist/core/Table.js +162 -0
- package/dist/core/Table.js.map +1 -0
- package/dist/feedback/Alert.d.ts +27 -0
- package/dist/feedback/Alert.js +68 -0
- package/dist/feedback/Alert.js.map +1 -0
- package/dist/feedback/Dialog.d.ts +36 -0
- package/dist/feedback/Dialog.js +218 -0
- package/dist/feedback/Dialog.js.map +1 -0
- package/dist/feedback/EmptyState.d.ts +13 -0
- package/dist/feedback/EmptyState.js +70 -0
- package/dist/feedback/EmptyState.js.map +1 -0
- package/dist/feedback/Skeleton.d.ts +23 -0
- package/dist/feedback/Skeleton.js +44 -0
- package/dist/feedback/Skeleton.js.map +1 -0
- package/dist/feedback/Toast.d.ts +23 -0
- package/dist/feedback/Toast.js +85 -0
- package/dist/feedback/Toast.js.map +1 -0
- package/dist/feedback/ToastProvider.d.ts +69 -0
- package/dist/feedback/ToastProvider.js +183 -0
- package/dist/feedback/ToastProvider.js.map +1 -0
- package/dist/forms/AvatarUpload.d.ts +57 -0
- package/dist/forms/AvatarUpload.js +579 -0
- package/dist/forms/AvatarUpload.js.map +1 -0
- package/dist/forms/Checkbox.d.ts +15 -0
- package/dist/forms/Checkbox.js +57 -0
- package/dist/forms/Checkbox.js.map +1 -0
- package/dist/forms/DateTimePicker.d.ts +43 -0
- package/dist/forms/DateTimePicker.js +391 -0
- package/dist/forms/DateTimePicker.js.map +1 -0
- package/dist/forms/FileUpload.d.ts +39 -0
- package/dist/forms/FileUpload.js +376 -0
- package/dist/forms/FileUpload.js.map +1 -0
- package/dist/forms/Input.d.ts +35 -0
- package/dist/forms/Input.js +143 -0
- package/dist/forms/Input.js.map +1 -0
- package/dist/forms/Radio.d.ts +18 -0
- package/dist/forms/Radio.js +50 -0
- package/dist/forms/Radio.js.map +1 -0
- package/dist/forms/SearchInput.d.ts +23 -0
- package/dist/forms/SearchInput.js +70 -0
- package/dist/forms/SearchInput.js.map +1 -0
- package/dist/forms/Select.d.ts +40 -0
- package/dist/forms/Select.js +524 -0
- package/dist/forms/Select.js.map +1 -0
- package/dist/forms/Switch.d.ts +20 -0
- package/dist/forms/Switch.js +76 -0
- package/dist/forms/Switch.js.map +1 -0
- package/dist/forms/Textarea.d.ts +19 -0
- package/dist/forms/Textarea.js +65 -0
- package/dist/forms/Textarea.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/navigation/BottomNav.d.ts +17 -0
- package/dist/navigation/BottomNav.js +72 -0
- package/dist/navigation/BottomNav.js.map +1 -0
- package/dist/navigation/SidebarNav.d.ts +53 -0
- package/dist/navigation/SidebarNav.js +594 -0
- package/dist/navigation/SidebarNav.js.map +1 -0
- package/dist/navigation/Stepper.d.ts +33 -0
- package/dist/navigation/Stepper.js +87 -0
- package/dist/navigation/Stepper.js.map +1 -0
- package/dist/navigation/Tabs.d.ts +23 -0
- package/dist/navigation/Tabs.js +174 -0
- package/dist/navigation/Tabs.js.map +1 -0
- package/dist/navigation/TopBar.d.ts +17 -0
- package/dist/navigation/TopBar.js +65 -0
- package/dist/navigation/TopBar.js.map +1 -0
- package/dist/styles.css +258 -0
- package/dist/theme/ThemeProvider.d.ts +12 -0
- package/dist/theme/ThemeProvider.js +10 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/theme/ThemeToggle.d.ts +14 -0
- package/dist/theme/ThemeToggle.js +25 -0
- package/dist/theme/ThemeToggle.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { File as FileIcon, FileArchive, FileSpreadsheet, FileText, RefreshCw, Trash2, UploadCloud } from "lucide-react";
|
|
5
|
+
import { sx } from "../_internal/style";
|
|
6
|
+
import { Field } from "../_internal/Field";
|
|
7
|
+
function matchesAccept(file, accept) {
|
|
8
|
+
if (!accept || accept === "*" || accept === "*/*") return true;
|
|
9
|
+
const name = file.name.toLowerCase();
|
|
10
|
+
const type = file.type.toLowerCase();
|
|
11
|
+
return accept.split(",").map((t) => t.trim().toLowerCase()).some((tok) => {
|
|
12
|
+
if (!tok) return false;
|
|
13
|
+
if (tok.startsWith(".")) return name.endsWith(tok);
|
|
14
|
+
if (tok.endsWith("/*")) return type.startsWith(tok.slice(0, -1));
|
|
15
|
+
return type === tok;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function fmtSize(bytes) {
|
|
19
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
20
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
21
|
+
return `${(bytes / 1048576).toFixed(1)} MB`;
|
|
22
|
+
}
|
|
23
|
+
const GLYPHS = {
|
|
24
|
+
pdf: { Icon: FileText, color: "var(--status-error-fg)" },
|
|
25
|
+
doc: { Icon: FileText, color: "var(--status-info-fg)" },
|
|
26
|
+
docx: { Icon: FileText, color: "var(--status-info-fg)" },
|
|
27
|
+
rtf: { Icon: FileText, color: "var(--status-info-fg)" },
|
|
28
|
+
odt: { Icon: FileText, color: "var(--status-info-fg)" },
|
|
29
|
+
txt: { Icon: FileText, color: "var(--status-neutral-fg)" },
|
|
30
|
+
md: { Icon: FileText, color: "var(--status-neutral-fg)" },
|
|
31
|
+
csv: { Icon: FileSpreadsheet, color: "var(--status-success-fg)" },
|
|
32
|
+
xls: { Icon: FileSpreadsheet, color: "var(--status-success-fg)" },
|
|
33
|
+
xlsx: { Icon: FileSpreadsheet, color: "var(--status-success-fg)" },
|
|
34
|
+
ppt: { Icon: FileText, color: "var(--status-warning-fg)" },
|
|
35
|
+
pptx: { Icon: FileText, color: "var(--status-warning-fg)" },
|
|
36
|
+
zip: { Icon: FileArchive, color: "var(--status-warning-fg)" },
|
|
37
|
+
rar: { Icon: FileArchive, color: "var(--status-warning-fg)" },
|
|
38
|
+
"7z": { Icon: FileArchive, color: "var(--status-warning-fg)" }
|
|
39
|
+
};
|
|
40
|
+
function glyphFor(name) {
|
|
41
|
+
return GLYPHS[(name.split(".").pop() || "").toLowerCase()] ?? { Icon: FileIcon, color: "var(--status-neutral-fg)" };
|
|
42
|
+
}
|
|
43
|
+
function Thumb({ url, name, size, shape }) {
|
|
44
|
+
const { Icon, color } = glyphFor(name);
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
"span",
|
|
47
|
+
{
|
|
48
|
+
style: sx({
|
|
49
|
+
width: size,
|
|
50
|
+
height: size,
|
|
51
|
+
flex: "0 0 auto",
|
|
52
|
+
borderRadius: shape === "circle" ? "999px" : "var(--radius-md)",
|
|
53
|
+
overflow: "hidden",
|
|
54
|
+
display: "inline-flex",
|
|
55
|
+
alignItems: "center",
|
|
56
|
+
justifyContent: "center",
|
|
57
|
+
background: url ? "var(--bg-subtle)" : `color-mix(in srgb, ${color} 12%, var(--bg-surface))`,
|
|
58
|
+
border: "1px solid " + (url ? "var(--border-subtle)" : `color-mix(in srgb, ${color} 28%, transparent)`)
|
|
59
|
+
}),
|
|
60
|
+
children: url ? (
|
|
61
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
62
|
+
/* @__PURE__ */ jsx("img", { src: url, alt: name, style: sx({ width: "100%", height: "100%", objectFit: "cover" }) })
|
|
63
|
+
) : /* @__PURE__ */ jsx(Icon, { size: Math.round(size * 0.44), strokeWidth: 1.75, style: { color } })
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const actionBtn = {
|
|
68
|
+
display: "inline-flex",
|
|
69
|
+
alignItems: "center",
|
|
70
|
+
justifyContent: "center",
|
|
71
|
+
gap: 6,
|
|
72
|
+
minHeight: 36,
|
|
73
|
+
padding: "0 12px",
|
|
74
|
+
borderRadius: "var(--radius-control)",
|
|
75
|
+
border: "1px solid var(--border-default)",
|
|
76
|
+
background: "var(--bg-surface)",
|
|
77
|
+
fontFamily: "var(--font-body)",
|
|
78
|
+
fontSize: "var(--text-sm)",
|
|
79
|
+
fontWeight: "var(--weight-medium)",
|
|
80
|
+
cursor: "pointer"
|
|
81
|
+
};
|
|
82
|
+
function usePreviewUrl(file) {
|
|
83
|
+
const [url, setUrl] = React.useState(typeof file === "string" ? file : null);
|
|
84
|
+
React.useEffect(() => {
|
|
85
|
+
const isImageFile = file instanceof File && file.type.startsWith("image/");
|
|
86
|
+
const next = isImageFile ? URL.createObjectURL(file) : typeof file === "string" ? file : null;
|
|
87
|
+
setUrl(next);
|
|
88
|
+
return isImageFile ? () => URL.revokeObjectURL(next) : void 0;
|
|
89
|
+
}, [file]);
|
|
90
|
+
return url;
|
|
91
|
+
}
|
|
92
|
+
function fileKey(f) {
|
|
93
|
+
return `${f.name}:${f.size}:${f.lastModified}`;
|
|
94
|
+
}
|
|
95
|
+
function FileUpload(props) {
|
|
96
|
+
const {
|
|
97
|
+
label,
|
|
98
|
+
hint,
|
|
99
|
+
error,
|
|
100
|
+
required,
|
|
101
|
+
accept = "image/*",
|
|
102
|
+
maxSizeMB = 5,
|
|
103
|
+
shape = "square",
|
|
104
|
+
prompt,
|
|
105
|
+
disabled,
|
|
106
|
+
id,
|
|
107
|
+
containerStyle
|
|
108
|
+
} = props;
|
|
109
|
+
const multiple = props.multiple === true;
|
|
110
|
+
const inputRef = React.useRef(null);
|
|
111
|
+
const autoId = React.useId();
|
|
112
|
+
const rid = id || autoId;
|
|
113
|
+
const [rejected, setRejected] = React.useState(null);
|
|
114
|
+
const [dragOver, setDragOver] = React.useState(false);
|
|
115
|
+
const [internalOne, setInternalOne] = React.useState(null);
|
|
116
|
+
const [internalMany, setInternalMany] = React.useState([]);
|
|
117
|
+
const one = props.multiple ? null : props.value !== void 0 ? props.value : internalOne;
|
|
118
|
+
const many = props.multiple ? props.value !== void 0 ? props.value : internalMany : [];
|
|
119
|
+
const validate = (f) => {
|
|
120
|
+
if (!matchesAccept(f, accept)) return `\u201C${f.name}\u201D isn\u2019t an accepted type.`;
|
|
121
|
+
if (f.size > maxSizeMB * 1048576) return `\u201C${f.name}\u201D is over ${maxSizeMB} MB.`;
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
const ingest = (list) => {
|
|
125
|
+
const files = list ? Array.from(list) : [];
|
|
126
|
+
if (!files.length) return;
|
|
127
|
+
if (multiple) {
|
|
128
|
+
const ok = [];
|
|
129
|
+
const bad = [];
|
|
130
|
+
for (const f of files) {
|
|
131
|
+
const err = validate(f);
|
|
132
|
+
if (err) bad.push(f.name);
|
|
133
|
+
else ok.push(f);
|
|
134
|
+
}
|
|
135
|
+
setRejected(bad.length ? `Skipped ${bad.length} file${bad.length > 1 ? "s" : ""} (type or size).` : null);
|
|
136
|
+
const next = [...many, ...ok];
|
|
137
|
+
if (props.value === void 0) setInternalMany(next);
|
|
138
|
+
props.onChange?.(next);
|
|
139
|
+
} else {
|
|
140
|
+
const f = files[0];
|
|
141
|
+
const err = validate(f);
|
|
142
|
+
if (err) {
|
|
143
|
+
setRejected(err);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
setRejected(null);
|
|
147
|
+
if (props.value === void 0) setInternalOne(f);
|
|
148
|
+
props.onChange?.(f);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const removeAt = (i) => {
|
|
152
|
+
const next = many.filter((_, j) => j !== i);
|
|
153
|
+
if (props.value === void 0) setInternalMany(next);
|
|
154
|
+
props.onChange?.(next);
|
|
155
|
+
};
|
|
156
|
+
const clearOne = () => {
|
|
157
|
+
setRejected(null);
|
|
158
|
+
if (inputRef.current) inputRef.current.value = "";
|
|
159
|
+
if (props.value === void 0) setInternalOne(null);
|
|
160
|
+
props.onChange?.(null);
|
|
161
|
+
};
|
|
162
|
+
const openPicker = () => {
|
|
163
|
+
if (!disabled) inputRef.current?.click();
|
|
164
|
+
};
|
|
165
|
+
const oneUrl = usePreviewUrl(one);
|
|
166
|
+
const invalid = Boolean(error || rejected && !multiple);
|
|
167
|
+
const edge = dragOver ? "var(--border-brand)" : invalid ? "var(--interactive-error)" : "var(--border-default)";
|
|
168
|
+
const usePrompt = prompt ?? (multiple ? "Drag files here, or click to choose" : "Drag a file here, or click to choose");
|
|
169
|
+
const dragProps = disabled ? {} : {
|
|
170
|
+
onDragOver: (e) => {
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
setDragOver(true);
|
|
173
|
+
},
|
|
174
|
+
onDragLeave: () => setDragOver(false),
|
|
175
|
+
onDrop: (e) => {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
setDragOver(false);
|
|
178
|
+
ingest(e.dataTransfer.files);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const circleZone = /* @__PURE__ */ jsxs(
|
|
182
|
+
"button",
|
|
183
|
+
{
|
|
184
|
+
type: "button",
|
|
185
|
+
className: "ds-affix-btn",
|
|
186
|
+
disabled,
|
|
187
|
+
onClick: openPicker,
|
|
188
|
+
...dragProps,
|
|
189
|
+
style: sx({
|
|
190
|
+
display: "flex",
|
|
191
|
+
alignItems: "center",
|
|
192
|
+
justifyContent: "flex-start",
|
|
193
|
+
gap: "var(--space-4)",
|
|
194
|
+
width: "100%",
|
|
195
|
+
padding: 0,
|
|
196
|
+
border: "none",
|
|
197
|
+
background: "transparent",
|
|
198
|
+
fontFamily: "var(--font-body)",
|
|
199
|
+
textAlign: "left",
|
|
200
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
201
|
+
opacity: disabled ? 0.6 : 1
|
|
202
|
+
}),
|
|
203
|
+
children: [
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
"span",
|
|
206
|
+
{
|
|
207
|
+
style: sx({
|
|
208
|
+
width: 96,
|
|
209
|
+
height: 96,
|
|
210
|
+
flex: "0 0 auto",
|
|
211
|
+
borderRadius: "999px",
|
|
212
|
+
display: "inline-flex",
|
|
213
|
+
alignItems: "center",
|
|
214
|
+
justifyContent: "center",
|
|
215
|
+
color: dragOver ? "var(--text-brand)" : "var(--text-muted)",
|
|
216
|
+
border: "1.5px dashed " + edge,
|
|
217
|
+
background: dragOver ? "color-mix(in srgb, var(--interactive-primary) 5%, transparent)" : "transparent",
|
|
218
|
+
transition: "var(--transition-control)"
|
|
219
|
+
}),
|
|
220
|
+
children: /* @__PURE__ */ jsx(UploadCloud, { size: 24, strokeWidth: 1.75 })
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
/* @__PURE__ */ jsx("span", { style: sx({ fontSize: "var(--text-sm)", fontWeight: "var(--weight-medium)", color: "var(--text-primary)" }), children: usePrompt })
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
const boxZone = /* @__PURE__ */ jsxs(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
className: "ds-affix-btn",
|
|
232
|
+
disabled,
|
|
233
|
+
onClick: openPicker,
|
|
234
|
+
...dragProps,
|
|
235
|
+
style: sx({
|
|
236
|
+
display: "flex",
|
|
237
|
+
flexDirection: "column",
|
|
238
|
+
alignItems: "center",
|
|
239
|
+
justifyContent: "center",
|
|
240
|
+
gap: "var(--space-2)",
|
|
241
|
+
width: "100%",
|
|
242
|
+
boxSizing: "border-box",
|
|
243
|
+
padding: "var(--space-6) var(--space-4)",
|
|
244
|
+
borderRadius: "var(--radius-lg)",
|
|
245
|
+
border: "1.5px dashed " + edge,
|
|
246
|
+
background: dragOver ? "color-mix(in srgb, var(--interactive-primary) 5%, var(--bg-surface))" : "var(--bg-surface)",
|
|
247
|
+
fontFamily: "var(--font-body)",
|
|
248
|
+
textAlign: "center",
|
|
249
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
250
|
+
opacity: disabled ? 0.6 : 1,
|
|
251
|
+
transition: "var(--transition-control)"
|
|
252
|
+
}),
|
|
253
|
+
children: [
|
|
254
|
+
/* @__PURE__ */ jsx(UploadCloud, { size: 22, strokeWidth: 1.75, style: { color: dragOver ? "var(--text-brand)" : "var(--text-muted)" } }),
|
|
255
|
+
/* @__PURE__ */ jsx("span", { style: sx({ fontSize: "var(--text-sm)", color: "var(--text-secondary)", lineHeight: 1.4 }), children: usePrompt })
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
return /* @__PURE__ */ jsxs(Field, { label, hint, error: error || (multiple ? void 0 : rejected) || void 0, required, htmlFor: rid, style: containerStyle, children: [
|
|
260
|
+
/* @__PURE__ */ jsx(
|
|
261
|
+
"input",
|
|
262
|
+
{
|
|
263
|
+
ref: inputRef,
|
|
264
|
+
id: rid,
|
|
265
|
+
type: "file",
|
|
266
|
+
accept,
|
|
267
|
+
multiple,
|
|
268
|
+
disabled,
|
|
269
|
+
onChange: (e) => ingest(e.target.files),
|
|
270
|
+
style: { display: "none" }
|
|
271
|
+
}
|
|
272
|
+
),
|
|
273
|
+
multiple ? /* @__PURE__ */ jsxs("div", { style: sx({ display: "flex", flexDirection: "column", gap: "var(--space-3)" }), children: [
|
|
274
|
+
boxZone,
|
|
275
|
+
many.length > 0 && /* @__PURE__ */ jsx("ul", { style: sx({ listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: "var(--space-2)" }), children: many.map((f, i) => /* @__PURE__ */ jsx(MultiRow, { file: f, disabled, onRemove: () => removeAt(i) }, fileKey(f))) }),
|
|
276
|
+
rejected && /* @__PURE__ */ jsx("span", { style: sx({ fontFamily: "var(--font-body)", fontSize: "var(--text-xs)", color: "var(--text-muted)" }), children: rejected })
|
|
277
|
+
] }) : one ? /* @__PURE__ */ jsxs("div", { style: sx({ display: "flex", alignItems: "flex-start", gap: "var(--space-4)" }), children: [
|
|
278
|
+
/* @__PURE__ */ jsx(Thumb, { url: oneUrl, name: typeof one === "string" ? one.split("/").pop() || one : one.name, size: shape === "circle" ? 88 : 96, shape }),
|
|
279
|
+
/* @__PURE__ */ jsxs("div", { style: sx({ flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: 4 }), children: [
|
|
280
|
+
/* @__PURE__ */ jsx(
|
|
281
|
+
"span",
|
|
282
|
+
{
|
|
283
|
+
style: sx({
|
|
284
|
+
fontFamily: "var(--font-body)",
|
|
285
|
+
fontSize: "var(--text-sm)",
|
|
286
|
+
color: "var(--text-primary)",
|
|
287
|
+
whiteSpace: "nowrap",
|
|
288
|
+
overflow: "hidden",
|
|
289
|
+
textOverflow: "ellipsis"
|
|
290
|
+
}),
|
|
291
|
+
title: typeof one === "string" ? one.split("/").pop() || one : one.name,
|
|
292
|
+
children: typeof one === "string" ? one.split("/").pop() || one : one.name
|
|
293
|
+
}
|
|
294
|
+
),
|
|
295
|
+
one instanceof File && /* @__PURE__ */ jsx("span", { style: sx({ fontFamily: "var(--font-body)", fontSize: "var(--text-xs)", color: "var(--text-muted)" }), children: fmtSize(one.size) }),
|
|
296
|
+
!disabled && /* @__PURE__ */ jsxs("div", { style: sx({ display: "flex", gap: "var(--space-2)", marginTop: 6, flexWrap: "wrap" }), children: [
|
|
297
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "ds-affix-btn", onClick: openPicker, style: { ...actionBtn, color: "var(--text-primary)" }, children: [
|
|
298
|
+
/* @__PURE__ */ jsx(RefreshCw, { size: 14, strokeWidth: 2 }),
|
|
299
|
+
" Replace"
|
|
300
|
+
] }),
|
|
301
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "ds-affix-btn", onClick: clearOne, style: { ...actionBtn, color: "var(--interactive-error)" }, children: [
|
|
302
|
+
/* @__PURE__ */ jsx(Trash2, { size: 14, strokeWidth: 2 }),
|
|
303
|
+
" Remove"
|
|
304
|
+
] })
|
|
305
|
+
] })
|
|
306
|
+
] })
|
|
307
|
+
] }) : shape === "circle" ? circleZone : boxZone
|
|
308
|
+
] });
|
|
309
|
+
}
|
|
310
|
+
function MultiRow({ file, disabled, onRemove }) {
|
|
311
|
+
const url = usePreviewUrl(file);
|
|
312
|
+
return /* @__PURE__ */ jsxs(
|
|
313
|
+
"li",
|
|
314
|
+
{
|
|
315
|
+
style: sx({
|
|
316
|
+
display: "flex",
|
|
317
|
+
alignItems: "center",
|
|
318
|
+
gap: "var(--space-3)",
|
|
319
|
+
padding: "var(--space-2)",
|
|
320
|
+
borderRadius: "var(--radius-md)",
|
|
321
|
+
border: "1px solid var(--border-subtle)",
|
|
322
|
+
background: "var(--bg-surface)"
|
|
323
|
+
}),
|
|
324
|
+
children: [
|
|
325
|
+
/* @__PURE__ */ jsx(Thumb, { url, name: file.name, size: 44, shape: "square" }),
|
|
326
|
+
/* @__PURE__ */ jsxs("span", { style: sx({ flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: 1 }), children: [
|
|
327
|
+
/* @__PURE__ */ jsx(
|
|
328
|
+
"span",
|
|
329
|
+
{
|
|
330
|
+
style: sx({
|
|
331
|
+
fontFamily: "var(--font-body)",
|
|
332
|
+
fontSize: "var(--text-sm)",
|
|
333
|
+
color: "var(--text-primary)",
|
|
334
|
+
minWidth: 0,
|
|
335
|
+
maxWidth: "100%",
|
|
336
|
+
whiteSpace: "nowrap",
|
|
337
|
+
overflow: "hidden",
|
|
338
|
+
textOverflow: "ellipsis"
|
|
339
|
+
}),
|
|
340
|
+
title: file.name,
|
|
341
|
+
children: file.name
|
|
342
|
+
}
|
|
343
|
+
),
|
|
344
|
+
/* @__PURE__ */ jsx("span", { style: sx({ fontFamily: "var(--font-body)", fontSize: "var(--text-xs)", color: "var(--text-muted)" }), children: fmtSize(file.size) })
|
|
345
|
+
] }),
|
|
346
|
+
!disabled && /* @__PURE__ */ jsx(
|
|
347
|
+
"button",
|
|
348
|
+
{
|
|
349
|
+
type: "button",
|
|
350
|
+
className: "ds-affix-btn",
|
|
351
|
+
"aria-label": `Remove ${file.name}`,
|
|
352
|
+
onClick: onRemove,
|
|
353
|
+
style: sx({
|
|
354
|
+
flex: "0 0 auto",
|
|
355
|
+
width: 36,
|
|
356
|
+
height: 36,
|
|
357
|
+
display: "inline-flex",
|
|
358
|
+
alignItems: "center",
|
|
359
|
+
justifyContent: "center",
|
|
360
|
+
borderRadius: "var(--radius-control)",
|
|
361
|
+
border: "1px solid transparent",
|
|
362
|
+
background: "transparent",
|
|
363
|
+
color: "var(--interactive-error)",
|
|
364
|
+
cursor: "pointer"
|
|
365
|
+
}),
|
|
366
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 16, strokeWidth: 1.75 })
|
|
367
|
+
}
|
|
368
|
+
)
|
|
369
|
+
]
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
export {
|
|
374
|
+
FileUpload
|
|
375
|
+
};
|
|
376
|
+
//# sourceMappingURL=FileUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/forms/FileUpload.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { File as FileIcon, FileArchive, FileSpreadsheet, FileText, RefreshCw, Trash2, UploadCloud, type LucideIcon } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\n\n/**\n * Pick files — click, keyboard, or drag-and-drop — with a local preview.\n * Image-first (`shape` circle/square thumbnail); other types show an extension\n * chip. No upload happens here: `onChange` hands you the `File`(s); the preview\n * is local. Set `multiple` for a list; `value` then is `File[]`.\n */\ninterface BaseProps {\n label?: string;\n /** Helper text under the field — a good place for the accepted types / size. */\n hint?: string;\n /** Error message; also shown instead of a rejected-file message. */\n error?: string;\n required?: boolean;\n /** `accept` attribute, also enforced on drop. */\n accept?: string;\n /** Max size in MB — files above this are rejected with a message. */\n maxSizeMB?: number;\n /** Thumbnail shape for image previews. `circle` for avatars (single only). */\n shape?: 'circle' | 'square';\n /** Prompt inside the empty drop area. */\n prompt?: string;\n disabled?: boolean;\n id?: string;\n containerStyle?: React.CSSProperties;\n}\n\nexport type FileUploadProps = BaseProps &\n (\n | { multiple?: false; value?: File | string | null; onChange?: (file: File | null) => void }\n | { multiple: true; value?: File[]; onChange?: (files: File[]) => void }\n );\n\nfunction matchesAccept(file: File, accept: string): boolean {\n if (!accept || accept === '*' || accept === '*/*') return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return accept\n .split(',')\n .map((t) => t.trim().toLowerCase())\n .some((tok) => {\n if (!tok) return false;\n if (tok.startsWith('.')) return name.endsWith(tok);\n if (tok.endsWith('/*')) return type.startsWith(tok.slice(0, -1));\n return type === tok;\n });\n}\n\nfunction fmtSize(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;\n return `${(bytes / 1048576).toFixed(1)} MB`;\n}\n\n/** File-type glyph + colour, keyed by extension. Images never reach this. */\nconst GLYPHS: Record<string, { Icon: LucideIcon; color: string }> = {\n pdf: { Icon: FileText, color: 'var(--status-error-fg)' },\n doc: { Icon: FileText, color: 'var(--status-info-fg)' },\n docx: { Icon: FileText, color: 'var(--status-info-fg)' },\n rtf: { Icon: FileText, color: 'var(--status-info-fg)' },\n odt: { Icon: FileText, color: 'var(--status-info-fg)' },\n txt: { Icon: FileText, color: 'var(--status-neutral-fg)' },\n md: { Icon: FileText, color: 'var(--status-neutral-fg)' },\n csv: { Icon: FileSpreadsheet, color: 'var(--status-success-fg)' },\n xls: { Icon: FileSpreadsheet, color: 'var(--status-success-fg)' },\n xlsx: { Icon: FileSpreadsheet, color: 'var(--status-success-fg)' },\n ppt: { Icon: FileText, color: 'var(--status-warning-fg)' },\n pptx: { Icon: FileText, color: 'var(--status-warning-fg)' },\n zip: { Icon: FileArchive, color: 'var(--status-warning-fg)' },\n rar: { Icon: FileArchive, color: 'var(--status-warning-fg)' },\n '7z': { Icon: FileArchive, color: 'var(--status-warning-fg)' },\n};\nfunction glyphFor(name: string) {\n return GLYPHS[(name.split('.').pop() || '').toLowerCase()] ?? { Icon: FileIcon, color: 'var(--status-neutral-fg)' };\n}\n\n/** One thumbnail — the image itself, or a colour-coded file-type glyph. */\nfunction Thumb({ url, name, size, shape }: { url: string | null; name: string; size: number; shape: 'circle' | 'square' }) {\n const { Icon, color } = glyphFor(name);\n return (\n <span\n style={sx({\n width: size,\n height: size,\n flex: '0 0 auto',\n borderRadius: shape === 'circle' ? '999px' : 'var(--radius-md)',\n overflow: 'hidden',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: url ? 'var(--bg-subtle)' : `color-mix(in srgb, ${color} 12%, var(--bg-surface))`,\n border: '1px solid ' + (url ? 'var(--border-subtle)' : `color-mix(in srgb, ${color} 28%, transparent)`),\n })}\n >\n {url ? (\n // eslint-disable-next-line @next/next/no-img-element\n <img src={url} alt={name} style={sx({ width: '100%', height: '100%', objectFit: 'cover' })} />\n ) : (\n <Icon size={Math.round(size * 0.44)} strokeWidth={1.75} style={{ color }} />\n )}\n </span>\n );\n}\n\nconst actionBtn = {\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 6,\n minHeight: 36,\n padding: '0 12px',\n borderRadius: 'var(--radius-control)',\n border: '1px solid var(--border-default)',\n background: 'var(--bg-surface)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-medium)',\n cursor: 'pointer',\n} as const;\n\n/**\n * A preview URL for a File (object URL) or an existing URL string. The object\n * URL is created *and* revoked inside one effect, so a re-render (or StrictMode's\n * mount/cleanup/mount) never leaves a revoked URL on screen.\n */\nfunction usePreviewUrl(file: File | string | null | undefined): string | null {\n const [url, setUrl] = React.useState<string | null>(typeof file === 'string' ? file : null);\n React.useEffect(() => {\n const isImageFile = file instanceof File && file.type.startsWith('image/');\n const next = isImageFile ? URL.createObjectURL(file) : typeof file === 'string' ? file : null;\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to an external resource (object URL)\n setUrl(next);\n return isImageFile ? () => URL.revokeObjectURL(next as string) : undefined;\n }, [file]);\n return url;\n}\n\n/** A stable-ish key for a File across list reorders. */\nfunction fileKey(f: File): string {\n return `${f.name}:${f.size}:${f.lastModified}`;\n}\n\nexport function FileUpload(props: FileUploadProps) {\n const {\n label,\n hint,\n error,\n required,\n accept = 'image/*',\n maxSizeMB = 5,\n shape = 'square',\n prompt,\n disabled,\n id,\n containerStyle,\n } = props;\n const multiple = props.multiple === true;\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const autoId = React.useId();\n const rid = id || autoId;\n const [rejected, setRejected] = React.useState<string | null>(null);\n const [dragOver, setDragOver] = React.useState(false);\n\n // Uncontrolled fallback — one shape covers both modes internally.\n const [internalOne, setInternalOne] = React.useState<File | null>(null);\n const [internalMany, setInternalMany] = React.useState<File[]>([]);\n const one = props.multiple ? null : props.value !== undefined ? props.value : internalOne;\n const many = props.multiple ? (props.value !== undefined ? props.value : internalMany) : [];\n\n const validate = (f: File): string | null => {\n if (!matchesAccept(f, accept)) return `“${f.name}” isn’t an accepted type.`;\n if (f.size > maxSizeMB * 1048576) return `“${f.name}” is over ${maxSizeMB} MB.`;\n return null;\n };\n\n const ingest = (list: FileList | null) => {\n const files = list ? Array.from(list) : [];\n if (!files.length) return;\n if (multiple) {\n const ok: File[] = [];\n const bad: string[] = [];\n for (const f of files) {\n const err = validate(f);\n if (err) bad.push(f.name);\n else ok.push(f);\n }\n setRejected(bad.length ? `Skipped ${bad.length} file${bad.length > 1 ? 's' : ''} (type or size).` : null);\n const next = [...many, ...ok];\n if (props.value === undefined) setInternalMany(next);\n props.onChange?.(next);\n } else {\n const f = files[0];\n const err = validate(f);\n if (err) {\n setRejected(err);\n return;\n }\n setRejected(null);\n if (props.value === undefined) setInternalOne(f);\n props.onChange?.(f);\n }\n };\n\n const removeAt = (i: number) => {\n const next = many.filter((_, j) => j !== i);\n if (props.value === undefined) setInternalMany(next);\n (props.onChange as ((f: File[]) => void) | undefined)?.(next);\n };\n const clearOne = () => {\n setRejected(null);\n if (inputRef.current) inputRef.current.value = '';\n if (props.value === undefined) setInternalOne(null);\n (props.onChange as ((f: File | null) => void) | undefined)?.(null);\n };\n const openPicker = () => {\n if (!disabled) inputRef.current?.click();\n };\n\n const oneUrl = usePreviewUrl(one);\n\n // A hard `error` (or a rejected single file) puts the field in an error state;\n // a \"skipped N\" note in multiple mode is informational, not an error.\n const invalid = Boolean(error || (rejected && !multiple));\n const edge = dragOver ? 'var(--border-brand)' : invalid ? 'var(--interactive-error)' : 'var(--border-default)';\n const usePrompt = prompt ?? (multiple ? 'Drag files here, or click to choose' : 'Drag a file here, or click to choose');\n\n const dragProps = disabled\n ? {}\n : {\n onDragOver: (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(true);\n },\n onDragLeave: () => setDragOver(false),\n onDrop: (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n ingest(e.dataTransfer.files);\n },\n };\n\n // ---- the drop zone (shown when empty in single mode, always in multiple) ----\n const circleZone = (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n disabled={disabled}\n onClick={openPicker}\n {...dragProps}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'flex-start',\n gap: 'var(--space-4)',\n width: '100%',\n padding: 0,\n border: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n textAlign: 'left',\n cursor: disabled ? 'not-allowed' : 'pointer',\n opacity: disabled ? 0.6 : 1,\n })}\n >\n <span\n style={sx({\n width: 96,\n height: 96,\n flex: '0 0 auto',\n borderRadius: '999px',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n color: dragOver ? 'var(--text-brand)' : 'var(--text-muted)',\n border: '1.5px dashed ' + edge,\n background: dragOver ? 'color-mix(in srgb, var(--interactive-primary) 5%, transparent)' : 'transparent',\n transition: 'var(--transition-control)',\n })}\n >\n <UploadCloud size={24} strokeWidth={1.75} />\n </span>\n <span style={sx({ fontSize: 'var(--text-sm)', fontWeight: 'var(--weight-medium)', color: 'var(--text-primary)' })}>{usePrompt}</span>\n </button>\n );\n\n const boxZone = (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n disabled={disabled}\n onClick={openPicker}\n {...dragProps}\n style={sx({\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 'var(--space-2)',\n width: '100%',\n boxSizing: 'border-box',\n padding: 'var(--space-6) var(--space-4)',\n borderRadius: 'var(--radius-lg)',\n border: '1.5px dashed ' + edge,\n background: dragOver ? 'color-mix(in srgb, var(--interactive-primary) 5%, var(--bg-surface))' : 'var(--bg-surface)',\n fontFamily: 'var(--font-body)',\n textAlign: 'center',\n cursor: disabled ? 'not-allowed' : 'pointer',\n opacity: disabled ? 0.6 : 1,\n transition: 'var(--transition-control)',\n })}\n >\n <UploadCloud size={22} strokeWidth={1.75} style={{ color: dragOver ? 'var(--text-brand)' : 'var(--text-muted)' }} />\n <span style={sx({ fontSize: 'var(--text-sm)', color: 'var(--text-secondary)', lineHeight: 1.4 })}>{usePrompt}</span>\n </button>\n );\n\n return (\n <Field label={label} hint={hint} error={error || (multiple ? undefined : rejected) || undefined} required={required} htmlFor={rid} style={containerStyle}>\n <input\n ref={inputRef}\n id={rid}\n type=\"file\"\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n onChange={(e) => ingest(e.target.files)}\n style={{ display: 'none' }}\n />\n\n {multiple ? (\n <div style={sx({ display: 'flex', flexDirection: 'column', gap: 'var(--space-3)' })}>\n {boxZone}\n {many.length > 0 && (\n <ul style={sx({ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 'var(--space-2)' })}>\n {many.map((f, i) => (\n <MultiRow key={fileKey(f)} file={f} disabled={disabled} onRemove={() => removeAt(i)} />\n ))}\n </ul>\n )}\n {rejected && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-xs)', color: 'var(--text-muted)' })}>{rejected}</span>}\n </div>\n ) : one ? (\n <div style={sx({ display: 'flex', alignItems: 'flex-start', gap: 'var(--space-4)' })}>\n <Thumb url={oneUrl} name={typeof one === 'string' ? one.split('/').pop() || one : one.name} size={shape === 'circle' ? 88 : 96} shape={shape} />\n <div style={sx({ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 4 })}>\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n color: 'var(--text-primary)',\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n })}\n title={typeof one === 'string' ? one.split('/').pop() || one : one.name}\n >\n {typeof one === 'string' ? one.split('/').pop() || one : one.name}\n </span>\n {one instanceof File && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-xs)', color: 'var(--text-muted)' })}>{fmtSize(one.size)}</span>}\n {!disabled && (\n <div style={sx({ display: 'flex', gap: 'var(--space-2)', marginTop: 6, flexWrap: 'wrap' })}>\n <button type=\"button\" className=\"ds-affix-btn\" onClick={openPicker} style={{ ...actionBtn, color: 'var(--text-primary)' }}>\n <RefreshCw size={14} strokeWidth={2} /> Replace\n </button>\n <button type=\"button\" className=\"ds-affix-btn\" onClick={clearOne} style={{ ...actionBtn, color: 'var(--interactive-error)' }}>\n <Trash2 size={14} strokeWidth={2} /> Remove\n </button>\n </div>\n )}\n </div>\n </div>\n ) : shape === 'circle' ? (\n circleZone\n ) : (\n boxZone\n )}\n </Field>\n );\n}\n\nfunction MultiRow({ file, disabled, onRemove }: { file: File; disabled?: boolean; onRemove: () => void }) {\n const url = usePreviewUrl(file);\n return (\n <li\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-3)',\n padding: 'var(--space-2)',\n borderRadius: 'var(--radius-md)',\n border: '1px solid var(--border-subtle)',\n background: 'var(--bg-surface)',\n })}\n >\n <Thumb url={url} name={file.name} size={44} shape=\"square\" />\n <span style={sx({ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 })}>\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n color: 'var(--text-primary)',\n minWidth: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n })}\n title={file.name}\n >\n {file.name}\n </span>\n <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-xs)', color: 'var(--text-muted)' })}>{fmtSize(file.size)}</span>\n </span>\n {!disabled && (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={`Remove ${file.name}`}\n onClick={onRemove}\n style={sx({\n flex: '0 0 auto',\n width: 36,\n height: 36,\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderRadius: 'var(--radius-control)',\n border: '1px solid transparent',\n background: 'transparent',\n color: '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askName } from '../_internal/mask.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Single-line text field with label, hint and error states.
|
|
6
|
+
*/
|
|
7
|
+
interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'> {
|
|
8
|
+
label?: string;
|
|
9
|
+
/** Helper text under the field. Replaced by `error` when present. */
|
|
10
|
+
hint?: string;
|
|
11
|
+
/** Error message; also turns the border red. */
|
|
12
|
+
error?: string;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
size?: 'sm' | 'md' | 'lg';
|
|
15
|
+
iconLeft?: React.ReactNode;
|
|
16
|
+
/** Leading text adornment (e.g. "R$", "@", "+55"). Not part of the value. */
|
|
17
|
+
prefix?: React.ReactNode;
|
|
18
|
+
/** Trailing text or control (e.g. "min", a clear button). Not part of the value. */
|
|
19
|
+
suffix?: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Format the value as the user types. A preset (`phone` / `cpf` / `cep` /
|
|
22
|
+
* `currency`) or a custom pattern where `#` is one digit (`(##) #####-####`).
|
|
23
|
+
* Sets `inputMode` and `maxLength` unless you pass your own.
|
|
24
|
+
*/
|
|
25
|
+
mask?: MaskName | string;
|
|
26
|
+
/**
|
|
27
|
+
* Show a `n / max` character counter on the hint row. Implied when `maxLength`
|
|
28
|
+
* is set; pass `showCount` on its own for a bare count with no ceiling.
|
|
29
|
+
*/
|
|
30
|
+
showCount?: boolean;
|
|
31
|
+
containerStyle?: React.CSSProperties;
|
|
32
|
+
}
|
|
33
|
+
declare function Input({ label, hint, error, required, size, iconLeft, prefix, suffix, disabled, id, style, containerStyle, mask, showCount, type, onChange, inputMode, maxLength, defaultValue, ...rest }: InputProps): React.JSX.Element;
|
|
34
|
+
|
|
35
|
+
export { Input, type InputProps };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Eye, EyeOff } from "lucide-react";
|
|
5
|
+
import { sx } from "../_internal/style";
|
|
6
|
+
import { Field } from "../_internal/Field";
|
|
7
|
+
import { CharCount } from "../_internal/CharCount";
|
|
8
|
+
import { formatMask, MASK_INPUTMODE, MASK_MAXLENGTH } from "../_internal/mask";
|
|
9
|
+
const H = { sm: "var(--control-height-sm)", md: "var(--control-height-md)", lg: "var(--control-height-lg)" };
|
|
10
|
+
function Input({
|
|
11
|
+
label,
|
|
12
|
+
hint,
|
|
13
|
+
error,
|
|
14
|
+
required,
|
|
15
|
+
size = "md",
|
|
16
|
+
iconLeft,
|
|
17
|
+
prefix,
|
|
18
|
+
suffix,
|
|
19
|
+
disabled,
|
|
20
|
+
id,
|
|
21
|
+
style,
|
|
22
|
+
containerStyle,
|
|
23
|
+
mask,
|
|
24
|
+
showCount,
|
|
25
|
+
type,
|
|
26
|
+
onChange,
|
|
27
|
+
inputMode,
|
|
28
|
+
maxLength,
|
|
29
|
+
defaultValue,
|
|
30
|
+
...rest
|
|
31
|
+
}) {
|
|
32
|
+
const [focus, setFocus] = React.useState(false);
|
|
33
|
+
const [reveal, setReveal] = React.useState(false);
|
|
34
|
+
const inputRef = React.useRef(null);
|
|
35
|
+
const autoId = React.useId();
|
|
36
|
+
const rid = id || autoId;
|
|
37
|
+
const isPassword = type === "password";
|
|
38
|
+
const showCounter = Boolean(showCount) || maxLength != null;
|
|
39
|
+
const seed = mask && typeof defaultValue === "string" ? formatMask(mask, defaultValue) : defaultValue;
|
|
40
|
+
const [uncount, setUncount] = React.useState(
|
|
41
|
+
() => typeof seed === "string" || typeof seed === "number" ? String(seed).length : 0
|
|
42
|
+
);
|
|
43
|
+
const count = rest.value !== void 0 ? String(rest.value ?? "").length : uncount;
|
|
44
|
+
const needsWrap = Boolean(mask) || showCounter;
|
|
45
|
+
const handleChange = needsWrap ? (e) => {
|
|
46
|
+
if (mask) {
|
|
47
|
+
const formatted = formatMask(mask, e.currentTarget.value);
|
|
48
|
+
if (formatted !== e.currentTarget.value) {
|
|
49
|
+
const el = e.currentTarget;
|
|
50
|
+
el.value = formatted;
|
|
51
|
+
try {
|
|
52
|
+
el.setSelectionRange(formatted.length, formatted.length);
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (rest.value === void 0) setUncount(e.currentTarget.value.length);
|
|
58
|
+
onChange?.(e);
|
|
59
|
+
} : onChange;
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
Field,
|
|
62
|
+
{
|
|
63
|
+
label,
|
|
64
|
+
hint,
|
|
65
|
+
error,
|
|
66
|
+
required,
|
|
67
|
+
htmlFor: rid,
|
|
68
|
+
style: containerStyle,
|
|
69
|
+
counter: showCounter ? /* @__PURE__ */ jsx(CharCount, { count, max: maxLength ?? void 0 }) : void 0,
|
|
70
|
+
children: /* @__PURE__ */ jsxs(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
style: sx({
|
|
74
|
+
display: "flex",
|
|
75
|
+
alignItems: "center",
|
|
76
|
+
gap: "var(--space-2)",
|
|
77
|
+
height: H[size] || H.md,
|
|
78
|
+
padding: "0 var(--space-3)",
|
|
79
|
+
borderRadius: "var(--radius-control)",
|
|
80
|
+
background: disabled ? "var(--interactive-disabled-bg)" : "var(--bg-surface)",
|
|
81
|
+
border: "var(--border-width-hairline) solid " + (error ? "var(--interactive-error)" : focus ? "var(--border-focus)" : "var(--border-default)"),
|
|
82
|
+
boxShadow: focus ? error ? "none" : "var(--focus-ring)" : "none",
|
|
83
|
+
transition: "var(--transition-control)"
|
|
84
|
+
}),
|
|
85
|
+
children: [
|
|
86
|
+
iconLeft && /* @__PURE__ */ jsx("span", { style: sx({ display: "flex", color: "var(--text-muted)", flex: "0 0 auto" }), children: iconLeft }),
|
|
87
|
+
prefix && /* @__PURE__ */ jsx("span", { style: sx({ display: "flex", alignItems: "center", color: "var(--text-muted)", fontSize: size === "sm" ? "var(--text-sm)" : "var(--text-base)", lineHeight: 1.2, flex: "0 0 auto" }), children: prefix }),
|
|
88
|
+
/* @__PURE__ */ jsx(
|
|
89
|
+
"input",
|
|
90
|
+
{
|
|
91
|
+
id: rid,
|
|
92
|
+
ref: inputRef,
|
|
93
|
+
type: isPassword && reveal ? "text" : type,
|
|
94
|
+
disabled,
|
|
95
|
+
onFocus: () => setFocus(true),
|
|
96
|
+
onBlur: () => setFocus(false),
|
|
97
|
+
onChange: handleChange,
|
|
98
|
+
inputMode: mask ? inputMode ?? MASK_INPUTMODE[mask] ?? "numeric" : inputMode,
|
|
99
|
+
maxLength: mask ? maxLength ?? MASK_MAXLENGTH[mask] : maxLength,
|
|
100
|
+
defaultValue: mask && typeof defaultValue === "string" ? formatMask(mask, defaultValue) : defaultValue,
|
|
101
|
+
...rest,
|
|
102
|
+
style: sx({
|
|
103
|
+
flex: 1,
|
|
104
|
+
minWidth: 0,
|
|
105
|
+
margin: 0,
|
|
106
|
+
padding: 0,
|
|
107
|
+
// reset the UA input padding — the row's own padding insets it
|
|
108
|
+
border: "none",
|
|
109
|
+
outline: "none",
|
|
110
|
+
background: "transparent",
|
|
111
|
+
fontFamily: "var(--font-body)",
|
|
112
|
+
fontSize: size === "sm" ? "var(--text-sm)" : "var(--text-base)",
|
|
113
|
+
lineHeight: 1.2,
|
|
114
|
+
// match the prefix/suffix line box so baselines align
|
|
115
|
+
color: disabled ? "var(--text-disabled)" : "var(--text-primary)",
|
|
116
|
+
...style
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
isPassword ? /* @__PURE__ */ jsx(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
type: "button",
|
|
124
|
+
className: "ds-affix-btn",
|
|
125
|
+
"aria-label": reveal ? "Ocultar senha" : "Mostrar senha",
|
|
126
|
+
"aria-pressed": reveal,
|
|
127
|
+
onClick: () => {
|
|
128
|
+
setReveal((r) => !r);
|
|
129
|
+
inputRef.current?.focus();
|
|
130
|
+
},
|
|
131
|
+
children: reveal ? /* @__PURE__ */ jsx(EyeOff, { size: 16, strokeWidth: 1.75 }) : /* @__PURE__ */ jsx(Eye, { size: 16, strokeWidth: 1.75 })
|
|
132
|
+
}
|
|
133
|
+
) : suffix && /* @__PURE__ */ jsx("span", { style: sx({ display: "flex", alignItems: "center", color: "var(--text-muted)", fontSize: size === "sm" ? "var(--text-sm)" : "var(--text-base)", lineHeight: 1.2, flex: "0 0 auto" }), children: suffix })
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
Input
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=Input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/forms/Input.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Eye, EyeOff } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { CharCount } from '../_internal/CharCount';\nimport { formatMask, MASK_INPUTMODE, MASK_MAXLENGTH, type MaskName } from '../_internal/mask';\n\n/**\n * Single-line text field with label, hint and error states.\n */\nexport interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'> {\n label?: string;\n /** Helper text under the field. Replaced by `error` when present. */\n hint?: string;\n /** Error message; also turns the border red. */\n error?: string;\n required?: boolean;\n size?: 'sm' | 'md' | 'lg';\n iconLeft?: React.ReactNode;\n /** Leading text adornment (e.g. \"R$\", \"@\", \"+55\"). Not part of the value. */\n prefix?: React.ReactNode;\n /** Trailing text or control (e.g. \"min\", a clear button). Not part of the value. */\n suffix?: React.ReactNode;\n /**\n * Format the value as the user types. A preset (`phone` / `cpf` / `cep` /\n * `currency`) or a custom pattern where `#` is one digit (`(##) #####-####`).\n * Sets `inputMode` and `maxLength` unless you pass your own.\n */\n mask?: MaskName | string;\n /**\n * Show a `n / max` character counter on the hint row. Implied when `maxLength`\n * is set; pass `showCount` on its own for a bare count with no ceiling.\n */\n showCount?: boolean;\n containerStyle?: React.CSSProperties;\n}\n\nconst H = { sm: 'var(--control-height-sm)', md: 'var(--control-height-md)', lg: 'var(--control-height-lg)' } as const;\n\nexport function Input({\n label,\n hint,\n error,\n required,\n size = 'md',\n iconLeft,\n prefix,\n suffix,\n disabled,\n id,\n style,\n containerStyle,\n mask,\n showCount,\n type,\n onChange,\n inputMode,\n maxLength,\n defaultValue,\n ...rest\n}: InputProps) {\n const [focus, setFocus] = React.useState(false);\n const [reveal, setReveal] = React.useState(false);\n const inputRef = React.useRef<HTMLInputElement>(null);\n // SSR-stable id (the DS source used Math.random(), which breaks hydration).\n const autoId = React.useId();\n const rid = id || autoId;\n\n const isPassword = type === 'password';\n const showCounter = Boolean(showCount) || maxLength != null;\n\n const seed = mask && typeof defaultValue === 'string' ? formatMask(mask, defaultValue) : defaultValue;\n const [uncount, setUncount] = React.useState(() =>\n typeof seed === 'string' || typeof seed === 'number' ? String(seed).length : 0,\n );\n const count = rest.value !== undefined ? String(rest.value ?? '').length : uncount;\n\n const needsWrap = Boolean(mask) || showCounter;\n const handleChange = needsWrap\n ? (e: React.ChangeEvent<HTMLInputElement>) => {\n if (mask) {\n const formatted = formatMask(mask, e.currentTarget.value);\n if (formatted !== e.currentTarget.value) {\n const el = e.currentTarget;\n el.value = formatted;\n // keep the caret at the end — the natural spot while typing forward\n try {\n el.setSelectionRange(formatted.length, formatted.length);\n } catch {\n /* type doesn't support selection */\n }\n }\n }\n if (rest.value === undefined) setUncount(e.currentTarget.value.length);\n onChange?.(e);\n }\n : onChange;\n\n return (\n <Field\n label={label}\n hint={hint}\n error={error}\n required={required}\n htmlFor={rid}\n style={containerStyle}\n counter={showCounter ? <CharCount count={count} max={maxLength ?? undefined} /> : undefined}\n >\n <div\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n height: H[size] || H.md,\n padding: '0 var(--space-3)',\n borderRadius: 'var(--radius-control)',\n background: disabled ? 'var(--interactive-disabled-bg)' : 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid ' + (error ? 'var(--interactive-error)' : focus ? 'var(--border-focus)' : 'var(--border-default)'),\n boxShadow: focus ? (error ? 'none' : 'var(--focus-ring)') : 'none',\n transition: 'var(--transition-control)',\n })}\n >\n {iconLeft && <span style={sx({ display: 'flex', color: 'var(--text-muted)', flex: '0 0 auto' })}>{iconLeft}</span>}\n {prefix && (\n <span style={sx({ display: 'flex', alignItems: 'center', color: 'var(--text-muted)', fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)', lineHeight: 1.2, flex: '0 0 auto' })}>{prefix}</span>\n )}\n <input\n id={rid}\n ref={inputRef}\n type={isPassword && reveal ? 'text' : type}\n disabled={disabled}\n onFocus={() => setFocus(true)}\n onBlur={() => setFocus(false)}\n onChange={handleChange}\n inputMode={mask ? inputMode ?? MASK_INPUTMODE[mask] ?? 'numeric' : inputMode}\n maxLength={mask ? maxLength ?? MASK_MAXLENGTH[mask] : maxLength}\n defaultValue={mask && typeof defaultValue === 'string' ? formatMask(mask, defaultValue) : defaultValue}\n {...rest}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding — the row's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)',\n lineHeight: 1.2, // match the prefix/suffix line box so baselines align\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n ...style,\n })}\n />\n {isPassword ? (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={reveal ? 'Ocultar senha' : 'Mostrar senha'}\n aria-pressed={reveal}\n onClick={() => {\n setReveal((r) => !r);\n inputRef.current?.focus();\n }}\n >\n {reveal ? <EyeOff size={16} strokeWidth={1.75} /> : <Eye size={16} strokeWidth={1.75} />}\n </button>\n ) : (\n suffix && (\n <span style={sx({ display: 'flex', alignItems: 'center', color: 'var(--text-muted)', fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)', lineHeight: 1.2, flex: '0 0 auto' })}>{suffix}</span>\n )\n )}\n </div>\n </Field>\n );\n}\n"],"mappings":";AA4G6B,cAEvB,YAFuB;AA1G7B,YAAY,WAAW;AACvB,SAAS,KAAK,cAAc;AAC5B,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,YAAY,gBAAgB,sBAAqC;AAgC1E,MAAM,IAAI,EAAE,IAAI,4BAA4B,IAAI,4BAA4B,IAAI,2BAA2B;AAEpG,SAAS,MAAM;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAe;AACb,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAAS,KAAK;AAChD,QAAM,WAAW,MAAM,OAAyB,IAAI;AAEpD,QAAM,SAAS,MAAM,MAAM;AAC3B,QAAM,MAAM,MAAM;AAElB,QAAM,aAAa,SAAS;AAC5B,QAAM,cAAc,QAAQ,SAAS,KAAK,aAAa;AAEvD,QAAM,OAAO,QAAQ,OAAO,iBAAiB,WAAW,WAAW,MAAM,YAAY,IAAI;AACzF,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM;AAAA,IAAS,MAC3C,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW,OAAO,IAAI,EAAE,SAAS;AAAA,EAC/E;AACA,QAAM,QAAQ,KAAK,UAAU,SAAY,OAAO,KAAK,SAAS,EAAE,EAAE,SAAS;AAE3E,QAAM,YAAY,QAAQ,IAAI,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G1M;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Single-choice control for mutually exclusive options (payment method, appointment format).
|
|
5
|
+
* Group by giving every option the same `name`. Visually matched to `Checkbox` — same 20px
|
|
6
|
+
* box, same hover and label/description rhythm — differing only in the pill radius and dot.
|
|
7
|
+
* Host must include the `.sereno-radio:checked` rule (see globals.css).
|
|
8
|
+
*/
|
|
9
|
+
interface RadioProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Secondary line under the label. */
|
|
12
|
+
description?: string;
|
|
13
|
+
/** Circle size. `sm` (16px) for dense lists; `md` (20px) everywhere else. Matches `Checkbox`. */
|
|
14
|
+
size?: 'sm' | 'md';
|
|
15
|
+
}
|
|
16
|
+
declare function Radio({ label, description, checked, defaultChecked, disabled, size, onChange, style, ...rest }: RadioProps): React.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Radio, type RadioProps };
|