@aspprev/versi-ds 0.1.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/README.md +463 -0
- package/dist/DocumentItem-BU0J2QGP.d.ts +21 -0
- package/dist/charts.d.ts +82 -0
- package/dist/charts.js +31 -0
- package/dist/charts.js.map +1 -0
- package/dist/chunk-2ACDV5D5.js +560 -0
- package/dist/chunk-2ACDV5D5.js.map +1 -0
- package/dist/chunk-2NMEKWO5.js +38 -0
- package/dist/chunk-2NMEKWO5.js.map +1 -0
- package/dist/chunk-6MXHE5MD.js +769 -0
- package/dist/chunk-6MXHE5MD.js.map +1 -0
- package/dist/chunk-A3PA5H7L.js +3099 -0
- package/dist/chunk-A3PA5H7L.js.map +1 -0
- package/dist/chunk-BY4HJZFJ.js +3308 -0
- package/dist/chunk-BY4HJZFJ.js.map +1 -0
- package/dist/chunk-CWIPMGCA.js +314 -0
- package/dist/chunk-CWIPMGCA.js.map +1 -0
- package/dist/chunk-OPUUOVCL.js +3226 -0
- package/dist/chunk-OPUUOVCL.js.map +1 -0
- package/dist/chunk-OWXG2A4N.js +77 -0
- package/dist/chunk-OWXG2A4N.js.map +1 -0
- package/dist/chunk-XGWGBD7X.js +45 -0
- package/dist/chunk-XGWGBD7X.js.map +1 -0
- package/dist/core.d.ts +471 -0
- package/dist/core.js +86 -0
- package/dist/core.js.map +1 -0
- package/dist/countries.d.ts +52 -0
- package/dist/countries.js +18 -0
- package/dist/countries.js.map +1 -0
- package/dist/documents.d.ts +9 -0
- package/dist/documents.js +13 -0
- package/dist/documents.js.map +1 -0
- package/dist/flags/ad.svg +1 -0
- package/dist/flags/ae.svg +1 -0
- package/dist/flags/af.svg +5 -0
- package/dist/flags/ag.svg +1 -0
- package/dist/flags/ai.svg +1 -0
- package/dist/flags/al.svg +1 -0
- package/dist/flags/am.svg +1 -0
- package/dist/flags/ao.svg +1 -0
- package/dist/flags/aq.svg +1 -0
- package/dist/flags/ar.svg +1 -0
- package/dist/flags/as.svg +1 -0
- package/dist/flags/at.svg +1 -0
- package/dist/flags/au.svg +1 -0
- package/dist/flags/aw.svg +1 -0
- package/dist/flags/ax.svg +1 -0
- package/dist/flags/az.svg +1 -0
- package/dist/flags/ba.svg +1 -0
- package/dist/flags/bb.svg +1 -0
- package/dist/flags/bd.svg +1 -0
- package/dist/flags/be.svg +1 -0
- package/dist/flags/bf.svg +1 -0
- package/dist/flags/bg.svg +1 -0
- package/dist/flags/bh.svg +1 -0
- package/dist/flags/bi.svg +1 -0
- package/dist/flags/bj.svg +1 -0
- package/dist/flags/bl.svg +1 -0
- package/dist/flags/bm.svg +1 -0
- package/dist/flags/bn.svg +1 -0
- package/dist/flags/bo.svg +1 -0
- package/dist/flags/bq.svg +1 -0
- package/dist/flags/br.svg +1 -0
- package/dist/flags/bs.svg +1 -0
- package/dist/flags/bt.svg +1 -0
- package/dist/flags/bv.svg +1 -0
- package/dist/flags/bw.svg +1 -0
- package/dist/flags/by.svg +1 -0
- package/dist/flags/bz.svg +1 -0
- package/dist/flags/ca.svg +1 -0
- package/dist/flags/cc.svg +1 -0
- package/dist/flags/cd.svg +1 -0
- package/dist/flags/cf.svg +1 -0
- package/dist/flags/cg.svg +1 -0
- package/dist/flags/ch.svg +1 -0
- package/dist/flags/ci.svg +1 -0
- package/dist/flags/ck.svg +1 -0
- package/dist/flags/cl.svg +1 -0
- package/dist/flags/cm.svg +1 -0
- package/dist/flags/cn.svg +1 -0
- package/dist/flags/co.svg +1 -0
- package/dist/flags/cr.svg +1 -0
- package/dist/flags/cu.svg +1 -0
- package/dist/flags/cv.svg +1 -0
- package/dist/flags/cw.svg +1 -0
- package/dist/flags/cx.svg +1 -0
- package/dist/flags/cy.svg +1 -0
- package/dist/flags/cz.svg +1 -0
- package/dist/flags/de.svg +1 -0
- package/dist/flags/dj.svg +1 -0
- package/dist/flags/dk.svg +1 -0
- package/dist/flags/dm.svg +1 -0
- package/dist/flags/do.svg +1 -0
- package/dist/flags/dz.svg +1 -0
- package/dist/flags/ec.svg +1 -0
- package/dist/flags/ee.svg +1 -0
- package/dist/flags/eg.svg +1 -0
- package/dist/flags/eh.svg +1 -0
- package/dist/flags/er.svg +1 -0
- package/dist/flags/es.svg +1 -0
- package/dist/flags/et.svg +1 -0
- package/dist/flags/fi.svg +1 -0
- package/dist/flags/fj.svg +1 -0
- package/dist/flags/fk.svg +1 -0
- package/dist/flags/fm.svg +1 -0
- package/dist/flags/fo.svg +1 -0
- package/dist/flags/fr.svg +1 -0
- package/dist/flags/ga.svg +1 -0
- package/dist/flags/gb.svg +1 -0
- package/dist/flags/gd.svg +1 -0
- package/dist/flags/ge.svg +1 -0
- package/dist/flags/gf.svg +1 -0
- package/dist/flags/gg.svg +1 -0
- package/dist/flags/gh.svg +1 -0
- package/dist/flags/gi.svg +1 -0
- package/dist/flags/gl.svg +1 -0
- package/dist/flags/gm.svg +1 -0
- package/dist/flags/gn.svg +1 -0
- package/dist/flags/gp.svg +1 -0
- package/dist/flags/gq.svg +1 -0
- package/dist/flags/gr.svg +1 -0
- package/dist/flags/gs.svg +1 -0
- package/dist/flags/gt.svg +1 -0
- package/dist/flags/gu.svg +1 -0
- package/dist/flags/gw.svg +1 -0
- package/dist/flags/gy.svg +1 -0
- package/dist/flags/hk.svg +1 -0
- package/dist/flags/hm.svg +1 -0
- package/dist/flags/hn.svg +1 -0
- package/dist/flags/hr.svg +1 -0
- package/dist/flags/ht.svg +1 -0
- package/dist/flags/hu.svg +1 -0
- package/dist/flags/id.svg +1 -0
- package/dist/flags/ie.svg +1 -0
- package/dist/flags/il.svg +1 -0
- package/dist/flags/im.svg +1 -0
- package/dist/flags/in.svg +1 -0
- package/dist/flags/io.svg +1 -0
- package/dist/flags/iq.svg +1 -0
- package/dist/flags/ir.svg +1 -0
- package/dist/flags/is.svg +1 -0
- package/dist/flags/it.svg +1 -0
- package/dist/flags/je.svg +1 -0
- package/dist/flags/jm.svg +1 -0
- package/dist/flags/jo.svg +1 -0
- package/dist/flags/jp.svg +1 -0
- package/dist/flags/ke.svg +1 -0
- package/dist/flags/kg.svg +1 -0
- package/dist/flags/kh.svg +1 -0
- package/dist/flags/ki.svg +1 -0
- package/dist/flags/km.svg +1 -0
- package/dist/flags/kn.svg +1 -0
- package/dist/flags/kp.svg +1 -0
- package/dist/flags/kr.svg +1 -0
- package/dist/flags/kw.svg +1 -0
- package/dist/flags/ky.svg +1 -0
- package/dist/flags/kz.svg +1 -0
- package/dist/flags/la.svg +1 -0
- package/dist/flags/lb.svg +1 -0
- package/dist/flags/lc.svg +1 -0
- package/dist/flags/li.svg +1 -0
- package/dist/flags/lk.svg +1 -0
- package/dist/flags/lr.svg +1 -0
- package/dist/flags/ls.svg +1 -0
- package/dist/flags/lt.svg +1 -0
- package/dist/flags/lu.svg +1 -0
- package/dist/flags/lv.svg +1 -0
- package/dist/flags/ly.svg +1 -0
- package/dist/flags/ma.svg +1 -0
- package/dist/flags/mc.svg +1 -0
- package/dist/flags/md.svg +1 -0
- package/dist/flags/me.svg +1 -0
- package/dist/flags/mf.svg +1 -0
- package/dist/flags/mg.svg +1 -0
- package/dist/flags/mh.svg +1 -0
- package/dist/flags/mk.svg +1 -0
- package/dist/flags/ml.svg +1 -0
- package/dist/flags/mm.svg +1 -0
- package/dist/flags/mn.svg +1 -0
- package/dist/flags/mo.svg +1 -0
- package/dist/flags/mp.svg +1 -0
- package/dist/flags/mq.svg +1 -0
- package/dist/flags/mr.svg +1 -0
- package/dist/flags/ms.svg +1 -0
- package/dist/flags/mt.svg +1 -0
- package/dist/flags/mu.svg +1 -0
- package/dist/flags/mv.svg +1 -0
- package/dist/flags/mw.svg +1 -0
- package/dist/flags/mx.svg +1 -0
- package/dist/flags/my.svg +1 -0
- package/dist/flags/mz.svg +1 -0
- package/dist/flags/na.svg +1 -0
- package/dist/flags/nc.svg +1 -0
- package/dist/flags/ne.svg +1 -0
- package/dist/flags/nf.svg +1 -0
- package/dist/flags/ng.svg +1 -0
- package/dist/flags/ni.svg +1 -0
- package/dist/flags/nl.svg +1 -0
- package/dist/flags/no.svg +1 -0
- package/dist/flags/np.svg +1 -0
- package/dist/flags/nr.svg +1 -0
- package/dist/flags/nu.svg +1 -0
- package/dist/flags/nz.svg +1 -0
- package/dist/flags/om.svg +1 -0
- package/dist/flags/pa.svg +1 -0
- package/dist/flags/pe.svg +1 -0
- package/dist/flags/pf.svg +1 -0
- package/dist/flags/pg.svg +1 -0
- package/dist/flags/ph.svg +1 -0
- package/dist/flags/pk.svg +1 -0
- package/dist/flags/pl.svg +1 -0
- package/dist/flags/pm.svg +1 -0
- package/dist/flags/pn.svg +1 -0
- package/dist/flags/pr.svg +1 -0
- package/dist/flags/ps.svg +1 -0
- package/dist/flags/pt.svg +1 -0
- package/dist/flags/pw.svg +1 -0
- package/dist/flags/py.svg +1 -0
- package/dist/flags/qa.svg +1 -0
- package/dist/flags/re.svg +1 -0
- package/dist/flags/ro.svg +1 -0
- package/dist/flags/rs.svg +1 -0
- package/dist/flags/ru.svg +1 -0
- package/dist/flags/rw.svg +1 -0
- package/dist/flags/sa.svg +1 -0
- package/dist/flags/sb.svg +1 -0
- package/dist/flags/sc.svg +1 -0
- package/dist/flags/sd.svg +1 -0
- package/dist/flags/se.svg +1 -0
- package/dist/flags/sg.svg +1 -0
- package/dist/flags/sh.svg +1 -0
- package/dist/flags/si.svg +1 -0
- package/dist/flags/sj.svg +1 -0
- package/dist/flags/sk.svg +1 -0
- package/dist/flags/sl.svg +1 -0
- package/dist/flags/sm.svg +1 -0
- package/dist/flags/sn.svg +1 -0
- package/dist/flags/so.svg +1 -0
- package/dist/flags/sr.svg +1 -0
- package/dist/flags/ss.svg +1 -0
- package/dist/flags/st.svg +1 -0
- package/dist/flags/sv.svg +1 -0
- package/dist/flags/sx.svg +1 -0
- package/dist/flags/sy.svg +1 -0
- package/dist/flags/sz.svg +1 -0
- package/dist/flags/tc.svg +1 -0
- package/dist/flags/td.svg +1 -0
- package/dist/flags/tf.svg +1 -0
- package/dist/flags/tg.svg +1 -0
- package/dist/flags/th.svg +1 -0
- package/dist/flags/tj.svg +1 -0
- package/dist/flags/tk.svg +1 -0
- package/dist/flags/tl.svg +1 -0
- package/dist/flags/tm.svg +1 -0
- package/dist/flags/tn.svg +1 -0
- package/dist/flags/to.svg +1 -0
- package/dist/flags/tr.svg +1 -0
- package/dist/flags/tt.svg +1 -0
- package/dist/flags/tv.svg +1 -0
- package/dist/flags/tw.svg +1 -0
- package/dist/flags/tz.svg +1 -0
- package/dist/flags/ua.svg +1 -0
- package/dist/flags/ug.svg +1 -0
- package/dist/flags/um.svg +1 -0
- package/dist/flags/us.svg +1 -0
- package/dist/flags/uy.svg +1 -0
- package/dist/flags/uz.svg +1 -0
- package/dist/flags/va.svg +1 -0
- package/dist/flags/vc.svg +1 -0
- package/dist/flags/ve.svg +1 -0
- package/dist/flags/vg.svg +1 -0
- package/dist/flags/vi.svg +1 -0
- package/dist/flags/vn.svg +1 -0
- package/dist/flags/vu.svg +1 -0
- package/dist/flags/wf.svg +1 -0
- package/dist/flags/ws.svg +1 -0
- package/dist/flags/xk.svg +1 -0
- package/dist/flags/ye.svg +1 -0
- package/dist/flags/yt.svg +1 -0
- package/dist/flags/za.svg +1 -0
- package/dist/flags/zm.svg +1 -0
- package/dist/flags/zw.svg +1 -0
- package/dist/forms.d.ts +242 -0
- package/dist/forms.js +41 -0
- package/dist/forms.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +163 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.json +33 -0
- package/dist/overlays.d.ts +75 -0
- package/dist/overlays.js +17 -0
- package/dist/overlays.js.map +1 -0
- package/dist/styles.css +3 -0
- package/dist/themes.css +125 -0
- package/package.json +156 -0
|
@@ -0,0 +1,3308 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Tooltip_default,
|
|
3
|
+
getFloatingLayerClass,
|
|
4
|
+
mergeAriaDescribedBy
|
|
5
|
+
} from "./chunk-CWIPMGCA.js";
|
|
6
|
+
import {
|
|
7
|
+
COUNTRY_OPTIONS,
|
|
8
|
+
PHONE_COUNTRY_OPTIONS,
|
|
9
|
+
filterCountryOptions,
|
|
10
|
+
getCountryFlagUrl
|
|
11
|
+
} from "./chunk-A3PA5H7L.js";
|
|
12
|
+
import {
|
|
13
|
+
__objRest,
|
|
14
|
+
__spreadProps,
|
|
15
|
+
__spreadValues
|
|
16
|
+
} from "./chunk-2NMEKWO5.js";
|
|
17
|
+
|
|
18
|
+
// src/components/input/Input.tsx
|
|
19
|
+
import React, { useRef, useCallback, useId, useState } from "react";
|
|
20
|
+
import classNames2 from "classnames";
|
|
21
|
+
import { PatternFormat } from "react-number-format";
|
|
22
|
+
import { useField } from "formik";
|
|
23
|
+
import { MdInfoOutline, MdVisibility, MdVisibilityOff } from "react-icons/md";
|
|
24
|
+
|
|
25
|
+
// src/components/field/FieldFrame.tsx
|
|
26
|
+
import classNames from "classnames";
|
|
27
|
+
import { forwardRef } from "react";
|
|
28
|
+
|
|
29
|
+
// src/components/field/field-styles.ts
|
|
30
|
+
var FIELD_ROOT_CLASS = "field-layout flex w-full min-w-0 flex-col leading-6";
|
|
31
|
+
var FIELD_LABEL_CLASS = "field-label-slot px-0.5 text-md tracking-wide text-field-content";
|
|
32
|
+
var FIELD_CONTROL_CLASS = "field-control-slot field-keyboard-focus-ring relative mt-4xs mb-[4px] flex min-h-control-md w-full min-w-0 items-center gap-3 rounded-sm border border-field-border-default bg-field-surface px-3 text-field-icon transition-colors focus-within:border-field-border-active focus-within:text-field-content data-[has-value=true]:text-field-content";
|
|
33
|
+
var FIELD_DISABLED_CLASS = "cursor-not-allowed border-field-border-default bg-field-surface-disabled text-field-content-disabled focus-within:border-field-border-default";
|
|
34
|
+
var FIELD_ERROR_CLASS = "border-field-border-error text-field-assistive-error focus-within:border-field-border-error";
|
|
35
|
+
var FIELD_MESSAGE_CLASS = "field-message-slot text-xs tracking-wide text-field-assistive-error";
|
|
36
|
+
var FIELD_DESCRIPTION_CLASS = "field-message-slot text-xs tracking-wide text-field-assistive";
|
|
37
|
+
var FIELD_INPUT_CLASS = "w-full border-none bg-transparent text-field-content outline-none placeholder:text-field-placeholder focus:outline-none disabled:text-field-content-disabled disabled:placeholder:text-field-content-disabled";
|
|
38
|
+
|
|
39
|
+
// src/components/field/FieldFrame.tsx
|
|
40
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
41
|
+
var FieldFrame = forwardRef(
|
|
42
|
+
function FieldFrame2(_a, ref) {
|
|
43
|
+
var _b = _a, {
|
|
44
|
+
children,
|
|
45
|
+
label,
|
|
46
|
+
labelFor,
|
|
47
|
+
labelId,
|
|
48
|
+
labelAdornment,
|
|
49
|
+
description,
|
|
50
|
+
descriptionId,
|
|
51
|
+
message,
|
|
52
|
+
messageId,
|
|
53
|
+
invalid = false,
|
|
54
|
+
className
|
|
55
|
+
} = _b, rest = __objRest(_b, [
|
|
56
|
+
"children",
|
|
57
|
+
"label",
|
|
58
|
+
"labelFor",
|
|
59
|
+
"labelId",
|
|
60
|
+
"labelAdornment",
|
|
61
|
+
"description",
|
|
62
|
+
"descriptionId",
|
|
63
|
+
"message",
|
|
64
|
+
"messageId",
|
|
65
|
+
"invalid",
|
|
66
|
+
"className"
|
|
67
|
+
]);
|
|
68
|
+
return /* @__PURE__ */ jsxs(
|
|
69
|
+
"div",
|
|
70
|
+
__spreadProps(__spreadValues({
|
|
71
|
+
ref,
|
|
72
|
+
className: classNames(FIELD_ROOT_CLASS, className)
|
|
73
|
+
}, rest), {
|
|
74
|
+
children: [
|
|
75
|
+
(label || labelAdornment) && /* @__PURE__ */ jsxs("div", { className: "field-label-slot flex flex-row items-end justify-between", children: [
|
|
76
|
+
label && /* @__PURE__ */ jsx(
|
|
77
|
+
"label",
|
|
78
|
+
{
|
|
79
|
+
id: labelId,
|
|
80
|
+
htmlFor: labelFor,
|
|
81
|
+
className: FIELD_LABEL_CLASS,
|
|
82
|
+
children: label
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
labelAdornment
|
|
86
|
+
] }),
|
|
87
|
+
children,
|
|
88
|
+
description !== void 0 && description !== null && !invalid && /* @__PURE__ */ jsx("span", { id: descriptionId, className: FIELD_DESCRIPTION_CLASS, children: description }),
|
|
89
|
+
message !== void 0 && message !== null && invalid && /* @__PURE__ */ jsx(
|
|
90
|
+
"span",
|
|
91
|
+
{
|
|
92
|
+
id: messageId,
|
|
93
|
+
role: "alert",
|
|
94
|
+
"aria-live": "polite",
|
|
95
|
+
className: FIELD_MESSAGE_CLASS,
|
|
96
|
+
children: message
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
FieldFrame.displayName = "FieldFrame";
|
|
105
|
+
var FieldFrame_default = FieldFrame;
|
|
106
|
+
|
|
107
|
+
// src/components/input/Input.tsx
|
|
108
|
+
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
109
|
+
var BaseInput = React.forwardRef((props, ref) => /* @__PURE__ */ jsx2(
|
|
110
|
+
"input",
|
|
111
|
+
__spreadProps(__spreadValues({}, props), {
|
|
112
|
+
ref,
|
|
113
|
+
className: classNames2(FIELD_INPUT_CLASS, props.className)
|
|
114
|
+
})
|
|
115
|
+
));
|
|
116
|
+
BaseInput.displayName = "BaseInput";
|
|
117
|
+
function normalizeCurrencyDigits(value) {
|
|
118
|
+
if (value === void 0 || value === null) return "";
|
|
119
|
+
return String(value).replace(/\D/g, "");
|
|
120
|
+
}
|
|
121
|
+
function formatCurrencyAmount(value) {
|
|
122
|
+
return value.toLocaleString("pt-BR", {
|
|
123
|
+
minimumFractionDigits: 2,
|
|
124
|
+
maximumFractionDigits: 2
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function formatCurrencyDigitsForDisplay(value) {
|
|
128
|
+
if (value === void 0 || value === null || value === "") return "";
|
|
129
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
130
|
+
return formatCurrencyAmount(value);
|
|
131
|
+
}
|
|
132
|
+
const stringValue = String(value).trim();
|
|
133
|
+
if (!stringValue) return "";
|
|
134
|
+
const digits = normalizeCurrencyDigits(stringValue);
|
|
135
|
+
if (!digits) return "";
|
|
136
|
+
const normalized = digits.padStart(3, "0");
|
|
137
|
+
const integerPart = normalized.slice(0, -2).replace(/^0+(?=\d)/, "") || "0";
|
|
138
|
+
const decimalPart = normalized.slice(-2);
|
|
139
|
+
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
140
|
+
return `${formattedInteger},${decimalPart}`;
|
|
141
|
+
}
|
|
142
|
+
function formatContaValue(value) {
|
|
143
|
+
const upperValue = value.toUpperCase();
|
|
144
|
+
const hasHyphen = upperValue.includes("-");
|
|
145
|
+
const [rawBody = "", rawDigit = ""] = upperValue.split("-", 2);
|
|
146
|
+
if (hasHyphen) {
|
|
147
|
+
const bodySeed = rawBody.replace(/\D/g, "");
|
|
148
|
+
const suffixChars = rawDigit.replace(/[^0-9X]/g, "");
|
|
149
|
+
const suffixBody = suffixChars.slice(0, -1).replace(/\D/g, "");
|
|
150
|
+
const body = `${bodySeed}${suffixBody}`.slice(0, 12);
|
|
151
|
+
const digit = suffixChars.slice(-1);
|
|
152
|
+
if (!body) return "";
|
|
153
|
+
return digit ? `${body}-${digit}` : `${body}-`;
|
|
154
|
+
}
|
|
155
|
+
const compactDigits = upperValue.replace(/\D/g, "").slice(0, 13);
|
|
156
|
+
if (!compactDigits) return "";
|
|
157
|
+
if (compactDigits.length <= 12) {
|
|
158
|
+
return `${compactDigits}-`;
|
|
159
|
+
}
|
|
160
|
+
return `${compactDigits.slice(0, 12)}-${compactDigits.slice(12, 13)}`;
|
|
161
|
+
}
|
|
162
|
+
var Input = (_a) => {
|
|
163
|
+
var _b = _a, {
|
|
164
|
+
name,
|
|
165
|
+
label,
|
|
166
|
+
helperText,
|
|
167
|
+
placeholder,
|
|
168
|
+
prefix,
|
|
169
|
+
suffix,
|
|
170
|
+
mask,
|
|
171
|
+
disabled,
|
|
172
|
+
error,
|
|
173
|
+
disallowSpaces,
|
|
174
|
+
leadIcon: LeadIcon,
|
|
175
|
+
endIcon: EndIcon,
|
|
176
|
+
type,
|
|
177
|
+
className
|
|
178
|
+
} = _b, rest = __objRest(_b, [
|
|
179
|
+
"name",
|
|
180
|
+
"label",
|
|
181
|
+
"helperText",
|
|
182
|
+
"placeholder",
|
|
183
|
+
"prefix",
|
|
184
|
+
"suffix",
|
|
185
|
+
"mask",
|
|
186
|
+
"disabled",
|
|
187
|
+
"error",
|
|
188
|
+
"disallowSpaces",
|
|
189
|
+
"leadIcon",
|
|
190
|
+
"endIcon",
|
|
191
|
+
"type",
|
|
192
|
+
"className"
|
|
193
|
+
]);
|
|
194
|
+
var _a2;
|
|
195
|
+
const [field, meta, helpers] = useField(name);
|
|
196
|
+
const inputRef = useRef(null);
|
|
197
|
+
const iconRef = useRef(null);
|
|
198
|
+
const [hovered, setHovered] = useState(false);
|
|
199
|
+
const isPasswordType = type === "password";
|
|
200
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
201
|
+
const currentType = isPasswordType ? showPassword ? "text" : "password" : type;
|
|
202
|
+
const hasError = Boolean(meta.touched && meta.error);
|
|
203
|
+
const inputId = (_a2 = rest.id) != null ? _a2 : name;
|
|
204
|
+
const errorId = `${inputId}-error`;
|
|
205
|
+
const ariaDescribedBy = mergeAriaDescribedBy(
|
|
206
|
+
rest["aria-describedby"],
|
|
207
|
+
hasError ? errorId : void 0
|
|
208
|
+
);
|
|
209
|
+
const accessibilityProps = {
|
|
210
|
+
id: inputId,
|
|
211
|
+
"aria-invalid": hasError || void 0,
|
|
212
|
+
"aria-describedby": ariaDescribedBy
|
|
213
|
+
};
|
|
214
|
+
const safeValue = (v) => v === void 0 || v === null ? "" : v;
|
|
215
|
+
const sanitizeValue = useCallback(
|
|
216
|
+
(value) => {
|
|
217
|
+
if (!disallowSpaces) return value;
|
|
218
|
+
return value.replace(/\s/g, "");
|
|
219
|
+
},
|
|
220
|
+
[disallowSpaces]
|
|
221
|
+
);
|
|
222
|
+
const handlePasteFormik = useCallback(
|
|
223
|
+
(e) => {
|
|
224
|
+
var _a3, _b2;
|
|
225
|
+
if (!disallowSpaces) {
|
|
226
|
+
(_a3 = rest.onPaste) == null ? void 0 : _a3.call(rest, e);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
e.preventDefault();
|
|
230
|
+
const pastedText = e.clipboardData.getData("text");
|
|
231
|
+
const sanitizedValue = sanitizeValue(pastedText);
|
|
232
|
+
helpers.setValue(sanitizedValue);
|
|
233
|
+
(_b2 = rest.onPaste) == null ? void 0 : _b2.call(rest, e);
|
|
234
|
+
},
|
|
235
|
+
[disallowSpaces, helpers, rest, sanitizeValue]
|
|
236
|
+
);
|
|
237
|
+
const handleValueChange = useCallback(
|
|
238
|
+
(values) => {
|
|
239
|
+
helpers.setValue(values.value);
|
|
240
|
+
},
|
|
241
|
+
[helpers]
|
|
242
|
+
);
|
|
243
|
+
const handleCurrencyChange = useCallback(
|
|
244
|
+
(e) => {
|
|
245
|
+
const formattedCurrencyValue = formatCurrencyDigitsForDisplay(
|
|
246
|
+
e.target.value
|
|
247
|
+
);
|
|
248
|
+
helpers.setValue(formattedCurrencyValue);
|
|
249
|
+
if (rest.onChange) {
|
|
250
|
+
const event = __spreadProps(__spreadValues({}, e), {
|
|
251
|
+
target: __spreadProps(__spreadValues({}, e.target), { value: formattedCurrencyValue }),
|
|
252
|
+
currentTarget: __spreadProps(__spreadValues({}, e.currentTarget), {
|
|
253
|
+
value: formattedCurrencyValue
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
rest.onChange(event);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
[helpers, rest]
|
|
260
|
+
);
|
|
261
|
+
const cleanSpecialChars = (value) => {
|
|
262
|
+
if (!value) return "";
|
|
263
|
+
let newValue = value;
|
|
264
|
+
newValue = newValue.replace(/[áàãâä]/gi, "a");
|
|
265
|
+
newValue = newValue.replace(/[éèêë]/gi, "e");
|
|
266
|
+
newValue = newValue.replace(/[íìîï]/gi, "i");
|
|
267
|
+
newValue = newValue.replace(/[óòõôö]/gi, "o");
|
|
268
|
+
newValue = newValue.replace(/[úùûü]/gi, "u");
|
|
269
|
+
newValue = newValue.replace(/[ç]/gi, "c");
|
|
270
|
+
newValue = newValue.replace(/['"`´@!#$%&¨()*;:?\-_+={}\[\]\\\/|<>.,]/g, "");
|
|
271
|
+
return newValue;
|
|
272
|
+
};
|
|
273
|
+
const patternMasks = {
|
|
274
|
+
cpf: "###.###.###-##",
|
|
275
|
+
cnpj: "##.###.###/####-##",
|
|
276
|
+
cep: "#####-###",
|
|
277
|
+
phone: "(##) #####-####",
|
|
278
|
+
date: "##/##/####",
|
|
279
|
+
agencia: "####"
|
|
280
|
+
};
|
|
281
|
+
const renderMaskedInput = (inputType) => {
|
|
282
|
+
const autoCompleteValue = rest.autoComplete;
|
|
283
|
+
if (mask === "currency") {
|
|
284
|
+
const rawCurrencyValue = typeof field.value === "string" || typeof field.value === "number" ? field.value : "";
|
|
285
|
+
return /* @__PURE__ */ jsx2(
|
|
286
|
+
"input",
|
|
287
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
288
|
+
name,
|
|
289
|
+
ref: inputRef,
|
|
290
|
+
type: "text",
|
|
291
|
+
inputMode: "numeric",
|
|
292
|
+
value: formatCurrencyDigitsForDisplay(rawCurrencyValue),
|
|
293
|
+
onChange: handleCurrencyChange,
|
|
294
|
+
onBlur: field.onBlur,
|
|
295
|
+
placeholder,
|
|
296
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
297
|
+
autoComplete: autoCompleteValue,
|
|
298
|
+
disabled
|
|
299
|
+
})
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
if (mask === "specialChars") {
|
|
303
|
+
return /* @__PURE__ */ jsx2(
|
|
304
|
+
"input",
|
|
305
|
+
__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, rest), accessibilityProps), field), {
|
|
306
|
+
name,
|
|
307
|
+
ref: inputRef,
|
|
308
|
+
placeholder,
|
|
309
|
+
type: inputType === "date" ? "text" : inputType,
|
|
310
|
+
value: String(safeValue(field.value)),
|
|
311
|
+
onKeyDown: (e) => {
|
|
312
|
+
var _a3;
|
|
313
|
+
if (disallowSpaces && e.key === " ") {
|
|
314
|
+
e.preventDefault();
|
|
315
|
+
}
|
|
316
|
+
(_a3 = rest.onKeyDown) == null ? void 0 : _a3.call(rest, e);
|
|
317
|
+
},
|
|
318
|
+
onPaste: handlePasteFormik,
|
|
319
|
+
onChange: (e) => {
|
|
320
|
+
var _a3;
|
|
321
|
+
const cleanedValue = cleanSpecialChars(e.target.value);
|
|
322
|
+
const sanitizedValue = sanitizeValue(cleanedValue);
|
|
323
|
+
helpers.setValue(sanitizedValue);
|
|
324
|
+
(_a3 = rest.onChange) == null ? void 0 : _a3.call(rest, e);
|
|
325
|
+
},
|
|
326
|
+
autoComplete: autoCompleteValue,
|
|
327
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
328
|
+
disabled
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
if (mask === "datePicker") {
|
|
333
|
+
const dateValue = field.value ? typeof field.value === "string" ? field.value : field.value instanceof Date ? field.value.toLocaleDateString("pt-BR") : String(field.value) : "";
|
|
334
|
+
return /* @__PURE__ */ jsx2(
|
|
335
|
+
"input",
|
|
336
|
+
__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, rest), accessibilityProps), field), {
|
|
337
|
+
name,
|
|
338
|
+
ref: inputRef,
|
|
339
|
+
placeholder,
|
|
340
|
+
type: inputType,
|
|
341
|
+
value: dateValue,
|
|
342
|
+
onKeyDown: (e) => {
|
|
343
|
+
var _a3;
|
|
344
|
+
if (disallowSpaces && e.key === " ") {
|
|
345
|
+
e.preventDefault();
|
|
346
|
+
}
|
|
347
|
+
(_a3 = rest.onKeyDown) == null ? void 0 : _a3.call(rest, e);
|
|
348
|
+
},
|
|
349
|
+
onPaste: handlePasteFormik,
|
|
350
|
+
onChange: (e) => {
|
|
351
|
+
const cleanedValue = cleanSpecialChars(e.target.value);
|
|
352
|
+
const sanitizedValue = sanitizeValue(cleanedValue);
|
|
353
|
+
helpers.setValue(sanitizedValue);
|
|
354
|
+
},
|
|
355
|
+
autoComplete: autoCompleteValue,
|
|
356
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
357
|
+
disabled
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
if (mask === "conta") {
|
|
362
|
+
return /* @__PURE__ */ jsx2(
|
|
363
|
+
"input",
|
|
364
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
365
|
+
name,
|
|
366
|
+
ref: inputRef,
|
|
367
|
+
placeholder,
|
|
368
|
+
maxLength: 14,
|
|
369
|
+
value: String(safeValue(field.value)),
|
|
370
|
+
disabled,
|
|
371
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
372
|
+
onKeyDown: (e) => {
|
|
373
|
+
var _a3;
|
|
374
|
+
if (disallowSpaces && e.key === " ") {
|
|
375
|
+
e.preventDefault();
|
|
376
|
+
}
|
|
377
|
+
if (e.key === "Backspace" && e.currentTarget.selectionStart === e.currentTarget.selectionEnd && e.currentTarget.selectionStart === e.currentTarget.value.length && e.currentTarget.value.endsWith("-")) {
|
|
378
|
+
e.preventDefault();
|
|
379
|
+
const nextValue = formatContaValue(
|
|
380
|
+
e.currentTarget.value.slice(0, -2)
|
|
381
|
+
);
|
|
382
|
+
helpers.setValue(nextValue);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
(_a3 = rest.onKeyDown) == null ? void 0 : _a3.call(rest, e);
|
|
386
|
+
},
|
|
387
|
+
onPaste: handlePasteFormik,
|
|
388
|
+
onChange: (e) => {
|
|
389
|
+
var _a3;
|
|
390
|
+
const val = sanitizeValue(formatContaValue(e.target.value));
|
|
391
|
+
e.target.value = val;
|
|
392
|
+
e.currentTarget.value = val;
|
|
393
|
+
helpers.setValue(val);
|
|
394
|
+
(_a3 = rest.onChange) == null ? void 0 : _a3.call(rest, e);
|
|
395
|
+
},
|
|
396
|
+
autoComplete: autoCompleteValue
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
if (mask && patternMasks[mask]) {
|
|
401
|
+
const patternValue = typeof field.value === "string" || typeof field.value === "number" ? field.value : "";
|
|
402
|
+
return /* @__PURE__ */ jsx2(
|
|
403
|
+
PatternFormat,
|
|
404
|
+
__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, rest), accessibilityProps), field), {
|
|
405
|
+
name,
|
|
406
|
+
value: patternValue,
|
|
407
|
+
defaultValue: "",
|
|
408
|
+
getInputRef: inputRef,
|
|
409
|
+
customInput: BaseInput,
|
|
410
|
+
format: patternMasks[mask],
|
|
411
|
+
allowEmptyFormatting: false,
|
|
412
|
+
mask: "",
|
|
413
|
+
placeholder,
|
|
414
|
+
onValueChange: handleValueChange,
|
|
415
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
416
|
+
autoComplete: autoCompleteValue,
|
|
417
|
+
disabled
|
|
418
|
+
})
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
return /* @__PURE__ */ jsx2(
|
|
422
|
+
"input",
|
|
423
|
+
__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, rest), accessibilityProps), field), {
|
|
424
|
+
name,
|
|
425
|
+
ref: inputRef,
|
|
426
|
+
placeholder,
|
|
427
|
+
type: inputType === "date" ? "text" : inputType,
|
|
428
|
+
value: String(safeValue(field.value)),
|
|
429
|
+
onKeyDown: (e) => {
|
|
430
|
+
var _a3;
|
|
431
|
+
if (disallowSpaces && e.key === " ") {
|
|
432
|
+
e.preventDefault();
|
|
433
|
+
}
|
|
434
|
+
(_a3 = rest.onKeyDown) == null ? void 0 : _a3.call(rest, e);
|
|
435
|
+
},
|
|
436
|
+
onPaste: handlePasteFormik,
|
|
437
|
+
onChange: (e) => {
|
|
438
|
+
var _a3;
|
|
439
|
+
const sanitizedValue = sanitizeValue(e.target.value);
|
|
440
|
+
helpers.setValue(sanitizedValue);
|
|
441
|
+
(_a3 = rest.onChange) == null ? void 0 : _a3.call(rest, e);
|
|
442
|
+
},
|
|
443
|
+
autoComplete: autoCompleteValue,
|
|
444
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
445
|
+
disabled
|
|
446
|
+
})
|
|
447
|
+
);
|
|
448
|
+
};
|
|
449
|
+
return /* @__PURE__ */ jsx2(
|
|
450
|
+
FieldFrame_default,
|
|
451
|
+
{
|
|
452
|
+
label,
|
|
453
|
+
labelFor: inputId,
|
|
454
|
+
invalid: Boolean(hasError),
|
|
455
|
+
message: meta.error,
|
|
456
|
+
messageId: errorId,
|
|
457
|
+
labelAdornment: helperText ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
458
|
+
/* @__PURE__ */ jsx2(
|
|
459
|
+
"button",
|
|
460
|
+
{
|
|
461
|
+
ref: iconRef,
|
|
462
|
+
onMouseEnter: () => setHovered(true),
|
|
463
|
+
onMouseLeave: () => setHovered(false),
|
|
464
|
+
onFocus: () => setHovered(true),
|
|
465
|
+
onBlur: () => setHovered(false),
|
|
466
|
+
type: "button",
|
|
467
|
+
"aria-label": `Mais informa\xE7\xF5es sobre ${label != null ? label : name}`,
|
|
468
|
+
className: "rounded-sm pb-[3px] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-1",
|
|
469
|
+
children: /* @__PURE__ */ jsx2(MdInfoOutline, { "aria-hidden": "true", className: "mr-0 text-content-muted" })
|
|
470
|
+
}
|
|
471
|
+
),
|
|
472
|
+
/* @__PURE__ */ jsx2(
|
|
473
|
+
Tooltip_default,
|
|
474
|
+
{
|
|
475
|
+
targetRef: iconRef,
|
|
476
|
+
content: helperText,
|
|
477
|
+
visible: hovered,
|
|
478
|
+
preferredPosition: "bottom"
|
|
479
|
+
}
|
|
480
|
+
)
|
|
481
|
+
] }) : void 0,
|
|
482
|
+
children: /* @__PURE__ */ jsxs2(
|
|
483
|
+
"div",
|
|
484
|
+
{
|
|
485
|
+
"data-has-value": String(safeValue(field.value)).length > 0,
|
|
486
|
+
className: classNames2(
|
|
487
|
+
FIELD_CONTROL_CLASS,
|
|
488
|
+
{
|
|
489
|
+
[FIELD_DISABLED_CLASS]: disabled,
|
|
490
|
+
[FIELD_ERROR_CLASS]: hasError
|
|
491
|
+
}
|
|
492
|
+
),
|
|
493
|
+
children: [
|
|
494
|
+
LeadIcon && /* @__PURE__ */ jsx2(
|
|
495
|
+
LeadIcon,
|
|
496
|
+
{
|
|
497
|
+
"aria-hidden": "true",
|
|
498
|
+
focusable: "false",
|
|
499
|
+
className: classNames2("h-5 w-5", {
|
|
500
|
+
"text-field-assistive-error": hasError
|
|
501
|
+
})
|
|
502
|
+
}
|
|
503
|
+
),
|
|
504
|
+
prefix && /* @__PURE__ */ jsx2("span", { children: prefix }),
|
|
505
|
+
renderMaskedInput(currentType),
|
|
506
|
+
suffix && /* @__PURE__ */ jsx2("span", { children: suffix }),
|
|
507
|
+
isPasswordType ? /* @__PURE__ */ jsx2(
|
|
508
|
+
"button",
|
|
509
|
+
{
|
|
510
|
+
type: "button",
|
|
511
|
+
"aria-label": showPassword ? "Ocultar senha" : "Mostrar senha",
|
|
512
|
+
"aria-pressed": showPassword,
|
|
513
|
+
onClick: () => setShowPassword((prev) => !prev),
|
|
514
|
+
className: "flex items-center justify-center rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-1",
|
|
515
|
+
children: showPassword ? /* @__PURE__ */ jsx2(
|
|
516
|
+
MdVisibilityOff,
|
|
517
|
+
{
|
|
518
|
+
"aria-hidden": "true",
|
|
519
|
+
className: classNames2("h-5 w-5", {
|
|
520
|
+
"text-field-assistive-error": hasError
|
|
521
|
+
})
|
|
522
|
+
}
|
|
523
|
+
) : /* @__PURE__ */ jsx2(
|
|
524
|
+
MdVisibility,
|
|
525
|
+
{
|
|
526
|
+
"aria-hidden": "true",
|
|
527
|
+
className: classNames2("h-5 w-5", {
|
|
528
|
+
"text-field-assistive-error": hasError
|
|
529
|
+
})
|
|
530
|
+
}
|
|
531
|
+
)
|
|
532
|
+
}
|
|
533
|
+
) : EndIcon && /* @__PURE__ */ jsx2(
|
|
534
|
+
EndIcon,
|
|
535
|
+
{
|
|
536
|
+
"aria-hidden": "true",
|
|
537
|
+
focusable: "false",
|
|
538
|
+
className: classNames2("h-5 w-5", {
|
|
539
|
+
"text-field-assistive-error": hasError
|
|
540
|
+
})
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
)
|
|
546
|
+
}
|
|
547
|
+
);
|
|
548
|
+
};
|
|
549
|
+
var Input_default = Input;
|
|
550
|
+
var InputStandalone = (props) => {
|
|
551
|
+
var _b, _c, _d;
|
|
552
|
+
const _a = props, {
|
|
553
|
+
label,
|
|
554
|
+
helperText,
|
|
555
|
+
prefix,
|
|
556
|
+
suffix,
|
|
557
|
+
mask,
|
|
558
|
+
disabled,
|
|
559
|
+
error,
|
|
560
|
+
errorText,
|
|
561
|
+
disallowSpaces,
|
|
562
|
+
leadIcon: LeadIcon,
|
|
563
|
+
endIcon: EndIcon,
|
|
564
|
+
type,
|
|
565
|
+
className
|
|
566
|
+
} = _a, rest = __objRest(_a, [
|
|
567
|
+
"label",
|
|
568
|
+
"helperText",
|
|
569
|
+
"prefix",
|
|
570
|
+
"suffix",
|
|
571
|
+
"mask",
|
|
572
|
+
"disabled",
|
|
573
|
+
"error",
|
|
574
|
+
"errorText",
|
|
575
|
+
"disallowSpaces",
|
|
576
|
+
"leadIcon",
|
|
577
|
+
"endIcon",
|
|
578
|
+
"type",
|
|
579
|
+
"className"
|
|
580
|
+
]);
|
|
581
|
+
const inputRef = useRef(null);
|
|
582
|
+
const iconRef = useRef(null);
|
|
583
|
+
const [hovered, setHovered] = useState(false);
|
|
584
|
+
const isPasswordType = type === "password";
|
|
585
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
586
|
+
const currentType = isPasswordType ? showPassword ? "text" : "password" : type;
|
|
587
|
+
const hasError = Boolean(error);
|
|
588
|
+
const generatedInputId = useId();
|
|
589
|
+
const inputId = (_b = rest.id) != null ? _b : generatedInputId;
|
|
590
|
+
const errorId = `${inputId}-error`;
|
|
591
|
+
const ariaDescribedBy = mergeAriaDescribedBy(
|
|
592
|
+
rest["aria-describedby"],
|
|
593
|
+
hasError && errorText ? errorId : void 0
|
|
594
|
+
);
|
|
595
|
+
const accessibilityProps = {
|
|
596
|
+
id: inputId,
|
|
597
|
+
"aria-invalid": hasError || void 0,
|
|
598
|
+
"aria-describedby": ariaDescribedBy
|
|
599
|
+
};
|
|
600
|
+
const safeValue = (v) => v === void 0 || v === null ? "" : v;
|
|
601
|
+
const sanitizeValue = useCallback(
|
|
602
|
+
(value) => {
|
|
603
|
+
if (!disallowSpaces) return value;
|
|
604
|
+
return value.replace(/\s/g, "");
|
|
605
|
+
},
|
|
606
|
+
[disallowSpaces]
|
|
607
|
+
);
|
|
608
|
+
const handlePasteStandalone = useCallback(
|
|
609
|
+
(e) => {
|
|
610
|
+
var _a2, _b2, _c2;
|
|
611
|
+
if (!disallowSpaces) {
|
|
612
|
+
(_a2 = rest.onPaste) == null ? void 0 : _a2.call(rest, e);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
e.preventDefault();
|
|
616
|
+
const pastedText = e.clipboardData.getData("text");
|
|
617
|
+
const sanitizedValue = sanitizeValue(pastedText);
|
|
618
|
+
const syntheticEvent = __spreadProps(__spreadValues({}, e), {
|
|
619
|
+
target: __spreadProps(__spreadValues({}, e.target), {
|
|
620
|
+
value: sanitizedValue
|
|
621
|
+
}),
|
|
622
|
+
currentTarget: __spreadProps(__spreadValues({}, e.currentTarget), {
|
|
623
|
+
value: sanitizedValue
|
|
624
|
+
})
|
|
625
|
+
});
|
|
626
|
+
(_b2 = rest.onChange) == null ? void 0 : _b2.call(rest, syntheticEvent);
|
|
627
|
+
(_c2 = rest.onPaste) == null ? void 0 : _c2.call(rest, e);
|
|
628
|
+
},
|
|
629
|
+
[disallowSpaces, rest, sanitizeValue]
|
|
630
|
+
);
|
|
631
|
+
const cleanSpecialChars = (value) => {
|
|
632
|
+
if (!value) return "";
|
|
633
|
+
let newValue = value;
|
|
634
|
+
newValue = newValue.replace(/[áàãâä]/gi, "a");
|
|
635
|
+
newValue = newValue.replace(/[éèêë]/gi, "e");
|
|
636
|
+
newValue = newValue.replace(/[íìîï]/gi, "i");
|
|
637
|
+
newValue = newValue.replace(/[óòõôö]/gi, "o");
|
|
638
|
+
newValue = newValue.replace(/[úùûü]/gi, "u");
|
|
639
|
+
newValue = newValue.replace(/[ç]/gi, "c");
|
|
640
|
+
newValue = newValue.replace(/['"`´@!#$%&¨()*;:?\-_+={}\[\]\\\/|<>.,]/g, "");
|
|
641
|
+
return newValue;
|
|
642
|
+
};
|
|
643
|
+
const patternMasks = {
|
|
644
|
+
cpf: "###.###.###-##",
|
|
645
|
+
cnpj: "##.###.###/####-##",
|
|
646
|
+
cep: "#####-###",
|
|
647
|
+
phone: "(##) #####-####",
|
|
648
|
+
date: "##/##/####",
|
|
649
|
+
agencia: "####"
|
|
650
|
+
};
|
|
651
|
+
const renderMaskedInput = (inputType) => {
|
|
652
|
+
const autoCompleteValue = rest.autoComplete;
|
|
653
|
+
if (mask === "currency") {
|
|
654
|
+
const rawCurrencyValue = typeof rest.value === "string" || typeof rest.value === "number" ? rest.value : "";
|
|
655
|
+
return /* @__PURE__ */ jsx2(
|
|
656
|
+
"input",
|
|
657
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
658
|
+
ref: inputRef,
|
|
659
|
+
type: "text",
|
|
660
|
+
inputMode: "numeric",
|
|
661
|
+
value: formatCurrencyDigitsForDisplay(rawCurrencyValue),
|
|
662
|
+
onChange: (e) => {
|
|
663
|
+
if (rest.onChange) {
|
|
664
|
+
const formattedCurrencyValue = formatCurrencyDigitsForDisplay(
|
|
665
|
+
e.target.value
|
|
666
|
+
);
|
|
667
|
+
const event = {
|
|
668
|
+
target: { value: formattedCurrencyValue },
|
|
669
|
+
currentTarget: { value: formattedCurrencyValue }
|
|
670
|
+
};
|
|
671
|
+
rest.onChange(event);
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
placeholder: rest.placeholder,
|
|
675
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
676
|
+
autoComplete: autoCompleteValue,
|
|
677
|
+
disabled
|
|
678
|
+
})
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
if (mask === "specialChars") {
|
|
682
|
+
return /* @__PURE__ */ jsx2(
|
|
683
|
+
"input",
|
|
684
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
685
|
+
ref: inputRef,
|
|
686
|
+
placeholder: rest.placeholder,
|
|
687
|
+
type: inputType === "date" ? "text" : inputType,
|
|
688
|
+
value: String(safeValue(rest.value)),
|
|
689
|
+
onKeyDown: (e) => {
|
|
690
|
+
var _a2;
|
|
691
|
+
if (disallowSpaces && e.key === " ") {
|
|
692
|
+
e.preventDefault();
|
|
693
|
+
}
|
|
694
|
+
(_a2 = rest.onKeyDown) == null ? void 0 : _a2.call(rest, e);
|
|
695
|
+
},
|
|
696
|
+
onPaste: handlePasteStandalone,
|
|
697
|
+
onChange: (e) => {
|
|
698
|
+
var _a2;
|
|
699
|
+
const cleaned = cleanSpecialChars(e.target.value);
|
|
700
|
+
const sanitizedValue = sanitizeValue(cleaned);
|
|
701
|
+
e.target.value = sanitizedValue;
|
|
702
|
+
(_a2 = rest.onChange) == null ? void 0 : _a2.call(rest, e);
|
|
703
|
+
},
|
|
704
|
+
autoComplete: autoCompleteValue,
|
|
705
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
706
|
+
disabled
|
|
707
|
+
})
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
if (mask === "datePicker") {
|
|
711
|
+
const dateValue = rest.value ? typeof rest.value === "string" ? rest.value : rest.value instanceof Date ? rest.value.toLocaleDateString("pt-BR") : String(rest.value) : "";
|
|
712
|
+
return /* @__PURE__ */ jsx2(
|
|
713
|
+
"input",
|
|
714
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
715
|
+
ref: inputRef,
|
|
716
|
+
placeholder: rest.placeholder,
|
|
717
|
+
type: inputType,
|
|
718
|
+
value: dateValue,
|
|
719
|
+
onKeyDown: (e) => {
|
|
720
|
+
var _a2;
|
|
721
|
+
if (disallowSpaces && e.key === " ") {
|
|
722
|
+
e.preventDefault();
|
|
723
|
+
}
|
|
724
|
+
(_a2 = rest.onKeyDown) == null ? void 0 : _a2.call(rest, e);
|
|
725
|
+
},
|
|
726
|
+
onPaste: handlePasteStandalone,
|
|
727
|
+
onChange: (e) => {
|
|
728
|
+
var _a2;
|
|
729
|
+
const cleaned = cleanSpecialChars(e.target.value);
|
|
730
|
+
const sanitizedValue = sanitizeValue(cleaned);
|
|
731
|
+
e.target.value = sanitizedValue;
|
|
732
|
+
(_a2 = rest.onChange) == null ? void 0 : _a2.call(rest, e);
|
|
733
|
+
},
|
|
734
|
+
autoComplete: autoCompleteValue,
|
|
735
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
736
|
+
disabled
|
|
737
|
+
})
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
if (mask === "conta") {
|
|
741
|
+
return /* @__PURE__ */ jsx2(
|
|
742
|
+
"input",
|
|
743
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
744
|
+
ref: inputRef,
|
|
745
|
+
placeholder: rest.placeholder,
|
|
746
|
+
maxLength: 14,
|
|
747
|
+
value: String(safeValue(rest.value)),
|
|
748
|
+
disabled,
|
|
749
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
750
|
+
onKeyDown: (e) => {
|
|
751
|
+
var _a2;
|
|
752
|
+
if (disallowSpaces && e.key === " ") {
|
|
753
|
+
e.preventDefault();
|
|
754
|
+
}
|
|
755
|
+
if (e.key === "Backspace" && e.currentTarget.selectionStart === e.currentTarget.selectionEnd && e.currentTarget.selectionStart === e.currentTarget.value.length && e.currentTarget.value.endsWith("-")) {
|
|
756
|
+
e.preventDefault();
|
|
757
|
+
const nextValue = formatContaValue(
|
|
758
|
+
e.currentTarget.value.slice(0, -2)
|
|
759
|
+
);
|
|
760
|
+
e.currentTarget.value = nextValue;
|
|
761
|
+
if (rest.onChange) {
|
|
762
|
+
const event = {
|
|
763
|
+
target: { value: nextValue },
|
|
764
|
+
currentTarget: { value: nextValue }
|
|
765
|
+
};
|
|
766
|
+
rest.onChange(event);
|
|
767
|
+
}
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
(_a2 = rest.onKeyDown) == null ? void 0 : _a2.call(rest, e);
|
|
771
|
+
},
|
|
772
|
+
onPaste: handlePasteStandalone,
|
|
773
|
+
onChange: (e) => {
|
|
774
|
+
var _a2;
|
|
775
|
+
const val = sanitizeValue(formatContaValue(e.target.value));
|
|
776
|
+
e.target.value = val;
|
|
777
|
+
(_a2 = rest.onChange) == null ? void 0 : _a2.call(rest, e);
|
|
778
|
+
},
|
|
779
|
+
autoComplete: autoCompleteValue
|
|
780
|
+
})
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
if (mask && patternMasks[mask]) {
|
|
784
|
+
const patternValue = typeof rest.value === "string" || typeof rest.value === "number" ? rest.value : "";
|
|
785
|
+
return /* @__PURE__ */ jsx2(
|
|
786
|
+
PatternFormat,
|
|
787
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
788
|
+
value: patternValue,
|
|
789
|
+
defaultValue: "",
|
|
790
|
+
getInputRef: inputRef,
|
|
791
|
+
customInput: BaseInput,
|
|
792
|
+
format: patternMasks[mask],
|
|
793
|
+
allowEmptyFormatting: false,
|
|
794
|
+
mask: "",
|
|
795
|
+
placeholder: rest.placeholder,
|
|
796
|
+
onValueChange: (values) => {
|
|
797
|
+
if (rest.onChange) {
|
|
798
|
+
const event = {
|
|
799
|
+
target: { value: values.value }
|
|
800
|
+
};
|
|
801
|
+
rest.onChange(event);
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
805
|
+
autoComplete: autoCompleteValue,
|
|
806
|
+
disabled
|
|
807
|
+
})
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
return /* @__PURE__ */ jsx2(
|
|
811
|
+
"input",
|
|
812
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), accessibilityProps), {
|
|
813
|
+
ref: inputRef,
|
|
814
|
+
placeholder: rest.placeholder,
|
|
815
|
+
type: inputType === "date" ? "text" : inputType,
|
|
816
|
+
value: String(safeValue(rest.value)),
|
|
817
|
+
onKeyDown: (e) => {
|
|
818
|
+
var _a2;
|
|
819
|
+
if (disallowSpaces && e.key === " ") {
|
|
820
|
+
e.preventDefault();
|
|
821
|
+
}
|
|
822
|
+
(_a2 = rest.onKeyDown) == null ? void 0 : _a2.call(rest, e);
|
|
823
|
+
},
|
|
824
|
+
onPaste: handlePasteStandalone,
|
|
825
|
+
onChange: (e) => {
|
|
826
|
+
var _a2;
|
|
827
|
+
const sanitizedValue = sanitizeValue(e.target.value);
|
|
828
|
+
e.target.value = sanitizedValue;
|
|
829
|
+
(_a2 = rest.onChange) == null ? void 0 : _a2.call(rest, e);
|
|
830
|
+
},
|
|
831
|
+
autoComplete: autoCompleteValue,
|
|
832
|
+
className: classNames2(FIELD_INPUT_CLASS, className),
|
|
833
|
+
disabled
|
|
834
|
+
})
|
|
835
|
+
);
|
|
836
|
+
};
|
|
837
|
+
return /* @__PURE__ */ jsx2(
|
|
838
|
+
FieldFrame_default,
|
|
839
|
+
{
|
|
840
|
+
label,
|
|
841
|
+
labelFor: inputId,
|
|
842
|
+
invalid: Boolean(hasError),
|
|
843
|
+
message: errorText,
|
|
844
|
+
messageId: errorId,
|
|
845
|
+
labelAdornment: helperText ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
846
|
+
/* @__PURE__ */ jsx2(
|
|
847
|
+
"button",
|
|
848
|
+
{
|
|
849
|
+
ref: iconRef,
|
|
850
|
+
onMouseEnter: () => setHovered(true),
|
|
851
|
+
onMouseLeave: () => setHovered(false),
|
|
852
|
+
onFocus: () => setHovered(true),
|
|
853
|
+
onBlur: () => setHovered(false),
|
|
854
|
+
type: "button",
|
|
855
|
+
"aria-label": `Mais informa\xE7\xF5es sobre ${(_c = label != null ? label : rest.name) != null ? _c : "este campo"}`,
|
|
856
|
+
className: "rounded-sm pb-[3px] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-1",
|
|
857
|
+
children: /* @__PURE__ */ jsx2(MdInfoOutline, { "aria-hidden": "true", className: "mr-0 text-content-muted" })
|
|
858
|
+
}
|
|
859
|
+
),
|
|
860
|
+
/* @__PURE__ */ jsx2(
|
|
861
|
+
Tooltip_default,
|
|
862
|
+
{
|
|
863
|
+
targetRef: iconRef,
|
|
864
|
+
content: helperText,
|
|
865
|
+
visible: hovered,
|
|
866
|
+
preferredPosition: "bottom"
|
|
867
|
+
}
|
|
868
|
+
)
|
|
869
|
+
] }) : void 0,
|
|
870
|
+
children: /* @__PURE__ */ jsxs2(
|
|
871
|
+
"div",
|
|
872
|
+
{
|
|
873
|
+
"data-has-value": String(safeValue((_d = rest.value) != null ? _d : rest.defaultValue)).length > 0,
|
|
874
|
+
className: classNames2(
|
|
875
|
+
FIELD_CONTROL_CLASS,
|
|
876
|
+
{
|
|
877
|
+
[FIELD_DISABLED_CLASS]: disabled,
|
|
878
|
+
[FIELD_ERROR_CLASS]: hasError
|
|
879
|
+
}
|
|
880
|
+
),
|
|
881
|
+
children: [
|
|
882
|
+
LeadIcon && /* @__PURE__ */ jsx2(
|
|
883
|
+
LeadIcon,
|
|
884
|
+
{
|
|
885
|
+
"aria-hidden": "true",
|
|
886
|
+
focusable: "false",
|
|
887
|
+
className: classNames2("h-5 w-5", {
|
|
888
|
+
"text-field-assistive-error": hasError
|
|
889
|
+
})
|
|
890
|
+
}
|
|
891
|
+
),
|
|
892
|
+
prefix && /* @__PURE__ */ jsx2("span", { children: prefix }),
|
|
893
|
+
renderMaskedInput(currentType),
|
|
894
|
+
suffix && /* @__PURE__ */ jsx2("span", { children: suffix }),
|
|
895
|
+
isPasswordType ? /* @__PURE__ */ jsx2(
|
|
896
|
+
"button",
|
|
897
|
+
{
|
|
898
|
+
type: "button",
|
|
899
|
+
"aria-label": showPassword ? "Ocultar senha" : "Mostrar senha",
|
|
900
|
+
"aria-pressed": showPassword,
|
|
901
|
+
onClick: () => setShowPassword((prev) => !prev),
|
|
902
|
+
className: "flex items-center justify-center rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-1",
|
|
903
|
+
children: showPassword ? /* @__PURE__ */ jsx2(
|
|
904
|
+
MdVisibilityOff,
|
|
905
|
+
{
|
|
906
|
+
"aria-hidden": "true",
|
|
907
|
+
className: classNames2("h-5 w-5", {
|
|
908
|
+
"text-field-assistive-error": hasError
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
) : /* @__PURE__ */ jsx2(
|
|
912
|
+
MdVisibility,
|
|
913
|
+
{
|
|
914
|
+
"aria-hidden": "true",
|
|
915
|
+
className: classNames2("h-5 w-5", {
|
|
916
|
+
"text-field-assistive-error": hasError
|
|
917
|
+
})
|
|
918
|
+
}
|
|
919
|
+
)
|
|
920
|
+
}
|
|
921
|
+
) : EndIcon && /* @__PURE__ */ jsx2(
|
|
922
|
+
EndIcon,
|
|
923
|
+
{
|
|
924
|
+
"aria-hidden": "true",
|
|
925
|
+
focusable: "false",
|
|
926
|
+
className: classNames2("h-5 w-5", {
|
|
927
|
+
"text-field-assistive-error": hasError
|
|
928
|
+
})
|
|
929
|
+
}
|
|
930
|
+
)
|
|
931
|
+
]
|
|
932
|
+
}
|
|
933
|
+
)
|
|
934
|
+
}
|
|
935
|
+
);
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
// src/components/inputSelect/InputSelect.tsx
|
|
939
|
+
import classNames3 from "classnames";
|
|
940
|
+
import { useField as useField2 } from "formik";
|
|
941
|
+
import { useCallback as useCallback2, useEffect, useId as useId2, useRef as useRef2, useState as useState2 } from "react";
|
|
942
|
+
import { createPortal } from "react-dom";
|
|
943
|
+
|
|
944
|
+
// src/utils/floating-panel-position.ts
|
|
945
|
+
function clamp(value, minimum, maximum) {
|
|
946
|
+
return Math.min(Math.max(value, minimum), Math.max(minimum, maximum));
|
|
947
|
+
}
|
|
948
|
+
function calculateFloatingPanelRect({
|
|
949
|
+
trigger,
|
|
950
|
+
panel,
|
|
951
|
+
viewport,
|
|
952
|
+
gap = 4,
|
|
953
|
+
margin = 8
|
|
954
|
+
}) {
|
|
955
|
+
const viewportWidth = Math.max(0, viewport.width - margin * 2);
|
|
956
|
+
const viewportHeight = Math.max(0, viewport.height - margin * 2);
|
|
957
|
+
const width = Math.min(Math.max(0, panel.width), viewportWidth);
|
|
958
|
+
const desiredHeight = Math.min(Math.max(0, panel.height), viewportHeight);
|
|
959
|
+
const spaceBelow = Math.max(
|
|
960
|
+
0,
|
|
961
|
+
viewport.height - trigger.bottom - gap - margin
|
|
962
|
+
);
|
|
963
|
+
const spaceAbove = Math.max(0, trigger.top - gap - margin);
|
|
964
|
+
let top = margin;
|
|
965
|
+
let placement = "viewport";
|
|
966
|
+
if (spaceBelow >= desiredHeight) {
|
|
967
|
+
top = trigger.bottom + gap;
|
|
968
|
+
placement = "bottom";
|
|
969
|
+
} else if (spaceAbove >= desiredHeight) {
|
|
970
|
+
top = trigger.top - desiredHeight - gap;
|
|
971
|
+
placement = "top";
|
|
972
|
+
}
|
|
973
|
+
return {
|
|
974
|
+
top,
|
|
975
|
+
left: clamp(trigger.left, margin, viewport.width - width - margin),
|
|
976
|
+
width,
|
|
977
|
+
maxHeight: desiredHeight,
|
|
978
|
+
placement
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// src/components/inputSelect/InputSelect.tsx
|
|
983
|
+
import {
|
|
984
|
+
MdInfoOutline as MdInfoOutline2,
|
|
985
|
+
MdOutlineKeyboardArrowDown,
|
|
986
|
+
MdOutlineKeyboardArrowUp,
|
|
987
|
+
MdSearch
|
|
988
|
+
} from "react-icons/md";
|
|
989
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
990
|
+
var InputSelect = (_a) => {
|
|
991
|
+
var _b = _a, {
|
|
992
|
+
name,
|
|
993
|
+
label,
|
|
994
|
+
helperText,
|
|
995
|
+
placeholder,
|
|
996
|
+
defaultValue,
|
|
997
|
+
options,
|
|
998
|
+
prefix,
|
|
999
|
+
suffix,
|
|
1000
|
+
disabled,
|
|
1001
|
+
error,
|
|
1002
|
+
leadIcon: LeadIcon,
|
|
1003
|
+
endIcon: EndIcon,
|
|
1004
|
+
searchable,
|
|
1005
|
+
searchPlaceholder = "Pesquisar...",
|
|
1006
|
+
noOptionsText = "Nenhuma op\xE7\xE3o encontrada",
|
|
1007
|
+
renderOption,
|
|
1008
|
+
renderValue,
|
|
1009
|
+
searchAccessor,
|
|
1010
|
+
className,
|
|
1011
|
+
onChange
|
|
1012
|
+
} = _b, rest = __objRest(_b, [
|
|
1013
|
+
"name",
|
|
1014
|
+
"label",
|
|
1015
|
+
"helperText",
|
|
1016
|
+
"placeholder",
|
|
1017
|
+
"defaultValue",
|
|
1018
|
+
"options",
|
|
1019
|
+
"prefix",
|
|
1020
|
+
"suffix",
|
|
1021
|
+
"disabled",
|
|
1022
|
+
"error",
|
|
1023
|
+
"leadIcon",
|
|
1024
|
+
"endIcon",
|
|
1025
|
+
"searchable",
|
|
1026
|
+
"searchPlaceholder",
|
|
1027
|
+
"noOptionsText",
|
|
1028
|
+
"renderOption",
|
|
1029
|
+
"renderValue",
|
|
1030
|
+
"searchAccessor",
|
|
1031
|
+
"className",
|
|
1032
|
+
"onChange"
|
|
1033
|
+
]);
|
|
1034
|
+
const isSearchable = searchable != null ? searchable : options.length > 10;
|
|
1035
|
+
const normalizeSearchText2 = (value) => value.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
1036
|
+
const [field, meta, helpers] = useField2(name);
|
|
1037
|
+
const inputRef = useRef2(null);
|
|
1038
|
+
const dropdownRef = useRef2(null);
|
|
1039
|
+
const iconRef = useRef2(null);
|
|
1040
|
+
const searchInputRef = useRef2(null);
|
|
1041
|
+
const [hovered, setHovered] = useState2(false);
|
|
1042
|
+
const [open, setOpen] = useState2(false);
|
|
1043
|
+
const [searchTerm, setSearchTerm] = useState2("");
|
|
1044
|
+
const [selectionAnnouncement, setSelectionAnnouncement] = useState2("");
|
|
1045
|
+
const [isMounted, setIsMounted] = useState2(false);
|
|
1046
|
+
const rafRef = useRef2(null);
|
|
1047
|
+
const selectId = useId2();
|
|
1048
|
+
const labelId = `${selectId}-label`;
|
|
1049
|
+
const listboxId = `${selectId}-listbox`;
|
|
1050
|
+
const resultsId = `${selectId}-results`;
|
|
1051
|
+
const valueDescriptionId = `${selectId}-value-description`;
|
|
1052
|
+
useEffect(() => {
|
|
1053
|
+
setIsMounted(true);
|
|
1054
|
+
}, []);
|
|
1055
|
+
const updateDropdownPosition = useCallback2(() => {
|
|
1056
|
+
if (open && inputRef.current) {
|
|
1057
|
+
const rect = inputRef.current.getBoundingClientRect();
|
|
1058
|
+
const dropdown = dropdownRef.current;
|
|
1059
|
+
if (!dropdown) return;
|
|
1060
|
+
const panelRect = calculateFloatingPanelRect({
|
|
1061
|
+
trigger: rect,
|
|
1062
|
+
panel: {
|
|
1063
|
+
width: rect.width,
|
|
1064
|
+
height: Math.min(dropdown.scrollHeight || 240, 240)
|
|
1065
|
+
},
|
|
1066
|
+
viewport: {
|
|
1067
|
+
width: window.innerWidth,
|
|
1068
|
+
height: window.innerHeight
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
dropdown.style.top = `${panelRect.top}px`;
|
|
1072
|
+
dropdown.style.left = `${panelRect.left}px`;
|
|
1073
|
+
dropdown.style.width = `${panelRect.width}px`;
|
|
1074
|
+
dropdown.style.maxHeight = `${panelRect.maxHeight}px`;
|
|
1075
|
+
}
|
|
1076
|
+
}, [open]);
|
|
1077
|
+
useEffect(() => {
|
|
1078
|
+
var _a2, _b2, _c, _d;
|
|
1079
|
+
if (!open) return;
|
|
1080
|
+
if (isSearchable) {
|
|
1081
|
+
(_a2 = searchInputRef.current) == null ? void 0 : _a2.focus({ preventScroll: true });
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
const selectedOptionElement = (_b2 = dropdownRef.current) == null ? void 0 : _b2.querySelector(
|
|
1085
|
+
'[role="option"][aria-selected="true"]'
|
|
1086
|
+
);
|
|
1087
|
+
const firstOptionElement = (_c = dropdownRef.current) == null ? void 0 : _c.querySelector('[role="option"]');
|
|
1088
|
+
(_d = selectedOptionElement != null ? selectedOptionElement : firstOptionElement) == null ? void 0 : _d.focus({
|
|
1089
|
+
preventScroll: true
|
|
1090
|
+
});
|
|
1091
|
+
}, [isSearchable, open]);
|
|
1092
|
+
useEffect(() => {
|
|
1093
|
+
if (!open) {
|
|
1094
|
+
setSearchTerm("");
|
|
1095
|
+
}
|
|
1096
|
+
}, [open]);
|
|
1097
|
+
useEffect(() => {
|
|
1098
|
+
if (open && dropdownRef.current) {
|
|
1099
|
+
updateDropdownPosition();
|
|
1100
|
+
}
|
|
1101
|
+
}, [open, updateDropdownPosition]);
|
|
1102
|
+
useEffect(() => {
|
|
1103
|
+
if (!open) return;
|
|
1104
|
+
const scheduleDropdownPosition = () => {
|
|
1105
|
+
if (rafRef.current != null) return;
|
|
1106
|
+
rafRef.current = window.requestAnimationFrame(() => {
|
|
1107
|
+
rafRef.current = null;
|
|
1108
|
+
updateDropdownPosition();
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
window.addEventListener("scroll", scheduleDropdownPosition, true);
|
|
1112
|
+
window.addEventListener("resize", scheduleDropdownPosition);
|
|
1113
|
+
return () => {
|
|
1114
|
+
if (rafRef.current != null) {
|
|
1115
|
+
window.cancelAnimationFrame(rafRef.current);
|
|
1116
|
+
rafRef.current = null;
|
|
1117
|
+
}
|
|
1118
|
+
window.removeEventListener("scroll", scheduleDropdownPosition, true);
|
|
1119
|
+
window.removeEventListener("resize", scheduleDropdownPosition);
|
|
1120
|
+
};
|
|
1121
|
+
}, [open, updateDropdownPosition]);
|
|
1122
|
+
const selectedOption = options.find((o) => o.value === (field.value || (defaultValue == null ? void 0 : defaultValue.value))) || null;
|
|
1123
|
+
const closeDropdown = useCallback2((restoreFocus = false) => {
|
|
1124
|
+
var _a2;
|
|
1125
|
+
setOpen(false);
|
|
1126
|
+
if (restoreFocus) {
|
|
1127
|
+
(_a2 = inputRef.current) == null ? void 0 : _a2.focus({ preventScroll: true });
|
|
1128
|
+
}
|
|
1129
|
+
}, []);
|
|
1130
|
+
const moveFocusFromTrigger = useCallback2((backward) => {
|
|
1131
|
+
var _a2;
|
|
1132
|
+
const trigger = inputRef.current;
|
|
1133
|
+
if (!trigger) return;
|
|
1134
|
+
const focusableElements = Array.from(
|
|
1135
|
+
document.querySelectorAll(
|
|
1136
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
1137
|
+
)
|
|
1138
|
+
).filter(
|
|
1139
|
+
(element) => {
|
|
1140
|
+
var _a3;
|
|
1141
|
+
return !((_a3 = dropdownRef.current) == null ? void 0 : _a3.contains(element)) && element.getAttribute("aria-hidden") !== "true" && element.getClientRects().length > 0;
|
|
1142
|
+
}
|
|
1143
|
+
);
|
|
1144
|
+
const triggerIndex = focusableElements.indexOf(trigger);
|
|
1145
|
+
const targetIndex = triggerIndex + (backward ? -1 : 1);
|
|
1146
|
+
(_a2 = focusableElements[targetIndex]) == null ? void 0 : _a2.focus({ preventScroll: true });
|
|
1147
|
+
}, []);
|
|
1148
|
+
const handleSelect = (value) => {
|
|
1149
|
+
const option = options.find((candidate) => candidate.value === value);
|
|
1150
|
+
helpers.setValue(value);
|
|
1151
|
+
helpers.setTouched(true);
|
|
1152
|
+
setSelectionAnnouncement(
|
|
1153
|
+
option ? `Selecionado: ${option.label}` : "Sele\xE7\xE3o atualizada"
|
|
1154
|
+
);
|
|
1155
|
+
if (onChange) {
|
|
1156
|
+
const syntheticEvent = {
|
|
1157
|
+
target: { value, name },
|
|
1158
|
+
currentTarget: { value, name }
|
|
1159
|
+
};
|
|
1160
|
+
onChange(syntheticEvent);
|
|
1161
|
+
}
|
|
1162
|
+
closeDropdown(true);
|
|
1163
|
+
};
|
|
1164
|
+
const handleBlur = useCallback2(() => {
|
|
1165
|
+
helpers.setTouched(true);
|
|
1166
|
+
}, [helpers]);
|
|
1167
|
+
useEffect(() => {
|
|
1168
|
+
const handleClickOutside = (event) => {
|
|
1169
|
+
if (inputRef.current && !inputRef.current.contains(event.target) && (!dropdownRef.current || !dropdownRef.current.contains(event.target))) {
|
|
1170
|
+
handleBlur();
|
|
1171
|
+
closeDropdown();
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
if (open) {
|
|
1175
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
1176
|
+
}
|
|
1177
|
+
return () => {
|
|
1178
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
1179
|
+
};
|
|
1180
|
+
}, [closeDropdown, handleBlur, open]);
|
|
1181
|
+
const hasError = meta.touched && meta.error;
|
|
1182
|
+
const errorId = `${selectId}-error`;
|
|
1183
|
+
const normalizedSearch = normalizeSearchText2(searchTerm.trim());
|
|
1184
|
+
const filteredOptions = isSearchable ? options.filter((option) => {
|
|
1185
|
+
const label2 = normalizeSearchText2(String(option.label || ""));
|
|
1186
|
+
const value = normalizeSearchText2(String(option.value || ""));
|
|
1187
|
+
const extraSearch = normalizeSearchText2(
|
|
1188
|
+
String((searchAccessor == null ? void 0 : searchAccessor(option)) || "")
|
|
1189
|
+
);
|
|
1190
|
+
return label2.includes(normalizedSearch) || value.includes(normalizedSearch) || extraSearch.includes(normalizedSearch);
|
|
1191
|
+
}) : options;
|
|
1192
|
+
const resultAnnouncement = filteredOptions.length === 0 ? noOptionsText : normalizedSearch ? filteredOptions.length === 1 ? "1 resultado encontrado" : `${filteredOptions.length} resultados encontrados` : filteredOptions.length === 1 ? "1 op\xE7\xE3o dispon\xEDvel" : `${filteredOptions.length} op\xE7\xF5es dispon\xEDveis`;
|
|
1193
|
+
const selectedValueDescription = selectedOption ? `Selecionado: ${selectedOption.label}` : placeholder ? `Nenhuma op\xE7\xE3o selecionada. ${placeholder}` : "Nenhuma op\xE7\xE3o selecionada";
|
|
1194
|
+
const triggerDescribedBy = [
|
|
1195
|
+
valueDescriptionId,
|
|
1196
|
+
hasError ? errorId : void 0
|
|
1197
|
+
].filter(Boolean).join(" ");
|
|
1198
|
+
const focusOption = (position) => {
|
|
1199
|
+
var _a2, _b2;
|
|
1200
|
+
const optionElements = Array.from(
|
|
1201
|
+
(_b2 = (_a2 = dropdownRef.current) == null ? void 0 : _a2.querySelectorAll(
|
|
1202
|
+
'[role="option"]'
|
|
1203
|
+
)) != null ? _b2 : []
|
|
1204
|
+
);
|
|
1205
|
+
const option = position === "first" ? optionElements[0] : optionElements[optionElements.length - 1];
|
|
1206
|
+
option == null ? void 0 : option.focus({ preventScroll: true });
|
|
1207
|
+
};
|
|
1208
|
+
const handleOptionKeyDown = (event) => {
|
|
1209
|
+
var _a2, _b2, _c, _d, _e;
|
|
1210
|
+
const optionElements = Array.from(
|
|
1211
|
+
(_b2 = (_a2 = dropdownRef.current) == null ? void 0 : _a2.querySelectorAll(
|
|
1212
|
+
'[role="option"]'
|
|
1213
|
+
)) != null ? _b2 : []
|
|
1214
|
+
);
|
|
1215
|
+
const currentIndex = optionElements.indexOf(event.currentTarget);
|
|
1216
|
+
if (event.key === "Escape") {
|
|
1217
|
+
event.preventDefault();
|
|
1218
|
+
closeDropdown(true);
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
if (event.key === "Tab") {
|
|
1222
|
+
event.preventDefault();
|
|
1223
|
+
closeDropdown();
|
|
1224
|
+
handleBlur();
|
|
1225
|
+
moveFocusFromTrigger(event.shiftKey);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp" && event.key !== "Home" && event.key !== "End") {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
event.preventDefault();
|
|
1232
|
+
if (event.key === "Home") {
|
|
1233
|
+
(_c = optionElements[0]) == null ? void 0 : _c.focus({ preventScroll: true });
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
if (event.key === "End") {
|
|
1237
|
+
(_d = optionElements[optionElements.length - 1]) == null ? void 0 : _d.focus({
|
|
1238
|
+
preventScroll: true
|
|
1239
|
+
});
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
1243
|
+
const nextIndex = (currentIndex + direction + optionElements.length) % optionElements.length;
|
|
1244
|
+
(_e = optionElements[nextIndex]) == null ? void 0 : _e.focus({ preventScroll: true });
|
|
1245
|
+
};
|
|
1246
|
+
const selectedValueContent = renderValue ? renderValue(selectedOption, placeholder) : /* @__PURE__ */ jsx3(
|
|
1247
|
+
"span",
|
|
1248
|
+
{
|
|
1249
|
+
className: classNames3("block w-full truncate overflow-hidden", {
|
|
1250
|
+
"text-field-placeholder": !selectedOption && placeholder
|
|
1251
|
+
}),
|
|
1252
|
+
children: selectedOption ? selectedOption.label : placeholder
|
|
1253
|
+
}
|
|
1254
|
+
);
|
|
1255
|
+
const dropdownContent = open && !disabled ? /* @__PURE__ */ jsxs3(
|
|
1256
|
+
"div",
|
|
1257
|
+
{
|
|
1258
|
+
ref: dropdownRef,
|
|
1259
|
+
className: `fixed ${getFloatingLayerClass(inputRef.current, "popover")} overflow-y-auto overflow-x-hidden overscroll-contain rounded-sm border border-field-border-default bg-field-surface text-field-content shadow-lg`,
|
|
1260
|
+
children: [
|
|
1261
|
+
isSearchable && /* @__PURE__ */ jsxs3("div", { className: "sticky top-0 flex items-center gap-2 border-b border-field-border-default bg-field-surface p-2", children: [
|
|
1262
|
+
/* @__PURE__ */ jsx3(MdSearch, { "aria-hidden": "true", className: "h-4 w-4 text-field-icon" }),
|
|
1263
|
+
/* @__PURE__ */ jsx3(
|
|
1264
|
+
"input",
|
|
1265
|
+
{
|
|
1266
|
+
ref: searchInputRef,
|
|
1267
|
+
type: "text",
|
|
1268
|
+
value: searchTerm,
|
|
1269
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
1270
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
1271
|
+
onKeyDown: (event) => {
|
|
1272
|
+
if (event.key === "Tab") {
|
|
1273
|
+
event.preventDefault();
|
|
1274
|
+
closeDropdown();
|
|
1275
|
+
handleBlur();
|
|
1276
|
+
moveFocusFromTrigger(event.shiftKey);
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
if (event.key === "Escape") {
|
|
1280
|
+
event.preventDefault();
|
|
1281
|
+
closeDropdown(true);
|
|
1282
|
+
}
|
|
1283
|
+
if (event.key === "ArrowDown") {
|
|
1284
|
+
event.preventDefault();
|
|
1285
|
+
focusOption("first");
|
|
1286
|
+
}
|
|
1287
|
+
if (event.key === "ArrowUp") {
|
|
1288
|
+
event.preventDefault();
|
|
1289
|
+
focusOption("last");
|
|
1290
|
+
}
|
|
1291
|
+
},
|
|
1292
|
+
"aria-label": `Pesquisar op\xE7\xF5es de ${label != null ? label : name}`,
|
|
1293
|
+
"aria-controls": listboxId,
|
|
1294
|
+
"aria-describedby": resultsId,
|
|
1295
|
+
placeholder: searchPlaceholder,
|
|
1296
|
+
className: "w-full bg-transparent text-sm text-field-content outline-none placeholder:text-field-placeholder"
|
|
1297
|
+
}
|
|
1298
|
+
)
|
|
1299
|
+
] }),
|
|
1300
|
+
isSearchable && /* @__PURE__ */ jsx3(
|
|
1301
|
+
"span",
|
|
1302
|
+
{
|
|
1303
|
+
id: resultsId,
|
|
1304
|
+
role: "status",
|
|
1305
|
+
"aria-live": "polite",
|
|
1306
|
+
"aria-atomic": "true",
|
|
1307
|
+
className: "sr-only",
|
|
1308
|
+
children: resultAnnouncement
|
|
1309
|
+
}
|
|
1310
|
+
),
|
|
1311
|
+
/* @__PURE__ */ jsx3(
|
|
1312
|
+
"div",
|
|
1313
|
+
{
|
|
1314
|
+
id: listboxId,
|
|
1315
|
+
role: "listbox",
|
|
1316
|
+
"aria-labelledby": label ? labelId : void 0,
|
|
1317
|
+
children: filteredOptions.length === 0 ? /* @__PURE__ */ jsx3("div", { className: "px-3 py-2 text-sm text-content-muted", children: noOptionsText }) : filteredOptions.map((opc) => /* @__PURE__ */ jsx3(
|
|
1318
|
+
"button",
|
|
1319
|
+
{
|
|
1320
|
+
type: "button",
|
|
1321
|
+
role: "option",
|
|
1322
|
+
"aria-selected": (selectedOption == null ? void 0 : selectedOption.value) === opc.value,
|
|
1323
|
+
tabIndex: -1,
|
|
1324
|
+
onMouseDown: (e) => {
|
|
1325
|
+
e.preventDefault();
|
|
1326
|
+
e.stopPropagation();
|
|
1327
|
+
},
|
|
1328
|
+
onClick: () => handleSelect(opc.value),
|
|
1329
|
+
onKeyDown: handleOptionKeyDown,
|
|
1330
|
+
className: "w-full px-3 py-2 text-left text-sm hover:bg-surface-muted focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-focus-ring",
|
|
1331
|
+
children: renderOption ? renderOption(opc) : opc.label
|
|
1332
|
+
},
|
|
1333
|
+
opc.value
|
|
1334
|
+
))
|
|
1335
|
+
}
|
|
1336
|
+
)
|
|
1337
|
+
]
|
|
1338
|
+
}
|
|
1339
|
+
) : null;
|
|
1340
|
+
return /* @__PURE__ */ jsxs3(
|
|
1341
|
+
FieldFrame_default,
|
|
1342
|
+
__spreadProps(__spreadValues({
|
|
1343
|
+
className,
|
|
1344
|
+
label,
|
|
1345
|
+
labelFor: selectId,
|
|
1346
|
+
labelId: label ? labelId : void 0,
|
|
1347
|
+
invalid: Boolean(hasError),
|
|
1348
|
+
message: meta.error,
|
|
1349
|
+
messageId: errorId,
|
|
1350
|
+
labelAdornment: helperText ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1351
|
+
/* @__PURE__ */ jsx3(
|
|
1352
|
+
"button",
|
|
1353
|
+
{
|
|
1354
|
+
ref: iconRef,
|
|
1355
|
+
onMouseEnter: () => setHovered(true),
|
|
1356
|
+
onMouseLeave: () => setHovered(false),
|
|
1357
|
+
onFocus: () => setHovered(true),
|
|
1358
|
+
onBlur: () => setHovered(false),
|
|
1359
|
+
type: "button",
|
|
1360
|
+
"aria-label": `Mais informa\xE7\xF5es sobre ${label != null ? label : name}`,
|
|
1361
|
+
className: "rounded-sm pb-[3px] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-1",
|
|
1362
|
+
children: /* @__PURE__ */ jsx3(
|
|
1363
|
+
MdInfoOutline2,
|
|
1364
|
+
{
|
|
1365
|
+
"aria-hidden": "true",
|
|
1366
|
+
className: "mr-0 text-content-muted"
|
|
1367
|
+
}
|
|
1368
|
+
)
|
|
1369
|
+
}
|
|
1370
|
+
),
|
|
1371
|
+
/* @__PURE__ */ jsx3(
|
|
1372
|
+
Tooltip_default,
|
|
1373
|
+
{
|
|
1374
|
+
targetRef: iconRef,
|
|
1375
|
+
content: helperText,
|
|
1376
|
+
visible: hovered,
|
|
1377
|
+
preferredPosition: "bottom"
|
|
1378
|
+
}
|
|
1379
|
+
)
|
|
1380
|
+
] }) : void 0
|
|
1381
|
+
}, rest), {
|
|
1382
|
+
children: [
|
|
1383
|
+
/* @__PURE__ */ jsxs3(
|
|
1384
|
+
"button",
|
|
1385
|
+
{
|
|
1386
|
+
type: "button",
|
|
1387
|
+
id: selectId,
|
|
1388
|
+
name,
|
|
1389
|
+
ref: inputRef,
|
|
1390
|
+
"data-has-value": Boolean(selectedOption),
|
|
1391
|
+
role: "combobox",
|
|
1392
|
+
"aria-controls": listboxId,
|
|
1393
|
+
"aria-expanded": open,
|
|
1394
|
+
"aria-haspopup": "listbox",
|
|
1395
|
+
"aria-labelledby": label ? labelId : void 0,
|
|
1396
|
+
"aria-label": label ? void 0 : placeholder != null ? placeholder : name,
|
|
1397
|
+
"aria-invalid": Boolean(hasError) || void 0,
|
|
1398
|
+
"aria-describedby": triggerDescribedBy,
|
|
1399
|
+
disabled,
|
|
1400
|
+
onBlur: () => !open && handleBlur(),
|
|
1401
|
+
onClick: () => setOpen((prev) => !prev),
|
|
1402
|
+
onKeyDown: (event) => {
|
|
1403
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1404
|
+
event.preventDefault();
|
|
1405
|
+
setOpen((prev) => !prev);
|
|
1406
|
+
}
|
|
1407
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
1408
|
+
event.preventDefault();
|
|
1409
|
+
setOpen(true);
|
|
1410
|
+
}
|
|
1411
|
+
if (event.key === "Escape") {
|
|
1412
|
+
closeDropdown();
|
|
1413
|
+
}
|
|
1414
|
+
},
|
|
1415
|
+
className: classNames3(`${FIELD_CONTROL_CLASS} px-2`, {
|
|
1416
|
+
[FIELD_DISABLED_CLASS]: disabled,
|
|
1417
|
+
[FIELD_ERROR_CLASS]: hasError,
|
|
1418
|
+
"cursor-pointer": !disabled
|
|
1419
|
+
}),
|
|
1420
|
+
children: [
|
|
1421
|
+
LeadIcon && /* @__PURE__ */ jsx3(
|
|
1422
|
+
LeadIcon,
|
|
1423
|
+
{
|
|
1424
|
+
"aria-hidden": "true",
|
|
1425
|
+
className: classNames3(`h-5 w-5`, {
|
|
1426
|
+
"text-field-assistive-error": hasError,
|
|
1427
|
+
"text-field-content": !hasError && (open || selectedOption),
|
|
1428
|
+
"text-field-content-disabled": disabled,
|
|
1429
|
+
"cursor-not-allowed": disabled,
|
|
1430
|
+
"cursor-pointer": !disabled
|
|
1431
|
+
})
|
|
1432
|
+
}
|
|
1433
|
+
),
|
|
1434
|
+
prefix && /* @__PURE__ */ jsx3("span", { children: prefix }),
|
|
1435
|
+
/* @__PURE__ */ jsx3(
|
|
1436
|
+
"span",
|
|
1437
|
+
{
|
|
1438
|
+
className: classNames3(
|
|
1439
|
+
"flex-1 min-w-0 flex items-center justify-between leading-5",
|
|
1440
|
+
"bg-transparent text-field-content text-left",
|
|
1441
|
+
{
|
|
1442
|
+
"text-field-content-disabled": disabled,
|
|
1443
|
+
"cursor-not-allowed": disabled,
|
|
1444
|
+
"cursor-pointer": !disabled
|
|
1445
|
+
}
|
|
1446
|
+
),
|
|
1447
|
+
children: selectedValueContent
|
|
1448
|
+
}
|
|
1449
|
+
),
|
|
1450
|
+
EndIcon ? /* @__PURE__ */ jsx3(
|
|
1451
|
+
EndIcon,
|
|
1452
|
+
{
|
|
1453
|
+
"aria-hidden": "true",
|
|
1454
|
+
className: classNames3(`h-5 w-5`, {
|
|
1455
|
+
"text-field-assistive-error": hasError,
|
|
1456
|
+
"text-field-content": !hasError && (open || selectedOption),
|
|
1457
|
+
"text-field-content-disabled": disabled,
|
|
1458
|
+
"cursor-not-allowed": disabled,
|
|
1459
|
+
"cursor-pointer": !disabled
|
|
1460
|
+
})
|
|
1461
|
+
}
|
|
1462
|
+
) : /* @__PURE__ */ jsx3(
|
|
1463
|
+
"span",
|
|
1464
|
+
{
|
|
1465
|
+
className: classNames3(
|
|
1466
|
+
"flex items-center justify-center text-field-icon",
|
|
1467
|
+
{
|
|
1468
|
+
"text-field-assistive-error": hasError,
|
|
1469
|
+
"text-field-content": !hasError && (open || selectedOption),
|
|
1470
|
+
"text-field-content-disabled": disabled,
|
|
1471
|
+
"cursor-not-allowed": disabled,
|
|
1472
|
+
"cursor-pointer": !disabled
|
|
1473
|
+
}
|
|
1474
|
+
),
|
|
1475
|
+
children: open ? /* @__PURE__ */ jsx3(
|
|
1476
|
+
MdOutlineKeyboardArrowUp,
|
|
1477
|
+
{
|
|
1478
|
+
"aria-hidden": "true",
|
|
1479
|
+
className: "h-5 w-5"
|
|
1480
|
+
}
|
|
1481
|
+
) : /* @__PURE__ */ jsx3(
|
|
1482
|
+
MdOutlineKeyboardArrowDown,
|
|
1483
|
+
{
|
|
1484
|
+
"aria-hidden": "true",
|
|
1485
|
+
className: "h-5 w-5"
|
|
1486
|
+
}
|
|
1487
|
+
)
|
|
1488
|
+
}
|
|
1489
|
+
)
|
|
1490
|
+
]
|
|
1491
|
+
}
|
|
1492
|
+
),
|
|
1493
|
+
/* @__PURE__ */ jsx3("span", { id: valueDescriptionId, className: "sr-only", children: selectedValueDescription }),
|
|
1494
|
+
/* @__PURE__ */ jsx3(
|
|
1495
|
+
"span",
|
|
1496
|
+
{
|
|
1497
|
+
role: "status",
|
|
1498
|
+
"aria-live": "polite",
|
|
1499
|
+
"aria-atomic": "true",
|
|
1500
|
+
className: "sr-only",
|
|
1501
|
+
children: selectionAnnouncement
|
|
1502
|
+
}
|
|
1503
|
+
),
|
|
1504
|
+
isMounted && dropdownContent ? createPortal(dropdownContent, document.body) : null
|
|
1505
|
+
]
|
|
1506
|
+
})
|
|
1507
|
+
);
|
|
1508
|
+
};
|
|
1509
|
+
var InputSelect_default = InputSelect;
|
|
1510
|
+
|
|
1511
|
+
// src/components/textArea/TextArea.tsx
|
|
1512
|
+
import { useRef as useRef3 } from "react";
|
|
1513
|
+
import classNames4 from "classnames";
|
|
1514
|
+
import { useField as useField3 } from "formik";
|
|
1515
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1516
|
+
var TextArea = (_a) => {
|
|
1517
|
+
var _b = _a, {
|
|
1518
|
+
name,
|
|
1519
|
+
label,
|
|
1520
|
+
helperText,
|
|
1521
|
+
className,
|
|
1522
|
+
placeholder,
|
|
1523
|
+
prefix,
|
|
1524
|
+
suffix,
|
|
1525
|
+
disabled,
|
|
1526
|
+
icon: Icon
|
|
1527
|
+
} = _b, rest = __objRest(_b, [
|
|
1528
|
+
"name",
|
|
1529
|
+
"label",
|
|
1530
|
+
"helperText",
|
|
1531
|
+
"className",
|
|
1532
|
+
"placeholder",
|
|
1533
|
+
"prefix",
|
|
1534
|
+
"suffix",
|
|
1535
|
+
"disabled",
|
|
1536
|
+
"icon"
|
|
1537
|
+
]);
|
|
1538
|
+
var _a2;
|
|
1539
|
+
const [field, meta] = useField3(name);
|
|
1540
|
+
const componentRef = useRef3(null);
|
|
1541
|
+
const hasError = meta.touched && meta.error;
|
|
1542
|
+
const errorId = `${name}-error`;
|
|
1543
|
+
const descriptionId = `${name}-description`;
|
|
1544
|
+
const ariaDescribedBy = mergeAriaDescribedBy(
|
|
1545
|
+
rest["aria-describedby"],
|
|
1546
|
+
helperText && !hasError ? descriptionId : void 0,
|
|
1547
|
+
hasError ? errorId : void 0
|
|
1548
|
+
);
|
|
1549
|
+
return /* @__PURE__ */ jsx4(
|
|
1550
|
+
FieldFrame_default,
|
|
1551
|
+
{
|
|
1552
|
+
label,
|
|
1553
|
+
labelFor: name,
|
|
1554
|
+
description: helperText,
|
|
1555
|
+
descriptionId,
|
|
1556
|
+
message: meta.error,
|
|
1557
|
+
messageId: errorId,
|
|
1558
|
+
invalid: Boolean(hasError),
|
|
1559
|
+
children: /* @__PURE__ */ jsxs4(
|
|
1560
|
+
"div",
|
|
1561
|
+
{
|
|
1562
|
+
"data-has-value": String((_a2 = field.value) != null ? _a2 : "").length > 0,
|
|
1563
|
+
className: classNames4(
|
|
1564
|
+
`${FIELD_CONTROL_CLASS} py-1`,
|
|
1565
|
+
{
|
|
1566
|
+
[FIELD_DISABLED_CLASS]: disabled,
|
|
1567
|
+
[FIELD_ERROR_CLASS]: hasError
|
|
1568
|
+
}
|
|
1569
|
+
),
|
|
1570
|
+
children: [
|
|
1571
|
+
Icon && /* @__PURE__ */ jsx4(Icon, { "aria-hidden": "true", className: "h-5 w-5" }),
|
|
1572
|
+
prefix && /* @__PURE__ */ jsx4("span", { children: prefix }),
|
|
1573
|
+
/* @__PURE__ */ jsx4(
|
|
1574
|
+
"textarea",
|
|
1575
|
+
__spreadProps(__spreadValues(__spreadValues({}, field), rest), {
|
|
1576
|
+
id: name,
|
|
1577
|
+
"aria-invalid": Boolean(hasError) || void 0,
|
|
1578
|
+
"aria-describedby": ariaDescribedBy,
|
|
1579
|
+
ref: componentRef,
|
|
1580
|
+
placeholder,
|
|
1581
|
+
disabled,
|
|
1582
|
+
className: classNames4(FIELD_INPUT_CLASS, className)
|
|
1583
|
+
})
|
|
1584
|
+
),
|
|
1585
|
+
suffix && /* @__PURE__ */ jsx4("span", { children: suffix })
|
|
1586
|
+
]
|
|
1587
|
+
}
|
|
1588
|
+
)
|
|
1589
|
+
}
|
|
1590
|
+
);
|
|
1591
|
+
};
|
|
1592
|
+
var TextArea_default = TextArea;
|
|
1593
|
+
|
|
1594
|
+
// src/components/inputPhone/InputPhone.tsx
|
|
1595
|
+
import classNames5 from "classnames";
|
|
1596
|
+
import { useField as useField4 } from "formik";
|
|
1597
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useMemo, useRef as useRef4, useState as useState3 } from "react";
|
|
1598
|
+
import {
|
|
1599
|
+
MdOutlineKeyboardArrowDown as MdOutlineKeyboardArrowDown2,
|
|
1600
|
+
MdOutlineKeyboardArrowUp as MdOutlineKeyboardArrowUp2,
|
|
1601
|
+
MdSearch as MdSearch2
|
|
1602
|
+
} from "react-icons/md";
|
|
1603
|
+
import { PatternFormat as PatternFormat2 } from "react-number-format";
|
|
1604
|
+
import { createPortal as createPortal2 } from "react-dom";
|
|
1605
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1606
|
+
var DEFAULT_BRAZIL_DDI = 55;
|
|
1607
|
+
var DEFAULT_BRAZIL_CCA2 = "BR";
|
|
1608
|
+
var phoneMasksByDdi = {
|
|
1609
|
+
"1": "(###) ###-####",
|
|
1610
|
+
"31": "## ########",
|
|
1611
|
+
"32": "### ## ## ##",
|
|
1612
|
+
"44": "#### ######",
|
|
1613
|
+
"49": null,
|
|
1614
|
+
"51": "### ### ###",
|
|
1615
|
+
"55": "(##) #####-####",
|
|
1616
|
+
"58": "### #######",
|
|
1617
|
+
"351": "### ### ###"
|
|
1618
|
+
};
|
|
1619
|
+
function normalizeDigits(value) {
|
|
1620
|
+
return String(value != null ? value : "").replace(/\D/g, "");
|
|
1621
|
+
}
|
|
1622
|
+
function normalizeSearchText(value) {
|
|
1623
|
+
return value.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
1624
|
+
}
|
|
1625
|
+
function toPhoneValue(value) {
|
|
1626
|
+
return {
|
|
1627
|
+
ddi: Number(normalizeDigits(value == null ? void 0 : value.ddi) || DEFAULT_BRAZIL_DDI),
|
|
1628
|
+
ddd: normalizeDigits(value == null ? void 0 : value.ddd),
|
|
1629
|
+
numero: normalizeDigits(value == null ? void 0 : value.numero)
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
function getMaskForDdi(ddi) {
|
|
1633
|
+
var _a;
|
|
1634
|
+
return (_a = phoneMasksByDdi[normalizeDigits(ddi)]) != null ? _a : null;
|
|
1635
|
+
}
|
|
1636
|
+
function getAreaCodeLength(mask) {
|
|
1637
|
+
if (!mask) return 0;
|
|
1638
|
+
const match = mask.match(/\((#+)\)/);
|
|
1639
|
+
return match ? match[1].length : 0;
|
|
1640
|
+
}
|
|
1641
|
+
function splitNationalNumber(localNumber, mask) {
|
|
1642
|
+
const digits = normalizeDigits(localNumber);
|
|
1643
|
+
const areaCodeLength = getAreaCodeLength(mask);
|
|
1644
|
+
if (!areaCodeLength) {
|
|
1645
|
+
return {
|
|
1646
|
+
ddd: "",
|
|
1647
|
+
numero: digits
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
return {
|
|
1651
|
+
ddd: digits.slice(0, areaCodeLength),
|
|
1652
|
+
numero: digits.slice(areaCodeLength)
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
function getDialDigits(country) {
|
|
1656
|
+
var _a;
|
|
1657
|
+
return normalizeDigits((_a = country == null ? void 0 : country.idd) == null ? void 0 : _a.display);
|
|
1658
|
+
}
|
|
1659
|
+
function getCountryByDdi(countries, ddi) {
|
|
1660
|
+
const normalizedDdi = Number(normalizeDigits(ddi));
|
|
1661
|
+
return countries.find(
|
|
1662
|
+
(country) => Number(getDialDigits(country)) === normalizedDdi
|
|
1663
|
+
) || countries.find((country) => country.cca2 === DEFAULT_BRAZIL_CCA2) || countries[0] || null;
|
|
1664
|
+
}
|
|
1665
|
+
function getCountriesByDialLength(countries) {
|
|
1666
|
+
return [...countries].sort((a, b) => {
|
|
1667
|
+
return getDialDigits(b).length - getDialDigits(a).length;
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
function getExplicitCountryFromRawValue(rawValue, countries) {
|
|
1671
|
+
if (typeof rawValue !== "string") return null;
|
|
1672
|
+
const trimmedValue = rawValue.trim();
|
|
1673
|
+
if (!trimmedValue || !/[^\d]/.test(trimmedValue)) return null;
|
|
1674
|
+
return getCountriesByDialLength(countries).find((country) => {
|
|
1675
|
+
const dialDigits = getDialDigits(country);
|
|
1676
|
+
if (!dialDigits) return false;
|
|
1677
|
+
const dialPattern = new RegExp(`^\\+?\\s*${dialDigits}(?=\\D|$)`);
|
|
1678
|
+
return dialPattern.test(trimmedValue);
|
|
1679
|
+
}) || null;
|
|
1680
|
+
}
|
|
1681
|
+
function parseStoredPhoneValue(rawValue, countries) {
|
|
1682
|
+
if (rawValue && typeof rawValue === "object" && !Array.isArray(rawValue)) {
|
|
1683
|
+
return {
|
|
1684
|
+
ddi: Number(normalizeDigits(rawValue.ddi) || DEFAULT_BRAZIL_DDI),
|
|
1685
|
+
ddd: normalizeDigits(rawValue.ddd),
|
|
1686
|
+
numero: normalizeDigits(rawValue.numero)
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
const digits = normalizeDigits(
|
|
1690
|
+
rawValue
|
|
1691
|
+
);
|
|
1692
|
+
if (!digits) {
|
|
1693
|
+
return {
|
|
1694
|
+
ddi: DEFAULT_BRAZIL_DDI,
|
|
1695
|
+
ddd: "",
|
|
1696
|
+
numero: ""
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
const explicitCountry = getExplicitCountryFromRawValue(rawValue, countries);
|
|
1700
|
+
if (explicitCountry) {
|
|
1701
|
+
const dialDigits2 = getDialDigits(explicitCountry);
|
|
1702
|
+
const localDigits2 = digits.slice(dialDigits2.length);
|
|
1703
|
+
const local2 = splitNationalNumber(
|
|
1704
|
+
localDigits2,
|
|
1705
|
+
getMaskForDdi(Number(dialDigits2))
|
|
1706
|
+
);
|
|
1707
|
+
return __spreadValues({
|
|
1708
|
+
ddi: Number(dialDigits2)
|
|
1709
|
+
}, local2);
|
|
1710
|
+
}
|
|
1711
|
+
if (digits.length <= 11) {
|
|
1712
|
+
const local2 = splitNationalNumber(
|
|
1713
|
+
digits,
|
|
1714
|
+
getMaskForDdi(DEFAULT_BRAZIL_DDI)
|
|
1715
|
+
);
|
|
1716
|
+
return __spreadValues({
|
|
1717
|
+
ddi: DEFAULT_BRAZIL_DDI
|
|
1718
|
+
}, local2);
|
|
1719
|
+
}
|
|
1720
|
+
const optionsByDialLength = getCountriesByDialLength(countries);
|
|
1721
|
+
const matchedCountry = optionsByDialLength.find((country) => {
|
|
1722
|
+
const dialDigits2 = getDialDigits(country);
|
|
1723
|
+
return dialDigits2 && digits.startsWith(dialDigits2) && digits.length > dialDigits2.length + 4;
|
|
1724
|
+
});
|
|
1725
|
+
if (!matchedCountry) {
|
|
1726
|
+
const local2 = splitNationalNumber(
|
|
1727
|
+
digits,
|
|
1728
|
+
getMaskForDdi(DEFAULT_BRAZIL_DDI)
|
|
1729
|
+
);
|
|
1730
|
+
return __spreadValues({
|
|
1731
|
+
ddi: DEFAULT_BRAZIL_DDI
|
|
1732
|
+
}, local2);
|
|
1733
|
+
}
|
|
1734
|
+
const dialDigits = getDialDigits(matchedCountry);
|
|
1735
|
+
const localDigits = digits.slice(dialDigits.length);
|
|
1736
|
+
const local = splitNationalNumber(
|
|
1737
|
+
localDigits,
|
|
1738
|
+
getMaskForDdi(Number(dialDigits))
|
|
1739
|
+
);
|
|
1740
|
+
return __spreadValues({
|
|
1741
|
+
ddi: Number(dialDigits)
|
|
1742
|
+
}, local);
|
|
1743
|
+
}
|
|
1744
|
+
function buildPhonePayload(phoneValue) {
|
|
1745
|
+
const normalized = toPhoneValue(phoneValue);
|
|
1746
|
+
const ddiDigits = normalizeDigits(normalized.ddi);
|
|
1747
|
+
const dddDigits = normalizeDigits(normalized.ddd);
|
|
1748
|
+
const numberDigits = normalizeDigits(normalized.numero);
|
|
1749
|
+
const phoneDigits = `${dddDigits}${numberDigits}`;
|
|
1750
|
+
if (!phoneDigits) {
|
|
1751
|
+
return "";
|
|
1752
|
+
}
|
|
1753
|
+
return `${ddiDigits}-${dddDigits}-${numberDigits}`;
|
|
1754
|
+
}
|
|
1755
|
+
function parsePhonePayload(rawValue, countries = PHONE_COUNTRY_OPTIONS) {
|
|
1756
|
+
return parseStoredPhoneValue(rawValue, countries);
|
|
1757
|
+
}
|
|
1758
|
+
function renderFlag(option) {
|
|
1759
|
+
var _a;
|
|
1760
|
+
const svgSrc = String(
|
|
1761
|
+
getCountryFlagUrl(option == null ? void 0 : option.cca2) || ((_a = option == null ? void 0 : option.flags) == null ? void 0 : _a.svg) || ""
|
|
1762
|
+
).trim();
|
|
1763
|
+
if (!svgSrc) {
|
|
1764
|
+
return /* @__PURE__ */ jsx5("span", { className: "h-5 w-7 shrink-0 rounded-sm bg-surface-muted" });
|
|
1765
|
+
}
|
|
1766
|
+
return /* @__PURE__ */ jsx5(
|
|
1767
|
+
"img",
|
|
1768
|
+
{
|
|
1769
|
+
src: svgSrc,
|
|
1770
|
+
alt: "",
|
|
1771
|
+
"aria-hidden": "true",
|
|
1772
|
+
className: "h-5 w-7 shrink-0 object-contain",
|
|
1773
|
+
loading: "lazy",
|
|
1774
|
+
referrerPolicy: "no-referrer"
|
|
1775
|
+
}
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1778
|
+
function InputPhone({
|
|
1779
|
+
name,
|
|
1780
|
+
label,
|
|
1781
|
+
placeholder,
|
|
1782
|
+
countries,
|
|
1783
|
+
countryList,
|
|
1784
|
+
disabled,
|
|
1785
|
+
className
|
|
1786
|
+
}) {
|
|
1787
|
+
const availableCountries = useMemo(
|
|
1788
|
+
() => filterCountryOptions(
|
|
1789
|
+
countries || PHONE_COUNTRY_OPTIONS,
|
|
1790
|
+
countryList
|
|
1791
|
+
),
|
|
1792
|
+
[countries, countryList]
|
|
1793
|
+
);
|
|
1794
|
+
const [field, meta, helpers] = useField4(name);
|
|
1795
|
+
const wrapperRef = useRef4(null);
|
|
1796
|
+
const countryButtonRef = useRef4(null);
|
|
1797
|
+
const dropdownRef = useRef4(null);
|
|
1798
|
+
const searchInputRef = useRef4(null);
|
|
1799
|
+
const initializedRef = useRef4(false);
|
|
1800
|
+
const [open, setOpen] = useState3(false);
|
|
1801
|
+
const [selectedCountryCode, setSelectedCountryCode] = useState3();
|
|
1802
|
+
const [searchTerm, setSearchTerm] = useState3("");
|
|
1803
|
+
const [dropdownPosition, setDropdownPosition] = useState3(null);
|
|
1804
|
+
const value = useMemo(() => toPhoneValue(field.value), [field.value]);
|
|
1805
|
+
const selectedCountry = useMemo(
|
|
1806
|
+
() => availableCountries.find((country) => country.cca2 === selectedCountryCode && Number(getDialDigits(country)) === value.ddi) || getCountryByDdi(availableCountries, value.ddi),
|
|
1807
|
+
[availableCountries, value.ddi, selectedCountryCode]
|
|
1808
|
+
);
|
|
1809
|
+
const phoneMask = getMaskForDdi(value.ddi);
|
|
1810
|
+
const phoneDigits = `${normalizeDigits(value.ddd)}${normalizeDigits(value.numero)}`;
|
|
1811
|
+
const normalizedSearch = normalizeSearchText(searchTerm.trim());
|
|
1812
|
+
const filteredCountries = useMemo(() => {
|
|
1813
|
+
return availableCountries.filter((country) => {
|
|
1814
|
+
const searchableText = [
|
|
1815
|
+
country.label,
|
|
1816
|
+
country.cca2,
|
|
1817
|
+
country.idd.display,
|
|
1818
|
+
getDialDigits(country)
|
|
1819
|
+
].join(" ").trim();
|
|
1820
|
+
return normalizeSearchText(searchableText).includes(normalizedSearch);
|
|
1821
|
+
});
|
|
1822
|
+
}, [availableCountries, normalizedSearch]);
|
|
1823
|
+
const getErrorMessage = useCallback3(() => {
|
|
1824
|
+
if (!meta.touched || !meta.error) return "";
|
|
1825
|
+
if (typeof meta.error === "string") return meta.error;
|
|
1826
|
+
if (typeof meta.error === "object") {
|
|
1827
|
+
const phoneError = meta.error;
|
|
1828
|
+
return String(phoneError.numero || phoneError.ddd || "");
|
|
1829
|
+
}
|
|
1830
|
+
return "";
|
|
1831
|
+
}, [meta.error, meta.touched]);
|
|
1832
|
+
const errorMessage = getErrorMessage();
|
|
1833
|
+
const hasError = Boolean(errorMessage);
|
|
1834
|
+
const errorId = `${name}-error`;
|
|
1835
|
+
const dropdownId = `${name}-countries`;
|
|
1836
|
+
const isDropdownPositioned = dropdownPosition !== null;
|
|
1837
|
+
const updateDropdownPosition = useCallback3(() => {
|
|
1838
|
+
const trigger = countryButtonRef.current;
|
|
1839
|
+
const dropdown = dropdownRef.current;
|
|
1840
|
+
if (!open || !trigger) return;
|
|
1841
|
+
const rect = trigger.getBoundingClientRect();
|
|
1842
|
+
const panelRect = calculateFloatingPanelRect({
|
|
1843
|
+
trigger: {
|
|
1844
|
+
top: rect.top,
|
|
1845
|
+
bottom: rect.bottom,
|
|
1846
|
+
left: rect.left,
|
|
1847
|
+
width: 220
|
|
1848
|
+
},
|
|
1849
|
+
panel: {
|
|
1850
|
+
width: 220,
|
|
1851
|
+
height: Math.min((dropdown == null ? void 0 : dropdown.scrollHeight) || 320, 320)
|
|
1852
|
+
},
|
|
1853
|
+
viewport: {
|
|
1854
|
+
width: window.innerWidth,
|
|
1855
|
+
height: window.innerHeight
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
setDropdownPosition(panelRect);
|
|
1859
|
+
}, [open]);
|
|
1860
|
+
useEffect2(() => {
|
|
1861
|
+
if (!open) {
|
|
1862
|
+
setSearchTerm("");
|
|
1863
|
+
setDropdownPosition(null);
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
updateDropdownPosition();
|
|
1867
|
+
}, [open, updateDropdownPosition]);
|
|
1868
|
+
useEffect2(() => {
|
|
1869
|
+
var _a;
|
|
1870
|
+
if (open && isDropdownPositioned) {
|
|
1871
|
+
(_a = searchInputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
1872
|
+
}
|
|
1873
|
+
}, [isDropdownPositioned, open]);
|
|
1874
|
+
useEffect2(() => {
|
|
1875
|
+
if (disabled) setOpen(false);
|
|
1876
|
+
}, [disabled]);
|
|
1877
|
+
useEffect2(() => {
|
|
1878
|
+
if (!open) return;
|
|
1879
|
+
const scheduleDropdownPosition = () => updateDropdownPosition();
|
|
1880
|
+
window.addEventListener("resize", scheduleDropdownPosition);
|
|
1881
|
+
window.addEventListener("scroll", scheduleDropdownPosition, true);
|
|
1882
|
+
return () => {
|
|
1883
|
+
window.removeEventListener("resize", scheduleDropdownPosition);
|
|
1884
|
+
window.removeEventListener("scroll", scheduleDropdownPosition, true);
|
|
1885
|
+
};
|
|
1886
|
+
}, [open, updateDropdownPosition]);
|
|
1887
|
+
useEffect2(() => {
|
|
1888
|
+
if (initializedRef.current || availableCountries.length === 0) return;
|
|
1889
|
+
const parsed = parseStoredPhoneValue(
|
|
1890
|
+
field.value,
|
|
1891
|
+
availableCountries
|
|
1892
|
+
);
|
|
1893
|
+
helpers.setValue(parsed);
|
|
1894
|
+
initializedRef.current = true;
|
|
1895
|
+
}, [availableCountries, field.value, helpers]);
|
|
1896
|
+
useEffect2(() => {
|
|
1897
|
+
if (!open) return;
|
|
1898
|
+
const handleClickOutside = (event) => {
|
|
1899
|
+
var _a, _b;
|
|
1900
|
+
if (!((_a = wrapperRef.current) == null ? void 0 : _a.contains(event.target)) && !((_b = dropdownRef.current) == null ? void 0 : _b.contains(event.target))) {
|
|
1901
|
+
setOpen(false);
|
|
1902
|
+
helpers.setTouched(true);
|
|
1903
|
+
}
|
|
1904
|
+
};
|
|
1905
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
1906
|
+
return () => {
|
|
1907
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
1908
|
+
};
|
|
1909
|
+
}, [helpers, open]);
|
|
1910
|
+
const setPhoneValue = (nextValue) => {
|
|
1911
|
+
var _a, _b, _c;
|
|
1912
|
+
helpers.setValue(__spreadProps(__spreadValues(__spreadValues({}, value), nextValue), {
|
|
1913
|
+
ddi: Number(
|
|
1914
|
+
normalizeDigits((_a = nextValue.ddi) != null ? _a : value.ddi) || DEFAULT_BRAZIL_DDI
|
|
1915
|
+
),
|
|
1916
|
+
ddd: normalizeDigits((_b = nextValue.ddd) != null ? _b : value.ddd),
|
|
1917
|
+
numero: normalizeDigits((_c = nextValue.numero) != null ? _c : value.numero)
|
|
1918
|
+
}));
|
|
1919
|
+
};
|
|
1920
|
+
const dropdownLayerClass = getFloatingLayerClass(
|
|
1921
|
+
countryButtonRef.current,
|
|
1922
|
+
"popover"
|
|
1923
|
+
);
|
|
1924
|
+
const dropdownZClass = dropdownLayerClass === "z-popover" ? "z-menu" : dropdownLayerClass;
|
|
1925
|
+
return /* @__PURE__ */ jsx5(
|
|
1926
|
+
FieldFrame_default,
|
|
1927
|
+
{
|
|
1928
|
+
className,
|
|
1929
|
+
label,
|
|
1930
|
+
labelFor: name,
|
|
1931
|
+
invalid: Boolean(hasError),
|
|
1932
|
+
message: errorMessage,
|
|
1933
|
+
messageId: errorId,
|
|
1934
|
+
children: /* @__PURE__ */ jsxs5(
|
|
1935
|
+
"div",
|
|
1936
|
+
{
|
|
1937
|
+
ref: wrapperRef,
|
|
1938
|
+
className: "field-control-slot relative mt-4xs mb-[4px]",
|
|
1939
|
+
children: [
|
|
1940
|
+
/* @__PURE__ */ jsxs5(
|
|
1941
|
+
"div",
|
|
1942
|
+
{
|
|
1943
|
+
"data-has-value": phoneDigits.length > 0,
|
|
1944
|
+
className: classNames5(
|
|
1945
|
+
"field-keyboard-focus-ring flex min-h-control-md items-center overflow-hidden rounded-sm border border-field-border-default bg-field-surface text-field-icon transition-colors focus-within:border-field-border-active focus-within:text-field-content data-[has-value=true]:text-field-content",
|
|
1946
|
+
{
|
|
1947
|
+
[FIELD_ERROR_CLASS]: hasError,
|
|
1948
|
+
[FIELD_DISABLED_CLASS]: disabled
|
|
1949
|
+
}
|
|
1950
|
+
),
|
|
1951
|
+
children: [
|
|
1952
|
+
/* @__PURE__ */ jsxs5(
|
|
1953
|
+
"button",
|
|
1954
|
+
{
|
|
1955
|
+
ref: countryButtonRef,
|
|
1956
|
+
type: "button",
|
|
1957
|
+
"aria-label": `Selecionar pa\xEDs de ${label || name}: ${(selectedCountry == null ? void 0 : selectedCountry.label) || ""} ${(selectedCountry == null ? void 0 : selectedCountry.idd.display) || `+${value.ddi}`}`,
|
|
1958
|
+
"aria-haspopup": "dialog",
|
|
1959
|
+
"aria-expanded": open && !disabled,
|
|
1960
|
+
"aria-controls": open && !disabled ? dropdownId : void 0,
|
|
1961
|
+
disabled,
|
|
1962
|
+
onClick: () => setOpen((prev) => !prev),
|
|
1963
|
+
onKeyDown: (event) => {
|
|
1964
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
1965
|
+
event.preventDefault();
|
|
1966
|
+
setOpen(true);
|
|
1967
|
+
}
|
|
1968
|
+
},
|
|
1969
|
+
onBlur: () => helpers.setTouched(true),
|
|
1970
|
+
className: classNames5(
|
|
1971
|
+
"flex h-full items-center gap-1.5 pl-2 pr-1 text-left",
|
|
1972
|
+
"border-r border-field-border-default bg-transparent text-field-content focus:outline-none",
|
|
1973
|
+
{
|
|
1974
|
+
"cursor-pointer": !disabled,
|
|
1975
|
+
"cursor-not-allowed text-content-disabled": disabled
|
|
1976
|
+
}
|
|
1977
|
+
),
|
|
1978
|
+
children: [
|
|
1979
|
+
renderFlag(selectedCountry),
|
|
1980
|
+
/* @__PURE__ */ jsx5("span", { className: "text-sm", children: (selectedCountry == null ? void 0 : selectedCountry.idd.display) || `+${value.ddi}` }),
|
|
1981
|
+
open ? /* @__PURE__ */ jsx5(
|
|
1982
|
+
MdOutlineKeyboardArrowUp2,
|
|
1983
|
+
{
|
|
1984
|
+
className: classNames5("h-4 w-4 shrink-0", {
|
|
1985
|
+
"text-field-assistive-error": hasError,
|
|
1986
|
+
"text-field-content": !hasError
|
|
1987
|
+
})
|
|
1988
|
+
}
|
|
1989
|
+
) : /* @__PURE__ */ jsx5(
|
|
1990
|
+
MdOutlineKeyboardArrowDown2,
|
|
1991
|
+
{
|
|
1992
|
+
className: classNames5("h-4 w-4 shrink-0", {
|
|
1993
|
+
"text-field-assistive-error": hasError,
|
|
1994
|
+
"text-field-content": !hasError && phoneDigits.length > 0,
|
|
1995
|
+
"text-field-icon": !hasError && phoneDigits.length === 0
|
|
1996
|
+
})
|
|
1997
|
+
}
|
|
1998
|
+
)
|
|
1999
|
+
]
|
|
2000
|
+
}
|
|
2001
|
+
),
|
|
2002
|
+
/* @__PURE__ */ jsx5("div", { className: "min-w-0 flex-1 pl-1 pr-3", children: phoneMask ? /* @__PURE__ */ jsx5(
|
|
2003
|
+
PatternFormat2,
|
|
2004
|
+
{
|
|
2005
|
+
id: name,
|
|
2006
|
+
name,
|
|
2007
|
+
type: "tel",
|
|
2008
|
+
inputMode: "tel",
|
|
2009
|
+
"aria-label": label ? void 0 : name,
|
|
2010
|
+
"aria-invalid": hasError || void 0,
|
|
2011
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
2012
|
+
value: phoneDigits,
|
|
2013
|
+
format: phoneMask,
|
|
2014
|
+
allowEmptyFormatting: false,
|
|
2015
|
+
mask: "",
|
|
2016
|
+
placeholder: placeholder || phoneMask.replace(/#/g, "9"),
|
|
2017
|
+
disabled,
|
|
2018
|
+
className: FIELD_INPUT_CLASS,
|
|
2019
|
+
onBlur: () => helpers.setTouched(true),
|
|
2020
|
+
onValueChange: (values) => {
|
|
2021
|
+
const areaCodeLength = getAreaCodeLength(phoneMask);
|
|
2022
|
+
const digits = normalizeDigits(values.value);
|
|
2023
|
+
setPhoneValue({
|
|
2024
|
+
ddd: areaCodeLength ? digits.slice(0, areaCodeLength) : "",
|
|
2025
|
+
numero: areaCodeLength ? digits.slice(areaCodeLength) : digits
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
) : /* @__PURE__ */ jsx5(
|
|
2030
|
+
"input",
|
|
2031
|
+
{
|
|
2032
|
+
id: name,
|
|
2033
|
+
name,
|
|
2034
|
+
"aria-label": label ? void 0 : name,
|
|
2035
|
+
"aria-invalid": hasError || void 0,
|
|
2036
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
2037
|
+
type: "tel",
|
|
2038
|
+
inputMode: "numeric",
|
|
2039
|
+
value: normalizeDigits(value.numero),
|
|
2040
|
+
placeholder: placeholder || "Digite o telefone",
|
|
2041
|
+
disabled,
|
|
2042
|
+
className: FIELD_INPUT_CLASS,
|
|
2043
|
+
onBlur: () => helpers.setTouched(true),
|
|
2044
|
+
onChange: (event) => setPhoneValue({ ddd: "", numero: event.target.value })
|
|
2045
|
+
}
|
|
2046
|
+
) })
|
|
2047
|
+
]
|
|
2048
|
+
}
|
|
2049
|
+
),
|
|
2050
|
+
open && !disabled && dropdownPosition && typeof document !== "undefined" && createPortal2(
|
|
2051
|
+
/* @__PURE__ */ jsxs5(
|
|
2052
|
+
"div",
|
|
2053
|
+
{
|
|
2054
|
+
ref: dropdownRef,
|
|
2055
|
+
id: dropdownId,
|
|
2056
|
+
role: "dialog",
|
|
2057
|
+
"aria-label": `Selecionar pa\xEDs de ${label || name}`,
|
|
2058
|
+
onKeyDown: (event) => {
|
|
2059
|
+
var _a, _b, _c, _d;
|
|
2060
|
+
if (event.key === "Escape" || event.key === "Tab") {
|
|
2061
|
+
event.preventDefault();
|
|
2062
|
+
setOpen(false);
|
|
2063
|
+
helpers.setTouched(true);
|
|
2064
|
+
if (event.key === "Escape" || event.shiftKey) (_a = countryButtonRef.current) == null ? void 0 : _a.focus();
|
|
2065
|
+
else (_b = document.getElementById(name)) == null ? void 0 : _b.focus();
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
|
|
2069
|
+
if (event.target === searchInputRef.current && ["Home", "End"].includes(event.key)) return;
|
|
2070
|
+
const options = Array.from(((_c = dropdownRef.current) == null ? void 0 : _c.querySelectorAll("button")) || []);
|
|
2071
|
+
if (!options.length) return;
|
|
2072
|
+
event.preventDefault();
|
|
2073
|
+
const index = options.indexOf(document.activeElement);
|
|
2074
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? options.length - 1 : event.key === "ArrowDown" ? (index + 1) % options.length : (index <= 0 ? options.length : index) - 1;
|
|
2075
|
+
(_d = options[next]) == null ? void 0 : _d.focus();
|
|
2076
|
+
},
|
|
2077
|
+
style: {
|
|
2078
|
+
top: dropdownPosition.top,
|
|
2079
|
+
left: dropdownPosition.left,
|
|
2080
|
+
width: dropdownPosition.width,
|
|
2081
|
+
maxHeight: dropdownPosition.maxHeight
|
|
2082
|
+
},
|
|
2083
|
+
className: classNames5(
|
|
2084
|
+
"fixed mt-1 overflow-hidden rounded-sm border border-field-border-default bg-field-surface shadow-lg",
|
|
2085
|
+
dropdownZClass
|
|
2086
|
+
),
|
|
2087
|
+
children: [
|
|
2088
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-2 border-b border-field-border-default bg-field-surface p-2", children: [
|
|
2089
|
+
/* @__PURE__ */ jsx5(MdSearch2, { className: "h-4 w-4 text-field-icon" }),
|
|
2090
|
+
/* @__PURE__ */ jsx5(
|
|
2091
|
+
"input",
|
|
2092
|
+
{
|
|
2093
|
+
ref: searchInputRef,
|
|
2094
|
+
type: "text",
|
|
2095
|
+
"aria-label": "Pesquisar pa\xEDs ou DDI",
|
|
2096
|
+
value: searchTerm,
|
|
2097
|
+
onChange: (event) => setSearchTerm(event.target.value),
|
|
2098
|
+
placeholder: "Busque um pa\xEDs ou DDI",
|
|
2099
|
+
className: "w-full bg-transparent text-sm text-field-content outline-none placeholder:text-field-placeholder"
|
|
2100
|
+
}
|
|
2101
|
+
)
|
|
2102
|
+
] }),
|
|
2103
|
+
/* @__PURE__ */ jsx5("div", { className: "max-h-60 overflow-y-auto", children: filteredCountries.length === 0 ? /* @__PURE__ */ jsx5("div", { role: "status", className: "px-3 py-2 text-sm text-content-muted", children: "Nenhum DDI encontrado" }) : filteredCountries.map((country) => /* @__PURE__ */ jsxs5(
|
|
2104
|
+
"button",
|
|
2105
|
+
{
|
|
2106
|
+
type: "button",
|
|
2107
|
+
"aria-pressed": (selectedCountry == null ? void 0 : selectedCountry.cca2) === country.cca2,
|
|
2108
|
+
onClick: () => {
|
|
2109
|
+
var _a;
|
|
2110
|
+
setSelectedCountryCode(country.cca2);
|
|
2111
|
+
setPhoneValue({ ddi: Number(getDialDigits(country)) });
|
|
2112
|
+
helpers.setTouched(true);
|
|
2113
|
+
setOpen(false);
|
|
2114
|
+
(_a = countryButtonRef.current) == null ? void 0 : _a.focus();
|
|
2115
|
+
},
|
|
2116
|
+
className: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-surface-muted focus-visible:bg-surface-muted focus-visible:outline focus-visible:outline-2 focus-visible:outline-focus-ring",
|
|
2117
|
+
children: [
|
|
2118
|
+
renderFlag(country),
|
|
2119
|
+
/* @__PURE__ */ jsx5("span", { className: "min-w-0 flex-1 truncate text-field-content", children: country.label }),
|
|
2120
|
+
/* @__PURE__ */ jsx5("span", { className: "shrink-0 text-content-muted", children: country.idd.display })
|
|
2121
|
+
]
|
|
2122
|
+
},
|
|
2123
|
+
`${country.cca2}-${country.idd.display}`
|
|
2124
|
+
)) })
|
|
2125
|
+
]
|
|
2126
|
+
}
|
|
2127
|
+
),
|
|
2128
|
+
document.body
|
|
2129
|
+
)
|
|
2130
|
+
]
|
|
2131
|
+
}
|
|
2132
|
+
)
|
|
2133
|
+
}
|
|
2134
|
+
);
|
|
2135
|
+
}
|
|
2136
|
+
var PhoneInput = InputPhone;
|
|
2137
|
+
var InputPhone_default = InputPhone;
|
|
2138
|
+
|
|
2139
|
+
// src/components/datePicker/UnifiedDatePicker.tsx
|
|
2140
|
+
import classNames6 from "classnames";
|
|
2141
|
+
import {
|
|
2142
|
+
addMonths,
|
|
2143
|
+
addYears,
|
|
2144
|
+
eachDayOfInterval,
|
|
2145
|
+
endOfMonth,
|
|
2146
|
+
endOfWeek,
|
|
2147
|
+
format,
|
|
2148
|
+
isAfter,
|
|
2149
|
+
isBefore,
|
|
2150
|
+
isSameDay,
|
|
2151
|
+
isSameMonth,
|
|
2152
|
+
isToday,
|
|
2153
|
+
isValid,
|
|
2154
|
+
parse,
|
|
2155
|
+
startOfDay,
|
|
2156
|
+
startOfMonth,
|
|
2157
|
+
startOfWeek,
|
|
2158
|
+
subMonths
|
|
2159
|
+
} from "date-fns";
|
|
2160
|
+
import { ptBR } from "date-fns/locale/pt-BR";
|
|
2161
|
+
import { FormikContext, getIn } from "formik";
|
|
2162
|
+
import { useContext, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef5, useState as useState4 } from "react";
|
|
2163
|
+
import { createPortal as createPortal3 } from "react-dom";
|
|
2164
|
+
import { MdCalendarMonth, MdChevronLeft, MdChevronRight } from "react-icons/md";
|
|
2165
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2166
|
+
var WEEKDAYS = ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"];
|
|
2167
|
+
var CALENDAR_WIDTH = 256;
|
|
2168
|
+
var VIEWPORT_MARGIN = 8;
|
|
2169
|
+
var CALENDAR_GAP = 4;
|
|
2170
|
+
var MONTHS = [
|
|
2171
|
+
"Janeiro",
|
|
2172
|
+
"Fevereiro",
|
|
2173
|
+
"Mar\xE7o",
|
|
2174
|
+
"Abril",
|
|
2175
|
+
"Maio",
|
|
2176
|
+
"Junho",
|
|
2177
|
+
"Julho",
|
|
2178
|
+
"Agosto",
|
|
2179
|
+
"Setembro",
|
|
2180
|
+
"Outubro",
|
|
2181
|
+
"Novembro",
|
|
2182
|
+
"Dezembro"
|
|
2183
|
+
];
|
|
2184
|
+
var formatDateForInput = (date) => {
|
|
2185
|
+
if (!date || !isValid(date)) return "";
|
|
2186
|
+
return format(date, "dd/MM/yyyy");
|
|
2187
|
+
};
|
|
2188
|
+
var formatInputValue = (value) => {
|
|
2189
|
+
const digits = value.replace(/\D/g, "").slice(0, 8);
|
|
2190
|
+
if (digits.length <= 2) return digits;
|
|
2191
|
+
if (digits.length <= 4) return `${digits.slice(0, 2)}/${digits.slice(2)}`;
|
|
2192
|
+
return `${digits.slice(0, 2)}/${digits.slice(2, 4)}/${digits.slice(4)}`;
|
|
2193
|
+
};
|
|
2194
|
+
var parseDateValue = (value) => {
|
|
2195
|
+
if (!value) return null;
|
|
2196
|
+
if (value instanceof Date) {
|
|
2197
|
+
return isValid(value) ? value : null;
|
|
2198
|
+
}
|
|
2199
|
+
if (typeof value === "string") {
|
|
2200
|
+
const trimmedValue = value.trim();
|
|
2201
|
+
if (!trimmedValue) return null;
|
|
2202
|
+
const parsedPtBr = parse(trimmedValue, "dd/MM/yyyy", /* @__PURE__ */ new Date());
|
|
2203
|
+
if (isValid(parsedPtBr) && format(parsedPtBr, "dd/MM/yyyy") === trimmedValue) {
|
|
2204
|
+
return parsedPtBr;
|
|
2205
|
+
}
|
|
2206
|
+
const nativeDate = new Date(trimmedValue);
|
|
2207
|
+
return isValid(nativeDate) ? nativeDate : null;
|
|
2208
|
+
}
|
|
2209
|
+
return null;
|
|
2210
|
+
};
|
|
2211
|
+
var getSafeViewDate = (date) => date && isValid(date) ? date : /* @__PURE__ */ new Date();
|
|
2212
|
+
var UnifiedDatePicker = ({
|
|
2213
|
+
value,
|
|
2214
|
+
onChange,
|
|
2215
|
+
onBlur,
|
|
2216
|
+
label,
|
|
2217
|
+
placeholder = "dd/mm/aaaa",
|
|
2218
|
+
minDate = addYears(/* @__PURE__ */ new Date(), -120),
|
|
2219
|
+
maxDate = addYears(/* @__PURE__ */ new Date(), 120),
|
|
2220
|
+
isDisabled = false,
|
|
2221
|
+
disabled = false,
|
|
2222
|
+
name = "data",
|
|
2223
|
+
error,
|
|
2224
|
+
errorText,
|
|
2225
|
+
defaultView = "days",
|
|
2226
|
+
navigationVariant = "drilldown",
|
|
2227
|
+
showAdjacentDays = true,
|
|
2228
|
+
className
|
|
2229
|
+
}) => {
|
|
2230
|
+
const formik = useContext(
|
|
2231
|
+
FormikContext
|
|
2232
|
+
);
|
|
2233
|
+
const hasFormikField = Boolean(formik && name);
|
|
2234
|
+
const formikRawValue = hasFormikField && formik ? getIn(formik.values, name) : void 0;
|
|
2235
|
+
const selectedDate = useMemo2(
|
|
2236
|
+
() => parseDateValue(hasFormikField ? formikRawValue : value),
|
|
2237
|
+
[formikRawValue, hasFormikField, value]
|
|
2238
|
+
);
|
|
2239
|
+
const formikTouched = hasFormikField && formik ? Boolean(getIn(formik.touched, name)) : false;
|
|
2240
|
+
const formikError = hasFormikField && formik ? getIn(formik.errors, name) : void 0;
|
|
2241
|
+
const isFieldDisabled = disabled || isDisabled;
|
|
2242
|
+
const [isOpen, setIsOpen] = useState4(false);
|
|
2243
|
+
const [isEditing, setIsEditing] = useState4(false);
|
|
2244
|
+
const [draftValue, setDraftValue] = useState4(
|
|
2245
|
+
formatDateForInput(selectedDate)
|
|
2246
|
+
);
|
|
2247
|
+
const [viewDate, setViewDate] = useState4(getSafeViewDate(selectedDate));
|
|
2248
|
+
const [mode, setMode] = useState4(defaultView);
|
|
2249
|
+
const [inputError, setInputError] = useState4(null);
|
|
2250
|
+
const containerRef = useRef5(null);
|
|
2251
|
+
const inputRef = useRef5(null);
|
|
2252
|
+
const dropdownRef = useRef5(null);
|
|
2253
|
+
const rafRef = useRef5(null);
|
|
2254
|
+
const [isMounted, setIsMounted] = useState4(false);
|
|
2255
|
+
const [panelNeedsScroll, setPanelNeedsScroll] = useState4(false);
|
|
2256
|
+
const [dropdownStyle, setDropdownStyle] = useState4({});
|
|
2257
|
+
useEffect3(() => {
|
|
2258
|
+
setIsMounted(true);
|
|
2259
|
+
}, []);
|
|
2260
|
+
useEffect3(() => {
|
|
2261
|
+
if (!isEditing) {
|
|
2262
|
+
setDraftValue(formatDateForInput(selectedDate));
|
|
2263
|
+
}
|
|
2264
|
+
setViewDate(getSafeViewDate(selectedDate));
|
|
2265
|
+
}, [isEditing, selectedDate]);
|
|
2266
|
+
useEffect3(() => {
|
|
2267
|
+
if (!isOpen) return;
|
|
2268
|
+
setMode(navigationVariant === "dropdown" ? "days" : defaultView);
|
|
2269
|
+
const onMouseDown = (event) => {
|
|
2270
|
+
var _a, _b;
|
|
2271
|
+
if (!((_a = containerRef.current) == null ? void 0 : _a.contains(event.target)) && !((_b = dropdownRef.current) == null ? void 0 : _b.contains(event.target))) {
|
|
2272
|
+
setIsOpen(false);
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
const onKeyDown = (event) => {
|
|
2276
|
+
if (event.key === "Escape") setIsOpen(false);
|
|
2277
|
+
};
|
|
2278
|
+
document.addEventListener("mousedown", onMouseDown);
|
|
2279
|
+
document.addEventListener("keydown", onKeyDown);
|
|
2280
|
+
return () => {
|
|
2281
|
+
document.removeEventListener("mousedown", onMouseDown);
|
|
2282
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
2283
|
+
};
|
|
2284
|
+
}, [defaultView, isOpen, navigationVariant]);
|
|
2285
|
+
useEffect3(() => {
|
|
2286
|
+
if (!isOpen) return;
|
|
2287
|
+
const updateDropdownPosition = () => {
|
|
2288
|
+
var _a;
|
|
2289
|
+
if (!containerRef.current) return;
|
|
2290
|
+
const rect = ((_a = inputRef.current) != null ? _a : containerRef.current).getBoundingClientRect();
|
|
2291
|
+
const isOutOfViewport = rect.bottom <= 0 || rect.top >= window.innerHeight || rect.right <= 0 || rect.left >= window.innerWidth;
|
|
2292
|
+
if (isOutOfViewport) {
|
|
2293
|
+
setIsOpen(false);
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
const dropdown = dropdownRef.current;
|
|
2297
|
+
const panelHeight = (dropdown == null ? void 0 : dropdown.scrollHeight) || 320;
|
|
2298
|
+
const panelRect = calculateFloatingPanelRect({
|
|
2299
|
+
trigger: rect,
|
|
2300
|
+
panel: {
|
|
2301
|
+
width: CALENDAR_WIDTH,
|
|
2302
|
+
height: panelHeight
|
|
2303
|
+
},
|
|
2304
|
+
viewport: {
|
|
2305
|
+
width: window.innerWidth,
|
|
2306
|
+
height: window.innerHeight
|
|
2307
|
+
},
|
|
2308
|
+
gap: CALENDAR_GAP,
|
|
2309
|
+
margin: VIEWPORT_MARGIN
|
|
2310
|
+
});
|
|
2311
|
+
const needsScroll = panelHeight > panelRect.maxHeight + 1;
|
|
2312
|
+
setPanelNeedsScroll(needsScroll);
|
|
2313
|
+
setDropdownStyle({
|
|
2314
|
+
position: "fixed",
|
|
2315
|
+
top: panelRect.top,
|
|
2316
|
+
left: panelRect.left,
|
|
2317
|
+
width: panelRect.width,
|
|
2318
|
+
maxHeight: needsScroll ? panelRect.maxHeight : void 0
|
|
2319
|
+
});
|
|
2320
|
+
};
|
|
2321
|
+
const scheduleDropdownPosition = () => {
|
|
2322
|
+
if (rafRef.current != null) return;
|
|
2323
|
+
rafRef.current = window.requestAnimationFrame(() => {
|
|
2324
|
+
rafRef.current = null;
|
|
2325
|
+
updateDropdownPosition();
|
|
2326
|
+
});
|
|
2327
|
+
};
|
|
2328
|
+
updateDropdownPosition();
|
|
2329
|
+
window.addEventListener("resize", scheduleDropdownPosition);
|
|
2330
|
+
window.addEventListener("scroll", scheduleDropdownPosition, true);
|
|
2331
|
+
return () => {
|
|
2332
|
+
if (rafRef.current != null) {
|
|
2333
|
+
window.cancelAnimationFrame(rafRef.current);
|
|
2334
|
+
rafRef.current = null;
|
|
2335
|
+
}
|
|
2336
|
+
window.removeEventListener("resize", scheduleDropdownPosition);
|
|
2337
|
+
window.removeEventListener("scroll", scheduleDropdownPosition, true);
|
|
2338
|
+
};
|
|
2339
|
+
}, [isOpen, defaultView, navigationVariant, viewDate, draftValue]);
|
|
2340
|
+
const syncValue = (nextDate) => {
|
|
2341
|
+
if (hasFormikField && formik) {
|
|
2342
|
+
formik.setFieldValue(name, nextDate);
|
|
2343
|
+
}
|
|
2344
|
+
onChange == null ? void 0 : onChange(nextDate);
|
|
2345
|
+
};
|
|
2346
|
+
const touchField = () => {
|
|
2347
|
+
if (hasFormikField && formik) {
|
|
2348
|
+
formik.setFieldTouched(name, true);
|
|
2349
|
+
}
|
|
2350
|
+
};
|
|
2351
|
+
const openCalendar = () => {
|
|
2352
|
+
var _a;
|
|
2353
|
+
if (isFieldDisabled) return;
|
|
2354
|
+
setIsOpen(true);
|
|
2355
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
2356
|
+
};
|
|
2357
|
+
const getDaysInView = () => {
|
|
2358
|
+
const start = startOfWeek(startOfMonth(viewDate), { weekStartsOn: 0 });
|
|
2359
|
+
const end = endOfWeek(endOfMonth(viewDate), { weekStartsOn: 0 });
|
|
2360
|
+
return eachDayOfInterval({ start, end });
|
|
2361
|
+
};
|
|
2362
|
+
const handleDayClick = (day) => {
|
|
2363
|
+
if (isBefore(day, startOfDay(minDate)) || isAfter(day, startOfDay(maxDate)))
|
|
2364
|
+
return;
|
|
2365
|
+
syncValue(day);
|
|
2366
|
+
setDraftValue(formatDateForInput(day));
|
|
2367
|
+
setInputError(null);
|
|
2368
|
+
setViewDate(day);
|
|
2369
|
+
touchField();
|
|
2370
|
+
setIsOpen(false);
|
|
2371
|
+
};
|
|
2372
|
+
const handleMonthClick = (monthIndex) => {
|
|
2373
|
+
setViewDate((currentDate) => {
|
|
2374
|
+
const nextDate = new Date(currentDate);
|
|
2375
|
+
nextDate.setMonth(monthIndex);
|
|
2376
|
+
return nextDate;
|
|
2377
|
+
});
|
|
2378
|
+
setMode("days");
|
|
2379
|
+
};
|
|
2380
|
+
const handleMonthChange = (monthIndex) => {
|
|
2381
|
+
setViewDate((currentDate) => {
|
|
2382
|
+
const nextDate = new Date(currentDate);
|
|
2383
|
+
nextDate.setDate(1);
|
|
2384
|
+
nextDate.setMonth(monthIndex);
|
|
2385
|
+
return nextDate;
|
|
2386
|
+
});
|
|
2387
|
+
};
|
|
2388
|
+
const handleYearClick = (year) => {
|
|
2389
|
+
setViewDate((currentDate) => {
|
|
2390
|
+
const nextDate = new Date(currentDate);
|
|
2391
|
+
nextDate.setFullYear(year);
|
|
2392
|
+
return nextDate;
|
|
2393
|
+
});
|
|
2394
|
+
setMode("days");
|
|
2395
|
+
};
|
|
2396
|
+
const handleYearChange = (year) => {
|
|
2397
|
+
setViewDate((currentDate) => {
|
|
2398
|
+
const nextDate = new Date(currentDate);
|
|
2399
|
+
nextDate.setDate(1);
|
|
2400
|
+
nextDate.setFullYear(year);
|
|
2401
|
+
if (year === minDate.getFullYear() && nextDate < startOfMonth(minDate)) {
|
|
2402
|
+
nextDate.setMonth(minDate.getMonth());
|
|
2403
|
+
}
|
|
2404
|
+
if (year === maxDate.getFullYear() && nextDate > startOfMonth(maxDate)) {
|
|
2405
|
+
nextDate.setMonth(maxDate.getMonth());
|
|
2406
|
+
}
|
|
2407
|
+
return nextDate;
|
|
2408
|
+
});
|
|
2409
|
+
};
|
|
2410
|
+
const commitDraftValue = (rawValue) => {
|
|
2411
|
+
const normalizedValue = formatInputValue(rawValue);
|
|
2412
|
+
setDraftValue(normalizedValue);
|
|
2413
|
+
touchField();
|
|
2414
|
+
if (!normalizedValue) {
|
|
2415
|
+
syncValue(null);
|
|
2416
|
+
setInputError(null);
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
if (normalizedValue.length < 10) {
|
|
2420
|
+
syncValue(null);
|
|
2421
|
+
setInputError("Data incompleta");
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
const parsedDate = parseDateValue(normalizedValue);
|
|
2425
|
+
if (!parsedDate) {
|
|
2426
|
+
syncValue(null);
|
|
2427
|
+
setInputError("Data invalida");
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
if (isBefore(parsedDate, startOfDay(minDate)) || isAfter(parsedDate, startOfDay(maxDate))) {
|
|
2431
|
+
syncValue(null);
|
|
2432
|
+
setInputError("Data fora do intervalo permitido");
|
|
2433
|
+
return;
|
|
2434
|
+
}
|
|
2435
|
+
syncValue(parsedDate);
|
|
2436
|
+
setViewDate(parsedDate);
|
|
2437
|
+
setInputError(null);
|
|
2438
|
+
};
|
|
2439
|
+
const yearRangeStart = viewDate.getFullYear() - 5;
|
|
2440
|
+
const years = Array.from(
|
|
2441
|
+
{ length: 12 },
|
|
2442
|
+
(_, index) => yearRangeStart + index
|
|
2443
|
+
);
|
|
2444
|
+
const minYear = minDate.getFullYear();
|
|
2445
|
+
const maxYear = maxDate.getFullYear();
|
|
2446
|
+
const selectableYears = Array.from(
|
|
2447
|
+
{ length: Math.max(0, maxYear - minYear + 1) },
|
|
2448
|
+
(_, index) => minYear + index
|
|
2449
|
+
);
|
|
2450
|
+
const previousMonth = subMonths(viewDate, 1);
|
|
2451
|
+
const nextMonth = addMonths(viewDate, 1);
|
|
2452
|
+
const previousMonthDisabled = isBefore(
|
|
2453
|
+
endOfMonth(previousMonth),
|
|
2454
|
+
startOfDay(minDate)
|
|
2455
|
+
);
|
|
2456
|
+
const nextMonthDisabled = isAfter(
|
|
2457
|
+
startOfMonth(nextMonth),
|
|
2458
|
+
startOfDay(maxDate)
|
|
2459
|
+
);
|
|
2460
|
+
const headerLabel = mode === "days" ? format(viewDate, "MMMM yyyy", { locale: ptBR }) : mode === "months" ? String(viewDate.getFullYear()) : `${yearRangeStart} - ${yearRangeStart + 11}`;
|
|
2461
|
+
const resolvedErrorText = inputError || (formikTouched && typeof formikError === "string" ? formikError : errorText);
|
|
2462
|
+
const hasError = Boolean(
|
|
2463
|
+
inputError || formikTouched && formikError || error
|
|
2464
|
+
);
|
|
2465
|
+
const errorId = `${name}-error`;
|
|
2466
|
+
return /* @__PURE__ */ jsxs6(
|
|
2467
|
+
FieldFrame_default,
|
|
2468
|
+
{
|
|
2469
|
+
className: "relative",
|
|
2470
|
+
ref: containerRef,
|
|
2471
|
+
label,
|
|
2472
|
+
labelFor: name,
|
|
2473
|
+
invalid: hasError,
|
|
2474
|
+
message: resolvedErrorText,
|
|
2475
|
+
messageId: errorId,
|
|
2476
|
+
children: [
|
|
2477
|
+
/* @__PURE__ */ jsxs6(
|
|
2478
|
+
"div",
|
|
2479
|
+
{
|
|
2480
|
+
"data-has-value": draftValue.length > 0,
|
|
2481
|
+
className: classNames6(
|
|
2482
|
+
FIELD_CONTROL_CLASS,
|
|
2483
|
+
{
|
|
2484
|
+
[FIELD_DISABLED_CLASS]: isFieldDisabled,
|
|
2485
|
+
[FIELD_ERROR_CLASS]: hasError
|
|
2486
|
+
},
|
|
2487
|
+
className
|
|
2488
|
+
),
|
|
2489
|
+
children: [
|
|
2490
|
+
/* @__PURE__ */ jsx6(
|
|
2491
|
+
"input",
|
|
2492
|
+
{
|
|
2493
|
+
ref: inputRef,
|
|
2494
|
+
id: name,
|
|
2495
|
+
name,
|
|
2496
|
+
"aria-invalid": hasError || void 0,
|
|
2497
|
+
"aria-describedby": hasError && resolvedErrorText ? errorId : void 0,
|
|
2498
|
+
type: "text",
|
|
2499
|
+
inputMode: "numeric",
|
|
2500
|
+
autoComplete: "off",
|
|
2501
|
+
maxLength: 10,
|
|
2502
|
+
disabled: isFieldDisabled,
|
|
2503
|
+
placeholder,
|
|
2504
|
+
value: draftValue,
|
|
2505
|
+
onClick: openCalendar,
|
|
2506
|
+
onFocus: () => {
|
|
2507
|
+
setIsEditing(true);
|
|
2508
|
+
openCalendar();
|
|
2509
|
+
},
|
|
2510
|
+
onChange: (event) => {
|
|
2511
|
+
const nextValue = formatInputValue(event.target.value);
|
|
2512
|
+
setDraftValue(nextValue);
|
|
2513
|
+
setInputError(null);
|
|
2514
|
+
if (nextValue.length === 10) {
|
|
2515
|
+
const parsedDate = parseDateValue(nextValue);
|
|
2516
|
+
if (parsedDate) {
|
|
2517
|
+
setViewDate(parsedDate);
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
},
|
|
2521
|
+
onBlur: (event) => {
|
|
2522
|
+
setIsEditing(false);
|
|
2523
|
+
commitDraftValue(event.target.value);
|
|
2524
|
+
onBlur == null ? void 0 : onBlur(event);
|
|
2525
|
+
},
|
|
2526
|
+
onKeyDown: (event) => {
|
|
2527
|
+
if (event.key === "Enter") {
|
|
2528
|
+
commitDraftValue(draftValue);
|
|
2529
|
+
setIsOpen(false);
|
|
2530
|
+
}
|
|
2531
|
+
},
|
|
2532
|
+
className: FIELD_INPUT_CLASS
|
|
2533
|
+
}
|
|
2534
|
+
),
|
|
2535
|
+
/* @__PURE__ */ jsx6(
|
|
2536
|
+
"button",
|
|
2537
|
+
{
|
|
2538
|
+
type: "button",
|
|
2539
|
+
disabled: isFieldDisabled,
|
|
2540
|
+
onClick: openCalendar,
|
|
2541
|
+
className: "flex items-center justify-center disabled:cursor-not-allowed",
|
|
2542
|
+
"aria-label": "Abrir calendario",
|
|
2543
|
+
children: /* @__PURE__ */ jsx6(
|
|
2544
|
+
MdCalendarMonth,
|
|
2545
|
+
{
|
|
2546
|
+
className: classNames6("h-5 w-5", {
|
|
2547
|
+
"text-field-assistive-error": hasError
|
|
2548
|
+
})
|
|
2549
|
+
}
|
|
2550
|
+
)
|
|
2551
|
+
}
|
|
2552
|
+
)
|
|
2553
|
+
]
|
|
2554
|
+
}
|
|
2555
|
+
),
|
|
2556
|
+
isMounted && isOpen ? createPortal3(
|
|
2557
|
+
/* @__PURE__ */ jsxs6(
|
|
2558
|
+
"div",
|
|
2559
|
+
{
|
|
2560
|
+
ref: dropdownRef,
|
|
2561
|
+
style: dropdownStyle,
|
|
2562
|
+
className: classNames6(
|
|
2563
|
+
getFloatingLayerClass(containerRef.current, "popover"),
|
|
2564
|
+
"rounded-sm border border-border-default bg-white shadow-md transition-all duration-150",
|
|
2565
|
+
panelNeedsScroll ? "overflow-y-auto overscroll-contain" : "overflow-visible",
|
|
2566
|
+
"py-3"
|
|
2567
|
+
),
|
|
2568
|
+
children: [
|
|
2569
|
+
/* @__PURE__ */ jsxs6("div", { className: "mb-1 flex items-center justify-between px-1", children: [
|
|
2570
|
+
/* @__PURE__ */ jsx6(
|
|
2571
|
+
"button",
|
|
2572
|
+
{
|
|
2573
|
+
type: "button",
|
|
2574
|
+
"aria-label": "Exibir m\xEAs anterior",
|
|
2575
|
+
disabled: navigationVariant === "dropdown" && previousMonthDisabled,
|
|
2576
|
+
onClick: () => mode === "days" ? setViewDate((currentDate) => subMonths(currentDate, 1)) : mode === "months" ? setViewDate((currentDate) => {
|
|
2577
|
+
const nextDate = new Date(currentDate);
|
|
2578
|
+
nextDate.setFullYear(nextDate.getFullYear() - 1);
|
|
2579
|
+
return nextDate;
|
|
2580
|
+
}) : setViewDate((currentDate) => {
|
|
2581
|
+
const nextDate = new Date(currentDate);
|
|
2582
|
+
nextDate.setFullYear(nextDate.getFullYear() - 12);
|
|
2583
|
+
return nextDate;
|
|
2584
|
+
}),
|
|
2585
|
+
className: "rounded-sm p-1 text-primary-1 transition-colors hover:bg-primary-1/10 disabled:cursor-not-allowed disabled:text-content-disabled",
|
|
2586
|
+
children: /* @__PURE__ */ jsx6(MdChevronLeft, { "aria-hidden": "true", className: "h-5 w-5" })
|
|
2587
|
+
}
|
|
2588
|
+
),
|
|
2589
|
+
navigationVariant === "dropdown" ? /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-[6px]", children: [
|
|
2590
|
+
/* @__PURE__ */ jsx6(
|
|
2591
|
+
"select",
|
|
2592
|
+
{
|
|
2593
|
+
"aria-label": "Selecionar m\xEAs do calend\xE1rio",
|
|
2594
|
+
value: viewDate.getMonth(),
|
|
2595
|
+
onChange: (event) => handleMonthChange(Number(event.target.value)),
|
|
2596
|
+
className: "h-6 w-24 rounded-sm border-2 border-border-default bg-field-surface px-0.5 text-xs leading-3 text-field-content focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring",
|
|
2597
|
+
children: MONTHS.map((month, monthIndex) => /* @__PURE__ */ jsx6(
|
|
2598
|
+
"option",
|
|
2599
|
+
{
|
|
2600
|
+
value: monthIndex,
|
|
2601
|
+
disabled: viewDate.getFullYear() === minYear && monthIndex < minDate.getMonth() || viewDate.getFullYear() === maxYear && monthIndex > maxDate.getMonth(),
|
|
2602
|
+
children: month
|
|
2603
|
+
},
|
|
2604
|
+
month
|
|
2605
|
+
))
|
|
2606
|
+
}
|
|
2607
|
+
),
|
|
2608
|
+
/* @__PURE__ */ jsx6(
|
|
2609
|
+
"select",
|
|
2610
|
+
{
|
|
2611
|
+
"aria-label": "Selecionar ano do calend\xE1rio",
|
|
2612
|
+
value: viewDate.getFullYear(),
|
|
2613
|
+
onChange: (event) => handleYearChange(Number(event.target.value)),
|
|
2614
|
+
className: "h-6 w-[58px] rounded-sm border-2 border-border-default bg-field-surface px-0.5 text-xs leading-3 text-field-content focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring",
|
|
2615
|
+
children: selectableYears.map((year) => /* @__PURE__ */ jsx6("option", { value: year, children: year }, year))
|
|
2616
|
+
}
|
|
2617
|
+
)
|
|
2618
|
+
] }) : /* @__PURE__ */ jsx6(
|
|
2619
|
+
"button",
|
|
2620
|
+
{
|
|
2621
|
+
type: "button",
|
|
2622
|
+
onClick: () => setMode(
|
|
2623
|
+
(currentMode) => currentMode === "days" ? "months" : currentMode === "months" ? "years" : "days"
|
|
2624
|
+
),
|
|
2625
|
+
className: "px-2 text-sm font-semibold capitalize text-content-primary transition-colors hover:text-primary-1",
|
|
2626
|
+
children: headerLabel
|
|
2627
|
+
}
|
|
2628
|
+
),
|
|
2629
|
+
/* @__PURE__ */ jsx6(
|
|
2630
|
+
"button",
|
|
2631
|
+
{
|
|
2632
|
+
type: "button",
|
|
2633
|
+
"aria-label": "Exibir pr\xF3ximo m\xEAs",
|
|
2634
|
+
disabled: navigationVariant === "dropdown" && nextMonthDisabled,
|
|
2635
|
+
onClick: () => mode === "days" ? setViewDate((currentDate) => addMonths(currentDate, 1)) : mode === "months" ? setViewDate((currentDate) => {
|
|
2636
|
+
const nextDate = new Date(currentDate);
|
|
2637
|
+
nextDate.setFullYear(nextDate.getFullYear() + 1);
|
|
2638
|
+
return nextDate;
|
|
2639
|
+
}) : setViewDate((currentDate) => {
|
|
2640
|
+
const nextDate = new Date(currentDate);
|
|
2641
|
+
nextDate.setFullYear(nextDate.getFullYear() + 12);
|
|
2642
|
+
return nextDate;
|
|
2643
|
+
}),
|
|
2644
|
+
className: "rounded-sm p-1 text-primary-1 transition-colors hover:bg-primary-1/10 disabled:cursor-not-allowed disabled:text-content-disabled",
|
|
2645
|
+
children: /* @__PURE__ */ jsx6(MdChevronRight, { "aria-hidden": "true", className: "h-5 w-5" })
|
|
2646
|
+
}
|
|
2647
|
+
)
|
|
2648
|
+
] }),
|
|
2649
|
+
mode === "days" && /* @__PURE__ */ jsxs6("div", { className: "px-3", children: [
|
|
2650
|
+
/* @__PURE__ */ jsx6("div", { className: "grid grid-cols-7 gap-x-1", children: WEEKDAYS.map((weekday) => /* @__PURE__ */ jsx6(
|
|
2651
|
+
"div",
|
|
2652
|
+
{
|
|
2653
|
+
className: "select-none py-0.5 text-center text-2xs font-semibold text-content-muted",
|
|
2654
|
+
children: weekday
|
|
2655
|
+
},
|
|
2656
|
+
weekday
|
|
2657
|
+
)) }),
|
|
2658
|
+
/* @__PURE__ */ jsx6("div", { className: "grid grid-cols-7 gap-x-1", children: getDaysInView().map((day, index) => {
|
|
2659
|
+
const selected = selectedDate ? isSameDay(day, selectedDate) : false;
|
|
2660
|
+
const currentDay = isToday(day);
|
|
2661
|
+
const inMonth = isSameMonth(day, viewDate);
|
|
2662
|
+
const dayDisabled = isBefore(day, startOfDay(minDate)) || isAfter(day, startOfDay(maxDate));
|
|
2663
|
+
if (!showAdjacentDays && !inMonth) {
|
|
2664
|
+
return /* @__PURE__ */ jsx6(
|
|
2665
|
+
"span",
|
|
2666
|
+
{
|
|
2667
|
+
"aria-hidden": "true",
|
|
2668
|
+
className: "h-7"
|
|
2669
|
+
},
|
|
2670
|
+
`${day.toISOString()}-${index}`
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
return /* @__PURE__ */ jsx6(
|
|
2674
|
+
"button",
|
|
2675
|
+
{
|
|
2676
|
+
type: "button",
|
|
2677
|
+
onClick: () => handleDayClick(day),
|
|
2678
|
+
disabled: dayDisabled,
|
|
2679
|
+
className: classNames6(
|
|
2680
|
+
"group flex h-7 w-full items-center justify-center text-xs transition-colors",
|
|
2681
|
+
{
|
|
2682
|
+
"opacity-30 cursor-not-allowed": dayDisabled,
|
|
2683
|
+
"cursor-pointer": !dayDisabled
|
|
2684
|
+
}
|
|
2685
|
+
),
|
|
2686
|
+
children: /* @__PURE__ */ jsx6(
|
|
2687
|
+
"span",
|
|
2688
|
+
{
|
|
2689
|
+
className: classNames6(
|
|
2690
|
+
"flex h-6 w-6 items-center justify-center rounded-sm transition-colors",
|
|
2691
|
+
{
|
|
2692
|
+
"border border-selection-border bg-selection-background font-semibold text-selection-content": selected,
|
|
2693
|
+
"border border-primary-1 text-primary-1 font-semibold group-hover:bg-primary-1/10": currentDay && inMonth && !selected,
|
|
2694
|
+
"text-content-primary group-hover:bg-primary-1/10": inMonth && !selected && !currentDay,
|
|
2695
|
+
"text-content-muted": !inMonth
|
|
2696
|
+
}
|
|
2697
|
+
),
|
|
2698
|
+
children: format(day, "d")
|
|
2699
|
+
}
|
|
2700
|
+
)
|
|
2701
|
+
},
|
|
2702
|
+
`${day.toISOString()}-${index}`
|
|
2703
|
+
);
|
|
2704
|
+
}) })
|
|
2705
|
+
] }),
|
|
2706
|
+
mode === "months" && /* @__PURE__ */ jsx6("div", { className: "grid grid-cols-3 gap-1 px-3", children: MONTHS.map((month, index) => {
|
|
2707
|
+
const selected = index === viewDate.getMonth();
|
|
2708
|
+
return /* @__PURE__ */ jsx6(
|
|
2709
|
+
"button",
|
|
2710
|
+
{
|
|
2711
|
+
type: "button",
|
|
2712
|
+
onClick: () => handleMonthClick(index),
|
|
2713
|
+
className: classNames6(
|
|
2714
|
+
"rounded-sm py-1 text-xs capitalize transition-colors",
|
|
2715
|
+
{
|
|
2716
|
+
"border border-selection-border bg-selection-background font-semibold text-selection-content": selected,
|
|
2717
|
+
"text-content-primary hover:bg-primary-1/10": !selected
|
|
2718
|
+
}
|
|
2719
|
+
),
|
|
2720
|
+
children: month.slice(0, 3)
|
|
2721
|
+
},
|
|
2722
|
+
month
|
|
2723
|
+
);
|
|
2724
|
+
}) }),
|
|
2725
|
+
mode === "years" && /* @__PURE__ */ jsx6("div", { className: "grid grid-cols-3 gap-1 px-3", children: years.map((year) => {
|
|
2726
|
+
const selected = year === viewDate.getFullYear();
|
|
2727
|
+
return /* @__PURE__ */ jsx6(
|
|
2728
|
+
"button",
|
|
2729
|
+
{
|
|
2730
|
+
type: "button",
|
|
2731
|
+
onClick: () => handleYearClick(year),
|
|
2732
|
+
className: classNames6(
|
|
2733
|
+
"rounded-sm py-1 text-xs transition-colors",
|
|
2734
|
+
{
|
|
2735
|
+
"border border-selection-border bg-selection-background font-semibold text-selection-content": selected,
|
|
2736
|
+
"text-content-primary hover:bg-primary-1/10": !selected
|
|
2737
|
+
}
|
|
2738
|
+
),
|
|
2739
|
+
children: year
|
|
2740
|
+
},
|
|
2741
|
+
year
|
|
2742
|
+
);
|
|
2743
|
+
}) })
|
|
2744
|
+
]
|
|
2745
|
+
}
|
|
2746
|
+
),
|
|
2747
|
+
document.body
|
|
2748
|
+
) : null
|
|
2749
|
+
]
|
|
2750
|
+
}
|
|
2751
|
+
);
|
|
2752
|
+
};
|
|
2753
|
+
var UnifiedDatePicker_default = UnifiedDatePicker;
|
|
2754
|
+
|
|
2755
|
+
// src/components/datePicker/datePicker.tsx
|
|
2756
|
+
var DatePicker = UnifiedDatePicker_default;
|
|
2757
|
+
var Datepicker = DatePicker;
|
|
2758
|
+
var datePicker_default = DatePicker;
|
|
2759
|
+
|
|
2760
|
+
// src/components/selectMulti/SelectMultiView.tsx
|
|
2761
|
+
import cs from "classnames";
|
|
2762
|
+
import {
|
|
2763
|
+
useEffect as useEffect4,
|
|
2764
|
+
useId as useId3,
|
|
2765
|
+
useRef as useRef6,
|
|
2766
|
+
useState as useState5
|
|
2767
|
+
} from "react";
|
|
2768
|
+
import { MdClose, MdKeyboardArrowDown } from "react-icons/md";
|
|
2769
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2770
|
+
function SelectMultiView(props) {
|
|
2771
|
+
const { options, error, label, checkedList = [], onClear, disabled } = props;
|
|
2772
|
+
const [isOpened, setIsOpened] = useState5(false);
|
|
2773
|
+
const containerRef = useRef6(null);
|
|
2774
|
+
const triggerRef = useRef6(null);
|
|
2775
|
+
const groupRef = useRef6(null);
|
|
2776
|
+
const baseId = useId3();
|
|
2777
|
+
const triggerId = `${baseId}-trigger`;
|
|
2778
|
+
const labelId = `${baseId}-label`;
|
|
2779
|
+
const groupId = `${baseId}-options`;
|
|
2780
|
+
const summaryId = `${baseId}-summary`;
|
|
2781
|
+
const errorId = `${baseId}-error`;
|
|
2782
|
+
const selectedCount = checkedList.length;
|
|
2783
|
+
const selectedSummary = selectedCount === 0 ? "Nenhuma op\xE7\xE3o selecionada" : selectedCount === 1 ? "1 op\xE7\xE3o selecionada" : `${selectedCount} op\xE7\xF5es selecionadas`;
|
|
2784
|
+
const describedBy = [summaryId, error ? errorId : void 0].filter(Boolean).join(" ");
|
|
2785
|
+
const floatingLayerClass = getFloatingLayerClass(
|
|
2786
|
+
triggerRef.current,
|
|
2787
|
+
"popover"
|
|
2788
|
+
);
|
|
2789
|
+
const menuLayerClass = floatingLayerClass === "z-popover" ? "z-menu" : floatingLayerClass;
|
|
2790
|
+
const closeAndFocusTrigger = () => {
|
|
2791
|
+
var _a;
|
|
2792
|
+
setIsOpened(false);
|
|
2793
|
+
(_a = triggerRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
2794
|
+
};
|
|
2795
|
+
useEffect4(() => {
|
|
2796
|
+
var _a, _b;
|
|
2797
|
+
if (!isOpened) return;
|
|
2798
|
+
(_b = (_a = groupRef.current) == null ? void 0 : _a.querySelector('input[type="checkbox"]')) == null ? void 0 : _b.focus({ preventScroll: true });
|
|
2799
|
+
}, [isOpened]);
|
|
2800
|
+
useEffect4(() => {
|
|
2801
|
+
function handleClickOutside(event) {
|
|
2802
|
+
var _a;
|
|
2803
|
+
if (!((_a = containerRef.current) == null ? void 0 : _a.contains(event.target))) {
|
|
2804
|
+
setIsOpened(false);
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
if (isOpened) {
|
|
2808
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2809
|
+
}
|
|
2810
|
+
return () => {
|
|
2811
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
2812
|
+
};
|
|
2813
|
+
}, [isOpened]);
|
|
2814
|
+
useEffect4(() => {
|
|
2815
|
+
if (disabled) setIsOpened(false);
|
|
2816
|
+
}, [disabled]);
|
|
2817
|
+
const handleOptionKeyDown = (event) => {
|
|
2818
|
+
var _a, _b, _c, _d, _e;
|
|
2819
|
+
const checkboxes = Array.from(
|
|
2820
|
+
(_b = (_a = groupRef.current) == null ? void 0 : _a.querySelectorAll(
|
|
2821
|
+
'input[type="checkbox"]:not([disabled])'
|
|
2822
|
+
)) != null ? _b : []
|
|
2823
|
+
);
|
|
2824
|
+
const currentIndex = checkboxes.indexOf(event.currentTarget);
|
|
2825
|
+
if (event.key === "Escape") {
|
|
2826
|
+
event.preventDefault();
|
|
2827
|
+
closeAndFocusTrigger();
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
if (event.key === "Enter") {
|
|
2831
|
+
event.preventDefault();
|
|
2832
|
+
event.currentTarget.click();
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp" && event.key !== "Home" && event.key !== "End") {
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
event.preventDefault();
|
|
2839
|
+
if (event.key === "Home") {
|
|
2840
|
+
(_c = checkboxes[0]) == null ? void 0 : _c.focus({ preventScroll: true });
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
if (event.key === "End") {
|
|
2844
|
+
(_d = checkboxes[checkboxes.length - 1]) == null ? void 0 : _d.focus({ preventScroll: true });
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
2848
|
+
const nextIndex = (currentIndex + direction + checkboxes.length) % checkboxes.length;
|
|
2849
|
+
(_e = checkboxes[nextIndex]) == null ? void 0 : _e.focus({ preventScroll: true });
|
|
2850
|
+
};
|
|
2851
|
+
return /* @__PURE__ */ jsx7(
|
|
2852
|
+
FieldFrame_default,
|
|
2853
|
+
{
|
|
2854
|
+
ref: containerRef,
|
|
2855
|
+
className: "multi-select-container",
|
|
2856
|
+
label,
|
|
2857
|
+
labelFor: triggerId,
|
|
2858
|
+
labelId: label ? labelId : void 0,
|
|
2859
|
+
invalid: Boolean(error),
|
|
2860
|
+
message: error,
|
|
2861
|
+
messageId: errorId,
|
|
2862
|
+
children: /* @__PURE__ */ jsxs7(
|
|
2863
|
+
"div",
|
|
2864
|
+
{
|
|
2865
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
2866
|
+
className: "relative mb-[4px] mt-4xs",
|
|
2867
|
+
children: [
|
|
2868
|
+
/* @__PURE__ */ jsxs7(
|
|
2869
|
+
"button",
|
|
2870
|
+
{
|
|
2871
|
+
type: "button",
|
|
2872
|
+
id: triggerId,
|
|
2873
|
+
ref: triggerRef,
|
|
2874
|
+
"aria-controls": groupId,
|
|
2875
|
+
"aria-expanded": isOpened,
|
|
2876
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
2877
|
+
"aria-labelledby": label ? labelId : void 0,
|
|
2878
|
+
"aria-label": label ? void 0 : "Selecionar op\xE7\xF5es",
|
|
2879
|
+
"aria-describedby": describedBy,
|
|
2880
|
+
disabled,
|
|
2881
|
+
onClick: () => setIsOpened((current) => !current),
|
|
2882
|
+
onKeyDown: (event) => {
|
|
2883
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
2884
|
+
event.preventDefault();
|
|
2885
|
+
setIsOpened(true);
|
|
2886
|
+
}
|
|
2887
|
+
if (event.key === "Escape") {
|
|
2888
|
+
event.preventDefault();
|
|
2889
|
+
setIsOpened(false);
|
|
2890
|
+
}
|
|
2891
|
+
},
|
|
2892
|
+
className: cs(
|
|
2893
|
+
"flex h-control-md w-full cursor-pointer items-center justify-between rounded-sm border border-field-border-default bg-field-surface px-3 text-field-icon focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring",
|
|
2894
|
+
error && "border-field-border-error text-field-assistive-error",
|
|
2895
|
+
!error && isOpened && "border-field-border-active text-field-content",
|
|
2896
|
+
!error && selectedCount > 0 && "text-field-content",
|
|
2897
|
+
disabled && "cursor-not-allowed border-field-border-default bg-field-surface-disabled text-field-content-disabled"
|
|
2898
|
+
),
|
|
2899
|
+
children: [
|
|
2900
|
+
/* @__PURE__ */ jsx7(
|
|
2901
|
+
"span",
|
|
2902
|
+
{
|
|
2903
|
+
className: cs(
|
|
2904
|
+
"min-w-0 flex-1 truncate text-left text-base font-normal text-field-placeholder",
|
|
2905
|
+
{
|
|
2906
|
+
"pr-12 text-field-content": !disabled && selectedCount > 0,
|
|
2907
|
+
"text-field-content-disabled": disabled
|
|
2908
|
+
}
|
|
2909
|
+
),
|
|
2910
|
+
children: "Selecione"
|
|
2911
|
+
}
|
|
2912
|
+
),
|
|
2913
|
+
/* @__PURE__ */ jsx7(
|
|
2914
|
+
MdKeyboardArrowDown,
|
|
2915
|
+
{
|
|
2916
|
+
"aria-hidden": "true",
|
|
2917
|
+
className: cs(
|
|
2918
|
+
"shrink-0 text-base text-field-icon transition-transform",
|
|
2919
|
+
{
|
|
2920
|
+
"rotate-180": isOpened,
|
|
2921
|
+
"text-field-assistive-error": error,
|
|
2922
|
+
"text-field-content": !error && (isOpened || selectedCount > 0),
|
|
2923
|
+
"text-field-content-disabled": disabled
|
|
2924
|
+
}
|
|
2925
|
+
)
|
|
2926
|
+
}
|
|
2927
|
+
)
|
|
2928
|
+
]
|
|
2929
|
+
}
|
|
2930
|
+
),
|
|
2931
|
+
/* @__PURE__ */ jsx7("span", { id: summaryId, className: "sr-only", children: selectedSummary }),
|
|
2932
|
+
isOpened && /* @__PURE__ */ jsx7(
|
|
2933
|
+
"div",
|
|
2934
|
+
{
|
|
2935
|
+
id: groupId,
|
|
2936
|
+
ref: groupRef,
|
|
2937
|
+
role: "group",
|
|
2938
|
+
"aria-labelledby": label ? labelId : void 0,
|
|
2939
|
+
"aria-label": label ? void 0 : "Op\xE7\xF5es dispon\xEDveis",
|
|
2940
|
+
"aria-describedby": summaryId,
|
|
2941
|
+
className: cs(
|
|
2942
|
+
"absolute top-[100%] w-full rounded-sm bg-surface-card p-3",
|
|
2943
|
+
menuLayerClass,
|
|
2944
|
+
"flex flex-col items-stretch gap-2 shadow-md"
|
|
2945
|
+
),
|
|
2946
|
+
children: options.map((option, index) => {
|
|
2947
|
+
const isChecked = checkedList.includes(option.value);
|
|
2948
|
+
return /* @__PURE__ */ jsxs7(
|
|
2949
|
+
"label",
|
|
2950
|
+
{
|
|
2951
|
+
className: cs(
|
|
2952
|
+
"flex h-10 cursor-pointer items-center gap-2 rounded p-2",
|
|
2953
|
+
isChecked && "bg-primary-5 text-primary-1",
|
|
2954
|
+
disabled && "cursor-not-allowed"
|
|
2955
|
+
),
|
|
2956
|
+
children: [
|
|
2957
|
+
/* @__PURE__ */ jsx7(
|
|
2958
|
+
"input",
|
|
2959
|
+
{
|
|
2960
|
+
id: `${baseId}-option-${index}`,
|
|
2961
|
+
type: "checkbox",
|
|
2962
|
+
className: "peer sr-only",
|
|
2963
|
+
value: option.value,
|
|
2964
|
+
checked: isChecked,
|
|
2965
|
+
name: props.name,
|
|
2966
|
+
onChange: props.onChange,
|
|
2967
|
+
onKeyDown: handleOptionKeyDown,
|
|
2968
|
+
"aria-invalid": Boolean(error) || void 0,
|
|
2969
|
+
"aria-describedby": error ? errorId : void 0,
|
|
2970
|
+
disabled
|
|
2971
|
+
}
|
|
2972
|
+
),
|
|
2973
|
+
/* @__PURE__ */ jsx7("span", { "aria-hidden": "true", className: "checkbox-control-proxy" }),
|
|
2974
|
+
option.label
|
|
2975
|
+
]
|
|
2976
|
+
},
|
|
2977
|
+
option.value
|
|
2978
|
+
);
|
|
2979
|
+
})
|
|
2980
|
+
}
|
|
2981
|
+
),
|
|
2982
|
+
selectedCount > 0 && onClear && /* @__PURE__ */ jsxs7(
|
|
2983
|
+
"button",
|
|
2984
|
+
{
|
|
2985
|
+
type: "button",
|
|
2986
|
+
"aria-label": `Limpar sele\xE7\xE3o de ${label != null ? label : "op\xE7\xF5es"}`,
|
|
2987
|
+
disabled,
|
|
2988
|
+
onClick: onClear,
|
|
2989
|
+
className: "absolute right-9 top-1/2 flex min-h-6 min-w-6 -translate-y-1/2 touch-manipulation items-center justify-center gap-1 rounded-full bg-action-primary px-2 text-xs text-action-primary-content focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring disabled:cursor-not-allowed",
|
|
2990
|
+
children: [
|
|
2991
|
+
/* @__PURE__ */ jsx7("span", { "aria-hidden": "true", children: selectedCount }),
|
|
2992
|
+
/* @__PURE__ */ jsx7(MdClose, { "aria-hidden": "true", size: 10 })
|
|
2993
|
+
]
|
|
2994
|
+
}
|
|
2995
|
+
)
|
|
2996
|
+
]
|
|
2997
|
+
}
|
|
2998
|
+
)
|
|
2999
|
+
}
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
var SelectMultiView_default = SelectMultiView;
|
|
3003
|
+
|
|
3004
|
+
// src/components/selectMulti/SelectMulti.tsx
|
|
3005
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
3006
|
+
function SelectMulti(props) {
|
|
3007
|
+
return /* @__PURE__ */ jsx8(
|
|
3008
|
+
SelectMultiView_default,
|
|
3009
|
+
__spreadProps(__spreadValues({}, props), {
|
|
3010
|
+
checkedList: props.value,
|
|
3011
|
+
onClear: props.onReset
|
|
3012
|
+
})
|
|
3013
|
+
);
|
|
3014
|
+
}
|
|
3015
|
+
var MultiSelect = SelectMulti;
|
|
3016
|
+
var SelectMulti_default = SelectMulti;
|
|
3017
|
+
|
|
3018
|
+
// src/components/selectCountry/SelectCountry.tsx
|
|
3019
|
+
import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
3020
|
+
function renderFlag2(option) {
|
|
3021
|
+
var _a;
|
|
3022
|
+
const svgSrc = String(
|
|
3023
|
+
getCountryFlagUrl(option.cca2) || ((_a = option.flags) == null ? void 0 : _a.svg) || ""
|
|
3024
|
+
).trim();
|
|
3025
|
+
if (!svgSrc) {
|
|
3026
|
+
return /* @__PURE__ */ jsx9(
|
|
3027
|
+
"span",
|
|
3028
|
+
{
|
|
3029
|
+
"aria-hidden": "true",
|
|
3030
|
+
className: "h-5 w-7 shrink-0 rounded-sm bg-surface-muted"
|
|
3031
|
+
}
|
|
3032
|
+
);
|
|
3033
|
+
}
|
|
3034
|
+
return /* @__PURE__ */ jsx9(
|
|
3035
|
+
"span",
|
|
3036
|
+
{
|
|
3037
|
+
"aria-hidden": "true",
|
|
3038
|
+
className: "flex h-5 w-7 shrink-0 items-center justify-center",
|
|
3039
|
+
children: /* @__PURE__ */ jsx9(
|
|
3040
|
+
"img",
|
|
3041
|
+
{
|
|
3042
|
+
src: svgSrc,
|
|
3043
|
+
alt: "",
|
|
3044
|
+
className: "h-full w-full object-contain",
|
|
3045
|
+
loading: "lazy",
|
|
3046
|
+
referrerPolicy: "no-referrer"
|
|
3047
|
+
}
|
|
3048
|
+
)
|
|
3049
|
+
}
|
|
3050
|
+
);
|
|
3051
|
+
}
|
|
3052
|
+
function renderCountryContent(option, placeholder) {
|
|
3053
|
+
if (!option) {
|
|
3054
|
+
return /* @__PURE__ */ jsx9("span", { className: "block w-full truncate overflow-hidden text-content-muted", children: placeholder });
|
|
3055
|
+
}
|
|
3056
|
+
return /* @__PURE__ */ jsxs8("span", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
3057
|
+
renderFlag2(option),
|
|
3058
|
+
/* @__PURE__ */ jsx9("span", { className: "block truncate overflow-hidden", children: option.label })
|
|
3059
|
+
] });
|
|
3060
|
+
}
|
|
3061
|
+
function SelectCountry(_a) {
|
|
3062
|
+
var _b = _a, {
|
|
3063
|
+
options,
|
|
3064
|
+
countryList,
|
|
3065
|
+
searchable = true,
|
|
3066
|
+
searchPlaceholder = "Busque um pa\xEDs",
|
|
3067
|
+
noOptionsText = "Nenhum pa\xEDs encontrado",
|
|
3068
|
+
defaultValue,
|
|
3069
|
+
onChange,
|
|
3070
|
+
className
|
|
3071
|
+
} = _b, props = __objRest(_b, [
|
|
3072
|
+
"options",
|
|
3073
|
+
"countryList",
|
|
3074
|
+
"searchable",
|
|
3075
|
+
"searchPlaceholder",
|
|
3076
|
+
"noOptionsText",
|
|
3077
|
+
"defaultValue",
|
|
3078
|
+
"onChange",
|
|
3079
|
+
"className"
|
|
3080
|
+
]);
|
|
3081
|
+
const availableOptions = filterCountryOptions(
|
|
3082
|
+
options || COUNTRY_OPTIONS,
|
|
3083
|
+
countryList
|
|
3084
|
+
);
|
|
3085
|
+
return /* @__PURE__ */ jsx9(
|
|
3086
|
+
InputSelect_default,
|
|
3087
|
+
__spreadProps(__spreadValues({}, props), {
|
|
3088
|
+
className,
|
|
3089
|
+
defaultValue,
|
|
3090
|
+
onChange,
|
|
3091
|
+
options: availableOptions,
|
|
3092
|
+
searchable,
|
|
3093
|
+
searchPlaceholder,
|
|
3094
|
+
noOptionsText,
|
|
3095
|
+
renderOption: (option) => renderCountryContent(option),
|
|
3096
|
+
renderValue: (option, placeholder) => renderCountryContent(option, placeholder)
|
|
3097
|
+
})
|
|
3098
|
+
);
|
|
3099
|
+
}
|
|
3100
|
+
var CountrySelect = SelectCountry;
|
|
3101
|
+
var SelectCountry_default = SelectCountry;
|
|
3102
|
+
|
|
3103
|
+
// src/components/radio-group/radio-group.tsx
|
|
3104
|
+
import { useField as useField5 } from "formik";
|
|
3105
|
+
import { useId as useId4 } from "react";
|
|
3106
|
+
import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
3107
|
+
function RadioGroup(_a) {
|
|
3108
|
+
var _b = _a, {
|
|
3109
|
+
name,
|
|
3110
|
+
label,
|
|
3111
|
+
options,
|
|
3112
|
+
className
|
|
3113
|
+
} = _b, rest = __objRest(_b, [
|
|
3114
|
+
"name",
|
|
3115
|
+
"label",
|
|
3116
|
+
"options",
|
|
3117
|
+
"className"
|
|
3118
|
+
]);
|
|
3119
|
+
const [field, meta] = useField5(name);
|
|
3120
|
+
const hasError = Boolean(meta.touched && meta.error);
|
|
3121
|
+
const errorId = `${useId4()}-error`;
|
|
3122
|
+
return /* @__PURE__ */ jsxs9(
|
|
3123
|
+
"fieldset",
|
|
3124
|
+
{
|
|
3125
|
+
className: `${FIELD_ROOT_CLASS} ${className != null ? className : ""}`,
|
|
3126
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
3127
|
+
"aria-invalid": hasError || void 0,
|
|
3128
|
+
children: [
|
|
3129
|
+
label && /* @__PURE__ */ jsx10("legend", { className: FIELD_LABEL_CLASS, children: label }),
|
|
3130
|
+
/* @__PURE__ */ jsx10("div", { className: "field-control-slot mt-4xs mb-[4px] flex min-h-control-md flex-wrap items-center gap-x-6 gap-y-2", children: options.map((option) => /* @__PURE__ */ jsxs9(
|
|
3131
|
+
"label",
|
|
3132
|
+
{
|
|
3133
|
+
className: "flex min-h-7 cursor-pointer items-center gap-2",
|
|
3134
|
+
children: [
|
|
3135
|
+
/* @__PURE__ */ jsx10(
|
|
3136
|
+
"input",
|
|
3137
|
+
__spreadProps(__spreadValues(__spreadValues({
|
|
3138
|
+
type: "radio"
|
|
3139
|
+
}, rest), field), {
|
|
3140
|
+
value: option.value,
|
|
3141
|
+
checked: field.value === option.value,
|
|
3142
|
+
"aria-describedby": hasError ? errorId : void 0,
|
|
3143
|
+
"data-invalid": hasError || void 0,
|
|
3144
|
+
className: "radio-control"
|
|
3145
|
+
})
|
|
3146
|
+
),
|
|
3147
|
+
/* @__PURE__ */ jsx10("span", { className: "text-content-secondary", children: option.label })
|
|
3148
|
+
]
|
|
3149
|
+
},
|
|
3150
|
+
option.value
|
|
3151
|
+
)) }),
|
|
3152
|
+
hasError && /* @__PURE__ */ jsx10(
|
|
3153
|
+
"span",
|
|
3154
|
+
{
|
|
3155
|
+
id: errorId,
|
|
3156
|
+
role: "alert",
|
|
3157
|
+
"aria-live": "polite",
|
|
3158
|
+
className: FIELD_MESSAGE_CLASS,
|
|
3159
|
+
children: meta.error
|
|
3160
|
+
}
|
|
3161
|
+
)
|
|
3162
|
+
]
|
|
3163
|
+
}
|
|
3164
|
+
);
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
// src/components/radioCardGroup/RadioCardGroup.tsx
|
|
3168
|
+
import classNames7 from "classnames";
|
|
3169
|
+
import { FormikContext as FormikContext2, getIn as getIn2 } from "formik";
|
|
3170
|
+
import {
|
|
3171
|
+
useContext as useContext2,
|
|
3172
|
+
useId as useId5,
|
|
3173
|
+
useMemo as useMemo3,
|
|
3174
|
+
useState as useState6
|
|
3175
|
+
} from "react";
|
|
3176
|
+
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
3177
|
+
var isFormikContext = (context) => Boolean(context && typeof context.setFieldValue === "function");
|
|
3178
|
+
function RadioCardGroup({
|
|
3179
|
+
name,
|
|
3180
|
+
label,
|
|
3181
|
+
options,
|
|
3182
|
+
value,
|
|
3183
|
+
defaultValue = "",
|
|
3184
|
+
onChange,
|
|
3185
|
+
error,
|
|
3186
|
+
touched,
|
|
3187
|
+
className,
|
|
3188
|
+
optionClassName,
|
|
3189
|
+
columnsClassName,
|
|
3190
|
+
disabled = false
|
|
3191
|
+
}) {
|
|
3192
|
+
const formikContext = useContext2(
|
|
3193
|
+
FormikContext2
|
|
3194
|
+
);
|
|
3195
|
+
const generatedName = useId5();
|
|
3196
|
+
const errorId = `${generatedName}-error`;
|
|
3197
|
+
const [internalValue, setInternalValue] = useState6(defaultValue);
|
|
3198
|
+
const hasFormikBinding = Boolean(name) && isFormikContext(formikContext);
|
|
3199
|
+
const fieldName = name != null ? name : generatedName;
|
|
3200
|
+
const fieldValue = useMemo3(() => {
|
|
3201
|
+
var _a;
|
|
3202
|
+
if (hasFormikBinding && name) {
|
|
3203
|
+
return String((_a = getIn2(formikContext.values, name)) != null ? _a : "");
|
|
3204
|
+
}
|
|
3205
|
+
if (value !== void 0) {
|
|
3206
|
+
return value;
|
|
3207
|
+
}
|
|
3208
|
+
return internalValue;
|
|
3209
|
+
}, [formikContext == null ? void 0 : formikContext.values, hasFormikBinding, internalValue, name, value]);
|
|
3210
|
+
const fieldTouched = hasFormikBinding && name ? Boolean(getIn2(formikContext.touched, name)) : Boolean(touched);
|
|
3211
|
+
const fieldError = hasFormikBinding && name ? getIn2(formikContext.errors, name) : error;
|
|
3212
|
+
const hasError = Boolean(fieldTouched && fieldError);
|
|
3213
|
+
const helperText = typeof fieldError === "string" && hasError ? fieldError : void 0;
|
|
3214
|
+
const handleChange = (nextValue, event) => {
|
|
3215
|
+
if (hasFormikBinding && name) {
|
|
3216
|
+
formikContext.setFieldValue(name, nextValue);
|
|
3217
|
+
formikContext.setFieldTouched(name, true, false);
|
|
3218
|
+
} else if (value === void 0) {
|
|
3219
|
+
setInternalValue(nextValue);
|
|
3220
|
+
}
|
|
3221
|
+
onChange == null ? void 0 : onChange(nextValue, event);
|
|
3222
|
+
};
|
|
3223
|
+
return /* @__PURE__ */ jsxs10(
|
|
3224
|
+
"fieldset",
|
|
3225
|
+
{
|
|
3226
|
+
className: classNames7("flex min-w-0 flex-col", className),
|
|
3227
|
+
"aria-describedby": helperText ? errorId : void 0,
|
|
3228
|
+
"aria-invalid": hasError || void 0,
|
|
3229
|
+
children: [
|
|
3230
|
+
label && /* @__PURE__ */ jsx11("legend", { className: "mb-2 px-0.5 text-[16px] tracking-wide", children: label }),
|
|
3231
|
+
/* @__PURE__ */ jsx11("div", { className: classNames7("grid gap-3", columnsClassName), children: options.map((option) => {
|
|
3232
|
+
const optionId = `${fieldName}-${option.value}`;
|
|
3233
|
+
const checked = fieldValue === option.value;
|
|
3234
|
+
const optionDisabled = disabled || Boolean(option.disabled);
|
|
3235
|
+
return /* @__PURE__ */ jsx11(
|
|
3236
|
+
"label",
|
|
3237
|
+
{
|
|
3238
|
+
htmlFor: optionId,
|
|
3239
|
+
className: classNames7(
|
|
3240
|
+
"block rounded-md border p-4 transition-colors",
|
|
3241
|
+
checked ? "border-primary-1 bg-primary-5" : "border-transparent bg-bg-light",
|
|
3242
|
+
hasError && !checked ? "outline outline-1 outline-feedback-danger-border" : "outline outline-1 outline-transparent",
|
|
3243
|
+
optionDisabled ? "cursor-not-allowed opacity-60" : "cursor-pointer",
|
|
3244
|
+
optionClassName
|
|
3245
|
+
),
|
|
3246
|
+
children: /* @__PURE__ */ jsxs10("div", { className: "flex items-start gap-3", children: [
|
|
3247
|
+
/* @__PURE__ */ jsx11(
|
|
3248
|
+
"input",
|
|
3249
|
+
{
|
|
3250
|
+
id: optionId,
|
|
3251
|
+
type: "radio",
|
|
3252
|
+
name: fieldName,
|
|
3253
|
+
value: option.value,
|
|
3254
|
+
checked,
|
|
3255
|
+
disabled: optionDisabled,
|
|
3256
|
+
onChange: (event) => handleChange(option.value, event),
|
|
3257
|
+
onBlur: () => {
|
|
3258
|
+
if (hasFormikBinding && name) {
|
|
3259
|
+
formikContext.setFieldTouched(name, true, false);
|
|
3260
|
+
}
|
|
3261
|
+
},
|
|
3262
|
+
"aria-describedby": helperText ? errorId : void 0,
|
|
3263
|
+
className: "radio-control mt-0.5"
|
|
3264
|
+
}
|
|
3265
|
+
),
|
|
3266
|
+
/* @__PURE__ */ jsxs10("div", { className: "min-w-0 flex-1", children: [
|
|
3267
|
+
/* @__PURE__ */ jsx11("div", { className: "font-bold text-content-primary", children: option.title }),
|
|
3268
|
+
option.description && /* @__PURE__ */ jsx11("div", { className: "mt-1 text-content-primary", children: option.description })
|
|
3269
|
+
] })
|
|
3270
|
+
] })
|
|
3271
|
+
},
|
|
3272
|
+
option.value
|
|
3273
|
+
);
|
|
3274
|
+
}) }),
|
|
3275
|
+
helperText && /* @__PURE__ */ jsx11(
|
|
3276
|
+
"span",
|
|
3277
|
+
{
|
|
3278
|
+
id: errorId,
|
|
3279
|
+
role: "alert",
|
|
3280
|
+
"aria-live": "assertive",
|
|
3281
|
+
className: "mt-1 text-xs tracking-wide text-feedback-danger-content",
|
|
3282
|
+
children: helperText
|
|
3283
|
+
}
|
|
3284
|
+
)
|
|
3285
|
+
]
|
|
3286
|
+
}
|
|
3287
|
+
);
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
export {
|
|
3291
|
+
Input_default,
|
|
3292
|
+
InputStandalone,
|
|
3293
|
+
InputSelect_default,
|
|
3294
|
+
TextArea_default,
|
|
3295
|
+
buildPhonePayload,
|
|
3296
|
+
parsePhonePayload,
|
|
3297
|
+
PhoneInput,
|
|
3298
|
+
InputPhone_default,
|
|
3299
|
+
Datepicker,
|
|
3300
|
+
datePicker_default,
|
|
3301
|
+
MultiSelect,
|
|
3302
|
+
SelectMulti_default,
|
|
3303
|
+
CountrySelect,
|
|
3304
|
+
SelectCountry_default,
|
|
3305
|
+
RadioGroup,
|
|
3306
|
+
RadioCardGroup
|
|
3307
|
+
};
|
|
3308
|
+
//# sourceMappingURL=chunk-BY4HJZFJ.js.map
|