@conatel-sa/react-ui 0.2.2 → 0.2.4
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/README.md +42 -23
- package/dist/cards.d.ts +37 -0
- package/dist/cards.mjs +299 -0
- package/dist/cards.umd.js +345 -0
- package/dist/dialogs.d.ts +25 -0
- package/dist/dialogs.mjs +194 -0
- package/dist/dialogs.umd.js +246 -0
- package/dist/forms.d.ts +61 -0
- package/dist/forms.mjs +518 -0
- package/dist/forms.umd.js +562 -0
- package/dist/icons.d.ts +50 -0
- package/dist/icons.mjs +149 -0
- package/dist/icons.umd.js +186 -0
- package/dist/index.css +1 -1
- package/dist/index.mjs +213 -141
- package/dist/index.umd.js +1 -1
- package/dist/material-symbols.css +20 -0
- package/dist/metrics.d.ts +19 -0
- package/dist/metrics.mjs +94 -0
- package/dist/metrics.umd.js +142 -0
- package/dist/status.d.ts +16 -0
- package/dist/status.mjs +117 -0
- package/dist/status.umd.js +165 -0
- package/package.json +42 -4
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ReactLibraryForms = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/forms-entry.ts
|
|
22
|
+
var forms_entry_exports = {};
|
|
23
|
+
__export(forms_entry_exports, {
|
|
24
|
+
MultiSelectDropdown: () => MultiSelectDropdown,
|
|
25
|
+
PASSWORD_HINT: () => PASSWORD_HINT,
|
|
26
|
+
PASSWORD_RULES: () => PASSWORD_RULES,
|
|
27
|
+
PasswordInput: () => PasswordInput,
|
|
28
|
+
getPasswordValid: () => getPasswordValid,
|
|
29
|
+
isPasswordValid: () => isPasswordValid,
|
|
30
|
+
validatePassword: () => validatePassword
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// tools/react-shim.mjs
|
|
34
|
+
var R = typeof window !== "undefined" && window.React ? window.React : {};
|
|
35
|
+
var react_shim_default = R;
|
|
36
|
+
var {
|
|
37
|
+
useContext,
|
|
38
|
+
useEffect,
|
|
39
|
+
useMemo,
|
|
40
|
+
useState,
|
|
41
|
+
useRef,
|
|
42
|
+
useCallback,
|
|
43
|
+
useId,
|
|
44
|
+
createContext,
|
|
45
|
+
Fragment
|
|
46
|
+
} = R;
|
|
47
|
+
|
|
48
|
+
// src/components/forms/passwordValidation.ts
|
|
49
|
+
var SPECIAL_REGEX = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?~`]/;
|
|
50
|
+
function validatePassword(password) {
|
|
51
|
+
return {
|
|
52
|
+
minLength: password.length >= 8,
|
|
53
|
+
hasLower: /[a-z]/.test(password),
|
|
54
|
+
hasUpper: /[A-Z]/.test(password),
|
|
55
|
+
hasDigit: /[0-9]/.test(password),
|
|
56
|
+
hasSpecial: SPECIAL_REGEX.test(password)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function isPasswordValid(checks) {
|
|
60
|
+
return checks.minLength && checks.hasLower && checks.hasUpper && checks.hasDigit && checks.hasSpecial;
|
|
61
|
+
}
|
|
62
|
+
function getPasswordValid(password) {
|
|
63
|
+
return isPasswordValid(validatePassword(password));
|
|
64
|
+
}
|
|
65
|
+
var PASSWORD_RULES = [
|
|
66
|
+
{ key: "minLength", label: "M\xEDnimo 8 caracteres", ok: (c) => c.minLength },
|
|
67
|
+
{ key: "hasLower", label: "Al menos una min\xFAscula", ok: (c) => c.hasLower },
|
|
68
|
+
{ key: "hasUpper", label: "Al menos una may\xFAscula", ok: (c) => c.hasUpper },
|
|
69
|
+
{ key: "hasDigit", label: "Al menos un n\xFAmero", ok: (c) => c.hasDigit },
|
|
70
|
+
{ key: "hasSpecial", label: "Al menos un car\xE1cter especial (!@#$%^&* etc.)", ok: (c) => c.hasSpecial }
|
|
71
|
+
];
|
|
72
|
+
var PASSWORD_HINT = "M\xEDn. 8 caracteres, may\xFAscula, min\xFAscula, n\xFAmero y un car\xE1cter especial.";
|
|
73
|
+
|
|
74
|
+
// tools/jsx-runtime-shim.mjs
|
|
75
|
+
function jsx(type, props, key) {
|
|
76
|
+
const p = key != null ? { ...props, key } : props;
|
|
77
|
+
return react_shim_default.createElement(type, p);
|
|
78
|
+
}
|
|
79
|
+
function jsxs(type, props, key) {
|
|
80
|
+
return jsx(type, props, key);
|
|
81
|
+
}
|
|
82
|
+
var Fragment2 = react_shim_default.Fragment;
|
|
83
|
+
|
|
84
|
+
// src/components/forms/PasswordInput.tsx
|
|
85
|
+
function inputBaseStyle(focused, disabled, error) {
|
|
86
|
+
return {
|
|
87
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
88
|
+
fontSize: "var(--text-base, 14px)",
|
|
89
|
+
fontWeight: "var(--weight-regular, 400)",
|
|
90
|
+
color: "var(--color-text, #1a1a1a)",
|
|
91
|
+
background: "var(--input-bg, #ffffff)",
|
|
92
|
+
border: `1.5px solid ${error ? "var(--color-error, #dc2626)" : focused ? "var(--input-border-focus, var(--color-primary, #CC032E))" : "var(--input-border, var(--color-border, #e0e0e0))"}`,
|
|
93
|
+
borderRadius: "var(--input-radius, var(--radius-md, 6px))",
|
|
94
|
+
padding: "var(--space-2, 8px) var(--space-3, 12px)",
|
|
95
|
+
paddingRight: "3rem",
|
|
96
|
+
outline: "none",
|
|
97
|
+
transition: "box-shadow var(--duration-fast, .1s) var(--ease-default, ease), border-color var(--duration-fast, .1s) var(--ease-default, ease)",
|
|
98
|
+
boxShadow: focused ? "var(--focus-ring, 0 0 0 3px rgba(204, 3, 46, 0.12))" : "none",
|
|
99
|
+
opacity: disabled ? 0.6 : 1,
|
|
100
|
+
width: "100%",
|
|
101
|
+
boxSizing: "border-box"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function PasswordInput({
|
|
105
|
+
value,
|
|
106
|
+
onChange,
|
|
107
|
+
placeholder = "Contrase\xF1a",
|
|
108
|
+
label,
|
|
109
|
+
hint,
|
|
110
|
+
error,
|
|
111
|
+
disabled,
|
|
112
|
+
required,
|
|
113
|
+
ariaLabel,
|
|
114
|
+
showValidation = false,
|
|
115
|
+
id: idProp,
|
|
116
|
+
inputClassName,
|
|
117
|
+
className,
|
|
118
|
+
minLength = 8,
|
|
119
|
+
"data-testid": dataTestId
|
|
120
|
+
}) {
|
|
121
|
+
const [revealed, setRevealed] = useState(false);
|
|
122
|
+
const [focused, setFocused] = useState(false);
|
|
123
|
+
const genId = useId();
|
|
124
|
+
const id = idProp ?? genId;
|
|
125
|
+
const appChrome = showValidation || inputClassName !== void 0 || className !== void 0;
|
|
126
|
+
const effectiveInputClass = inputClassName ?? (showValidation ? "form-input" : void 0);
|
|
127
|
+
if (appChrome) {
|
|
128
|
+
const checks = validatePassword(value);
|
|
129
|
+
return /* @__PURE__ */ jsxs("div", { className: className ?? "form-group", children: [
|
|
130
|
+
label ? /* @__PURE__ */ jsx("label", { className: "text-xs block mb-2 font-semibold", htmlFor: id, children: label }) : null,
|
|
131
|
+
/* @__PURE__ */ jsxs("div", { style: { position: "relative", display: "flex", alignItems: "center" }, children: [
|
|
132
|
+
/* @__PURE__ */ jsx(
|
|
133
|
+
"input",
|
|
134
|
+
{
|
|
135
|
+
type: revealed ? "text" : "password",
|
|
136
|
+
id,
|
|
137
|
+
"data-testid": dataTestId,
|
|
138
|
+
value,
|
|
139
|
+
disabled,
|
|
140
|
+
onChange: (e) => onChange(e.target.value),
|
|
141
|
+
placeholder,
|
|
142
|
+
title: PASSWORD_HINT,
|
|
143
|
+
className: effectiveInputClass,
|
|
144
|
+
minLength,
|
|
145
|
+
required,
|
|
146
|
+
"aria-label": ariaLabel ?? label ?? "Password",
|
|
147
|
+
style: { paddingRight: "2.5rem", flex: 1 }
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
/* @__PURE__ */ jsx(
|
|
151
|
+
"button",
|
|
152
|
+
{
|
|
153
|
+
type: "button",
|
|
154
|
+
onClick: () => setRevealed((v) => !v),
|
|
155
|
+
tabIndex: -1,
|
|
156
|
+
style: {
|
|
157
|
+
position: "absolute",
|
|
158
|
+
right: "0.5rem",
|
|
159
|
+
background: "none",
|
|
160
|
+
border: "none",
|
|
161
|
+
padding: "0.25rem",
|
|
162
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
163
|
+
color: "var(--color-text-muted)",
|
|
164
|
+
display: "flex",
|
|
165
|
+
alignItems: "center"
|
|
166
|
+
},
|
|
167
|
+
title: revealed ? "Ocultar contrase\xF1a" : "Mostrar contrase\xF1a",
|
|
168
|
+
disabled,
|
|
169
|
+
children: /* @__PURE__ */ jsx("span", { className: "material-symbols-outlined", style: { fontSize: "1.25rem" }, children: revealed ? "visibility_off" : "visibility" })
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
] }),
|
|
173
|
+
showValidation ? /* @__PURE__ */ jsxs("p", { style: { marginTop: "0.5rem", fontSize: "0.75rem", color: "var(--color-text-secondary)" }, children: [
|
|
174
|
+
"* ",
|
|
175
|
+
PASSWORD_HINT
|
|
176
|
+
] }) : null,
|
|
177
|
+
showValidation && value.length > 0 ? /* @__PURE__ */ jsx(
|
|
178
|
+
"ul",
|
|
179
|
+
{
|
|
180
|
+
style: {
|
|
181
|
+
marginTop: "0.5rem",
|
|
182
|
+
paddingLeft: "1.25rem",
|
|
183
|
+
fontSize: "0.75rem",
|
|
184
|
+
color: "var(--color-text-secondary)"
|
|
185
|
+
},
|
|
186
|
+
children: PASSWORD_RULES.map((rule) => /* @__PURE__ */ jsxs(
|
|
187
|
+
"li",
|
|
188
|
+
{
|
|
189
|
+
style: {
|
|
190
|
+
listStyle: "none",
|
|
191
|
+
marginLeft: "-1.25rem",
|
|
192
|
+
marginBottom: "0.25rem",
|
|
193
|
+
display: "flex",
|
|
194
|
+
alignItems: "center",
|
|
195
|
+
gap: "0.35rem"
|
|
196
|
+
},
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ jsx(
|
|
199
|
+
"span",
|
|
200
|
+
{
|
|
201
|
+
style: {
|
|
202
|
+
color: rule.ok(checks) ? "var(--color-success)" : "var(--color-text-muted)",
|
|
203
|
+
fontWeight: rule.ok(checks) ? 600 : 400
|
|
204
|
+
},
|
|
205
|
+
children: rule.ok(checks) ? "\u2713" : "\u25CB"
|
|
206
|
+
}
|
|
207
|
+
),
|
|
208
|
+
/* @__PURE__ */ jsx("span", { style: rule.ok(checks) ? { color: "var(--color-success)" } : void 0, children: rule.label })
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
rule.key
|
|
212
|
+
))
|
|
213
|
+
}
|
|
214
|
+
) : null,
|
|
215
|
+
error ? /* @__PURE__ */ jsx("p", { role: "alert", style: { marginTop: "0.35rem", fontSize: "0.8125rem", color: "var(--color-error, #dc2626)" }, children: error }) : hint ? /* @__PURE__ */ jsx("p", { style: { marginTop: "0.35rem", fontSize: "0.8125rem", color: "var(--color-text-muted, #757578)" }, children: hint }) : null
|
|
216
|
+
] });
|
|
217
|
+
}
|
|
218
|
+
const inputStyle = inputBaseStyle(focused, disabled, Boolean(error));
|
|
219
|
+
const buttonStyle = {
|
|
220
|
+
position: "absolute",
|
|
221
|
+
right: "var(--space-2, 8px)",
|
|
222
|
+
top: "50%",
|
|
223
|
+
transform: "translateY(-50%)",
|
|
224
|
+
background: "transparent",
|
|
225
|
+
border: "none",
|
|
226
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
227
|
+
padding: 0,
|
|
228
|
+
display: "inline-flex",
|
|
229
|
+
alignItems: "center",
|
|
230
|
+
justifyContent: "center",
|
|
231
|
+
color: "var(--color-text-muted, #6b6b6b)",
|
|
232
|
+
opacity: disabled ? 0.6 : 1
|
|
233
|
+
};
|
|
234
|
+
const wrapStyle = {
|
|
235
|
+
position: "relative"
|
|
236
|
+
};
|
|
237
|
+
const labelStyle = {
|
|
238
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
239
|
+
fontSize: "var(--text-sm, 13px)",
|
|
240
|
+
fontWeight: "var(--weight-medium, 500)",
|
|
241
|
+
color: "var(--color-text, #1a1a1a)",
|
|
242
|
+
marginBottom: "var(--space-1, .25rem)",
|
|
243
|
+
display: "flex",
|
|
244
|
+
gap: "6px",
|
|
245
|
+
alignItems: "baseline"
|
|
246
|
+
};
|
|
247
|
+
const metaStyle = {
|
|
248
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
249
|
+
fontSize: "var(--text-sm, 13px)",
|
|
250
|
+
margin: "var(--space-1, .25rem) 0 0",
|
|
251
|
+
lineHeight: 1.2,
|
|
252
|
+
color: error ? "var(--color-error, #dc2626)" : "var(--color-text-muted, #757578)"
|
|
253
|
+
};
|
|
254
|
+
return /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", width: "100%" }, children: [
|
|
255
|
+
label ? /* @__PURE__ */ jsxs("label", { htmlFor: id, style: labelStyle, children: [
|
|
256
|
+
label,
|
|
257
|
+
required ? /* @__PURE__ */ jsxs("span", { style: { color: "var(--color-error, #dc2626)" }, "aria-hidden": true, children: [
|
|
258
|
+
" ",
|
|
259
|
+
"*"
|
|
260
|
+
] }) : null
|
|
261
|
+
] }) : null,
|
|
262
|
+
/* @__PURE__ */ jsxs("div", { style: wrapStyle, children: [
|
|
263
|
+
/* @__PURE__ */ jsx(
|
|
264
|
+
"input",
|
|
265
|
+
{
|
|
266
|
+
id,
|
|
267
|
+
type: revealed ? "text" : "password",
|
|
268
|
+
value,
|
|
269
|
+
disabled,
|
|
270
|
+
onChange: (e) => onChange(e.target.value),
|
|
271
|
+
placeholder,
|
|
272
|
+
"aria-label": ariaLabel ?? label ?? "Password",
|
|
273
|
+
onFocus: () => setFocused(true),
|
|
274
|
+
onBlur: () => setFocused(false),
|
|
275
|
+
style: inputStyle,
|
|
276
|
+
"data-testid": dataTestId
|
|
277
|
+
}
|
|
278
|
+
),
|
|
279
|
+
/* @__PURE__ */ jsx(
|
|
280
|
+
"button",
|
|
281
|
+
{
|
|
282
|
+
type: "button",
|
|
283
|
+
style: buttonStyle,
|
|
284
|
+
disabled,
|
|
285
|
+
"aria-label": revealed ? "Ocultar password" : "Mostrar password",
|
|
286
|
+
onClick: () => setRevealed((v) => !v),
|
|
287
|
+
children: /* @__PURE__ */ jsx(
|
|
288
|
+
"span",
|
|
289
|
+
{
|
|
290
|
+
className: "material-symbols-outlined",
|
|
291
|
+
style: { fontSize: "1.1rem", lineHeight: 1 },
|
|
292
|
+
"aria-hidden": "true",
|
|
293
|
+
children: revealed ? "visibility_off" : "visibility"
|
|
294
|
+
}
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
)
|
|
298
|
+
] }),
|
|
299
|
+
error ? /* @__PURE__ */ jsx("p", { role: "alert", style: metaStyle, children: error }) : hint ? /* @__PURE__ */ jsx("p", { style: metaStyle, children: hint }) : null
|
|
300
|
+
] });
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/components/forms/MultiSelectDropdown.tsx
|
|
304
|
+
function baseControlStyle(disabled, focused, error) {
|
|
305
|
+
return {
|
|
306
|
+
width: "100%",
|
|
307
|
+
display: "flex",
|
|
308
|
+
alignItems: "center",
|
|
309
|
+
justifyContent: "space-between",
|
|
310
|
+
gap: "var(--space-2, 8px)",
|
|
311
|
+
padding: "var(--space-2, 8px) var(--space-3, 12px)",
|
|
312
|
+
borderRadius: "var(--input-radius, var(--radius-md, 6px))",
|
|
313
|
+
border: `1.5px solid ${error ? "var(--color-error, #dc2626)" : focused ? "var(--input-border-focus, var(--color-primary, #CC032E))" : "var(--input-border, var(--color-border, #e0e0e0))"}`,
|
|
314
|
+
background: "var(--input-bg, #ffffff)",
|
|
315
|
+
color: "var(--color-text, #1a1a1a)",
|
|
316
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
317
|
+
opacity: disabled ? 0.6 : 1,
|
|
318
|
+
boxShadow: focused ? "var(--focus-ring, 0 0 0 3px rgba(204, 3, 46, 0.12))" : "none",
|
|
319
|
+
outline: "none",
|
|
320
|
+
userSelect: "none"
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
var appButtonStyle = (disabled) => ({
|
|
324
|
+
width: "100%",
|
|
325
|
+
textAlign: "left",
|
|
326
|
+
appearance: "none",
|
|
327
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
328
|
+
display: "flex",
|
|
329
|
+
alignItems: "center",
|
|
330
|
+
justifyContent: "space-between",
|
|
331
|
+
gap: "0.5rem"
|
|
332
|
+
});
|
|
333
|
+
function popoverStyle() {
|
|
334
|
+
return {
|
|
335
|
+
position: "absolute",
|
|
336
|
+
left: 0,
|
|
337
|
+
right: 0,
|
|
338
|
+
top: "calc(100% + 6px)",
|
|
339
|
+
zIndex: "var(--z-dropdown, 100)",
|
|
340
|
+
background: "var(--color-surface, #ffffff)",
|
|
341
|
+
border: "1.5px solid var(--color-border, #e0e0e0)",
|
|
342
|
+
borderRadius: "var(--radius-md, 6px)",
|
|
343
|
+
boxShadow: "var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,.1))",
|
|
344
|
+
padding: "var(--space-2, 8px)",
|
|
345
|
+
maxHeight: "240px",
|
|
346
|
+
overflowY: "auto"
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function itemRowStyle(active) {
|
|
350
|
+
return {
|
|
351
|
+
width: "100%",
|
|
352
|
+
display: "flex",
|
|
353
|
+
alignItems: "center",
|
|
354
|
+
justifyContent: "flex-start",
|
|
355
|
+
gap: "var(--space-2, 8px)",
|
|
356
|
+
padding: "var(--space-1, .25rem) var(--space-2, 8px)",
|
|
357
|
+
borderRadius: "var(--radius-sm, 4px)",
|
|
358
|
+
cursor: "pointer",
|
|
359
|
+
background: active ? "var(--color-primary-light, rgba(204, 3, 46, 0.08))" : "transparent",
|
|
360
|
+
color: active ? "var(--color-primary, #CC032E)" : "var(--color-text, #1a1a1a)"
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
var defaultLabelStyle = {
|
|
364
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
365
|
+
fontSize: "var(--text-sm, 13px)",
|
|
366
|
+
fontWeight: "var(--weight-medium, 500)",
|
|
367
|
+
color: "var(--color-text, #1a1a1a)",
|
|
368
|
+
marginBottom: "var(--space-1, .25rem)",
|
|
369
|
+
display: "block"
|
|
370
|
+
};
|
|
371
|
+
function MultiSelectDropdown({
|
|
372
|
+
label,
|
|
373
|
+
options,
|
|
374
|
+
value,
|
|
375
|
+
selected,
|
|
376
|
+
onChange,
|
|
377
|
+
placeholder = "Seleccionar\u2026",
|
|
378
|
+
emptyLabel,
|
|
379
|
+
disabled,
|
|
380
|
+
allowAllNone = true,
|
|
381
|
+
allLabel = "Todos",
|
|
382
|
+
noneLabel = "Ninguno",
|
|
383
|
+
maxLabels = 2,
|
|
384
|
+
labelStyle,
|
|
385
|
+
style,
|
|
386
|
+
buttonClassName
|
|
387
|
+
}) {
|
|
388
|
+
const [open, setOpen] = useState(false);
|
|
389
|
+
const [focused, setFocused] = useState(false);
|
|
390
|
+
const id = useId();
|
|
391
|
+
const rootRef = useRef(null);
|
|
392
|
+
const selectedValues = value ?? selected ?? [];
|
|
393
|
+
const effectivePlaceholder = emptyLabel ?? placeholder;
|
|
394
|
+
const selectedSet = useMemo(() => new Set(selectedValues), [selectedValues]);
|
|
395
|
+
const selectedLabels = useMemo(() => {
|
|
396
|
+
const byValue = new Map(options.map((o) => [o.value, o.label]));
|
|
397
|
+
return selectedValues.map((v) => byValue.get(v) ?? v);
|
|
398
|
+
}, [options, selectedValues]);
|
|
399
|
+
const allValues = useMemo(() => options.map((o) => o.value), [options]);
|
|
400
|
+
const isAllSelected = useMemo(
|
|
401
|
+
() => selectedValues.length > 0 && selectedValues.length === allValues.length,
|
|
402
|
+
[selectedValues, allValues]
|
|
403
|
+
);
|
|
404
|
+
useEffect(() => {
|
|
405
|
+
if (!open) return;
|
|
406
|
+
const onDown = (e) => {
|
|
407
|
+
const el = rootRef.current;
|
|
408
|
+
if (!el) return;
|
|
409
|
+
const target = e.target;
|
|
410
|
+
if (target && el.contains(target)) return;
|
|
411
|
+
setOpen(false);
|
|
412
|
+
};
|
|
413
|
+
document.addEventListener("mousedown", onDown);
|
|
414
|
+
return () => document.removeEventListener("mousedown", onDown);
|
|
415
|
+
}, [open]);
|
|
416
|
+
const toggleValue = (v) => {
|
|
417
|
+
if (disabled) return;
|
|
418
|
+
const next = selectedSet.has(v) ? selectedValues.filter((x) => x !== v) : [...selectedValues, v];
|
|
419
|
+
onChange(next);
|
|
420
|
+
};
|
|
421
|
+
const applyAllNone = (mode) => {
|
|
422
|
+
if (disabled) return;
|
|
423
|
+
if (mode === "all") onChange(allValues);
|
|
424
|
+
else onChange([]);
|
|
425
|
+
};
|
|
426
|
+
const summary = (() => {
|
|
427
|
+
if (selectedValues.length === 0) return effectivePlaceholder;
|
|
428
|
+
if (isAllSelected) return allLabel;
|
|
429
|
+
const shown = selectedLabels.slice(0, Math.max(1, maxLabels));
|
|
430
|
+
const extra = selectedLabels.length - shown.length;
|
|
431
|
+
return extra > 0 ? `${shown.join(", ")} +${extra} mas` : shown.join(", ");
|
|
432
|
+
})();
|
|
433
|
+
const checkboxStyle = {
|
|
434
|
+
accentColor: "var(--color-primary, #CC032E)",
|
|
435
|
+
margin: 0
|
|
436
|
+
};
|
|
437
|
+
const chevron = open ? "expand_less" : "expand_more";
|
|
438
|
+
const triggerStyle = buttonClassName ? appButtonStyle(disabled) : baseControlStyle(disabled, focused);
|
|
439
|
+
const mergedLabelStyle = label ? { ...defaultLabelStyle, ...labelStyle } : void 0;
|
|
440
|
+
return /* @__PURE__ */ jsxs(
|
|
441
|
+
"div",
|
|
442
|
+
{
|
|
443
|
+
style: { display: "flex", flexDirection: "column", width: "100%", position: "relative", ...style },
|
|
444
|
+
ref: rootRef,
|
|
445
|
+
children: [
|
|
446
|
+
label ? /* @__PURE__ */ jsx("label", { htmlFor: id, style: mergedLabelStyle, children: label }) : null,
|
|
447
|
+
/* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
|
|
448
|
+
/* @__PURE__ */ jsxs(
|
|
449
|
+
"button",
|
|
450
|
+
{
|
|
451
|
+
id,
|
|
452
|
+
type: "button",
|
|
453
|
+
className: buttonClassName,
|
|
454
|
+
disabled,
|
|
455
|
+
style: triggerStyle,
|
|
456
|
+
onClick: () => setOpen((v) => !v),
|
|
457
|
+
onFocus: () => setFocused(true),
|
|
458
|
+
onBlur: () => setFocused(false),
|
|
459
|
+
"aria-haspopup": "listbox",
|
|
460
|
+
"aria-expanded": open,
|
|
461
|
+
children: [
|
|
462
|
+
/* @__PURE__ */ jsx("span", { style: { flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: summary }),
|
|
463
|
+
/* @__PURE__ */ jsx(
|
|
464
|
+
"span",
|
|
465
|
+
{
|
|
466
|
+
className: "material-symbols-outlined",
|
|
467
|
+
style: { fontSize: "1.1rem", color: "var(--color-text-muted, #6b6b6b)", opacity: buttonClassName ? 0.7 : void 0 },
|
|
468
|
+
"aria-hidden": "true",
|
|
469
|
+
children: chevron
|
|
470
|
+
}
|
|
471
|
+
)
|
|
472
|
+
]
|
|
473
|
+
}
|
|
474
|
+
),
|
|
475
|
+
open ? /* @__PURE__ */ jsx("div", { style: popoverStyle(), role: "listbox", "aria-multiselectable": "true", children: options.length === 0 ? /* @__PURE__ */ jsx(
|
|
476
|
+
"div",
|
|
477
|
+
{
|
|
478
|
+
style: {
|
|
479
|
+
padding: "0.75rem",
|
|
480
|
+
fontSize: "0.875rem",
|
|
481
|
+
color: "var(--color-text-muted, #6b6b6b)"
|
|
482
|
+
},
|
|
483
|
+
children: effectivePlaceholder
|
|
484
|
+
}
|
|
485
|
+
) : /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
486
|
+
allowAllNone ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2, 8px)", marginBottom: "var(--space-2, 8px)" }, children: [
|
|
487
|
+
/* @__PURE__ */ jsx(
|
|
488
|
+
"button",
|
|
489
|
+
{
|
|
490
|
+
type: "button",
|
|
491
|
+
style: {
|
|
492
|
+
padding: "var(--space-1, .25rem) var(--space-2, 8px)",
|
|
493
|
+
borderRadius: "var(--radius-md, 6px)",
|
|
494
|
+
border: "1.5px solid var(--color-border, #e0e0e0)",
|
|
495
|
+
background: "var(--color-neutral-100, #f5f5f5)",
|
|
496
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
497
|
+
color: "var(--color-text, #1a1a1a)",
|
|
498
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
499
|
+
fontSize: "var(--text-sm, 13px)",
|
|
500
|
+
fontWeight: "var(--weight-medium, 500)"
|
|
501
|
+
},
|
|
502
|
+
onClick: () => applyAllNone("all"),
|
|
503
|
+
disabled,
|
|
504
|
+
children: allLabel
|
|
505
|
+
}
|
|
506
|
+
),
|
|
507
|
+
/* @__PURE__ */ jsx(
|
|
508
|
+
"button",
|
|
509
|
+
{
|
|
510
|
+
type: "button",
|
|
511
|
+
style: {
|
|
512
|
+
padding: "var(--space-1, .25rem) var(--space-2, 8px)",
|
|
513
|
+
borderRadius: "var(--radius-md, 6px)",
|
|
514
|
+
border: "1.5px solid var(--color-border, #e0e0e0)",
|
|
515
|
+
background: "var(--color-neutral-100, #f5f5f5)",
|
|
516
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
517
|
+
color: "var(--color-text, #1a1a1a)",
|
|
518
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
519
|
+
fontSize: "var(--text-sm, 13px)",
|
|
520
|
+
fontWeight: "var(--weight-medium, 500)"
|
|
521
|
+
},
|
|
522
|
+
onClick: () => applyAllNone("none"),
|
|
523
|
+
disabled,
|
|
524
|
+
children: noneLabel
|
|
525
|
+
}
|
|
526
|
+
)
|
|
527
|
+
] }) : null,
|
|
528
|
+
options.map((opt) => {
|
|
529
|
+
const checked = selectedSet.has(opt.value);
|
|
530
|
+
return /* @__PURE__ */ jsxs(
|
|
531
|
+
"div",
|
|
532
|
+
{
|
|
533
|
+
style: itemRowStyle(checked),
|
|
534
|
+
role: "option",
|
|
535
|
+
"aria-selected": checked,
|
|
536
|
+
onClick: () => toggleValue(opt.value),
|
|
537
|
+
children: [
|
|
538
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked, readOnly: true, style: checkboxStyle, "aria-label": opt.label }),
|
|
539
|
+
/* @__PURE__ */ jsx(
|
|
540
|
+
"span",
|
|
541
|
+
{
|
|
542
|
+
style: {
|
|
543
|
+
fontFamily: "var(--font-sans, system-ui)",
|
|
544
|
+
fontSize: "var(--text-sm, 13px)",
|
|
545
|
+
fontWeight: "var(--weight-medium, 500)"
|
|
546
|
+
},
|
|
547
|
+
children: opt.label
|
|
548
|
+
}
|
|
549
|
+
)
|
|
550
|
+
]
|
|
551
|
+
},
|
|
552
|
+
opt.value
|
|
553
|
+
);
|
|
554
|
+
})
|
|
555
|
+
] }) }) : null
|
|
556
|
+
] })
|
|
557
|
+
]
|
|
558
|
+
}
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
return __toCommonJS(forms_entry_exports);
|
|
562
|
+
})();
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ComponentType, Context, CSSProperties, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type IconSize = 'sm' | 'md' | 'lg' | number;
|
|
4
|
+
|
|
5
|
+
export interface IconContextValue {
|
|
6
|
+
fontHref: string;
|
|
7
|
+
injectStylesheet: boolean;
|
|
8
|
+
defaultSize: IconSize;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IconProps {
|
|
13
|
+
name: string;
|
|
14
|
+
size?: IconSize;
|
|
15
|
+
fill?: 0 | 1;
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
'aria-label'?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LucideIconProps {
|
|
22
|
+
as: ComponentType<{
|
|
23
|
+
className?: string;
|
|
24
|
+
size?: number | string;
|
|
25
|
+
strokeWidth?: number;
|
|
26
|
+
'aria-hidden'?: boolean;
|
|
27
|
+
'aria-label'?: string;
|
|
28
|
+
}>;
|
|
29
|
+
size?: IconSize;
|
|
30
|
+
className?: string;
|
|
31
|
+
strokeWidth?: number;
|
|
32
|
+
'aria-label'?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IconProviderProps {
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
fontHref?: string;
|
|
38
|
+
injectStylesheet?: boolean;
|
|
39
|
+
defaultSize?: IconContextValue['defaultSize'];
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare const DEFAULT_FONT_HREF: string;
|
|
44
|
+
export declare const defaultIconContext: IconContextValue;
|
|
45
|
+
export declare const IconContext: Context<IconContextValue>;
|
|
46
|
+
|
|
47
|
+
export declare function IconProvider(props: IconProviderProps): JSX.Element;
|
|
48
|
+
export declare function Icon(props: IconProps): JSX.Element;
|
|
49
|
+
export declare function LucideIcon(props: LucideIconProps): JSX.Element;
|
|
50
|
+
export declare function useIconContext(): IconContextValue;
|