mitre-form-component 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1084 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ MitreFormComponent: () => Form_default
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/components/Form/index.tsx
39
+ var import_react5 = __toESM(require("react"));
40
+
41
+ // src/components/hooks/useError.ts
42
+ var import_react = require("react");
43
+ function useError() {
44
+ const [error, setError] = (0, import_react.useState)(null);
45
+ const handleError = (err) => {
46
+ const errorObj = err instanceof Error ? err : new Error(String(err));
47
+ setError(errorObj);
48
+ console.error(errorObj);
49
+ };
50
+ const clearError = () => setError(null);
51
+ return { error, handleError, clearError };
52
+ }
53
+
54
+ // src/components/Form/index.tsx
55
+ var import_react_hook_form = require("react-hook-form");
56
+ var import_yup = require("@hookform/resolvers/yup");
57
+ var yup = __toESM(require("yup"));
58
+
59
+ // src/components/styles/utils.ts
60
+ function flex(direction = "row", alignItems, justifyContent) {
61
+ return `
62
+ align-items:${alignItems || null};
63
+ display:flex;
64
+ flex-direction:${direction};
65
+ justify-content:${justifyContent || null};
66
+ `;
67
+ }
68
+ var opacityEffect = `
69
+ &:hover {
70
+ cursor:pointer;
71
+ opacity:.9;
72
+ }
73
+
74
+ &:active {
75
+ opacity:.7;
76
+ }
77
+ `;
78
+
79
+ // src/components/Form/styles.ts
80
+ var import_styled_components = __toESM(require("styled-components"));
81
+ var FormContainer = import_styled_components.default.div`
82
+ ${flex("column")}
83
+ align-items: stretch;
84
+ justify-content: flex-start;
85
+ overflow-x: hidden;
86
+ overflow-y: auto;
87
+
88
+ /* Hide scrollbars for WebKit browsers */
89
+ ::-webkit-scrollbar {
90
+ display: none;
91
+ }
92
+
93
+ /* Hide scrollbars for Firefox */
94
+ scrollbar-width: none;
95
+
96
+ box-sizing: border-box;
97
+ `;
98
+ var HeaderContainer = import_styled_components.default.div`
99
+ margin-bottom: 1rem;
100
+ `;
101
+ var ButtonContainer = import_styled_components.default.div`
102
+ display: flex;
103
+ flex-direction: column;
104
+ align-items: center;
105
+ justify-content: center;
106
+ width: 100%;
107
+ margin-top: 0.75rem;
108
+ `;
109
+ var Form = import_styled_components.default.form`
110
+ label {
111
+ font-weight: 700;
112
+ }
113
+
114
+ input {
115
+ background: white;
116
+ margin-bottom: 0.75rem;
117
+ }
118
+
119
+ p {
120
+ font-family: "Montserrat", sans-serif;
121
+ font-style: italic;
122
+ font-weight: 200;
123
+ font-size: 0.8rem;
124
+ color: ${(props) => props.$textColor || "var(--black)"};
125
+ text-align: start;
126
+ }
127
+
128
+ a {
129
+ font-family: "Montserrat", sans-serif;
130
+ font-style: italic;
131
+ font-weight: 200;
132
+ font-size: 0.8rem;
133
+ color: ${(props) => props.$textColor || "var(--black)"};
134
+ }
135
+
136
+ h6 {
137
+ text-align: start;
138
+ margin-left: 10px;
139
+ color: ${(props) => props.$textColor || "var(--black)"};
140
+ }
141
+
142
+ & > div {
143
+ margin-bottom: 10px;,
144
+ }
145
+
146
+ button {
147
+ ${opacityEffect}
148
+ color: var(--black);
149
+ font-weight: 600;
150
+ border: none;
151
+ border-radius: 8px;
152
+ width: 60%;
153
+ margin-top: 10px;
154
+ margin-bottom: 10px;
155
+ }
156
+ `;
157
+ var Title = import_styled_components.default.h2`
158
+ font-size: 1.25rem;
159
+ font-weight: 700;
160
+ line-height: 24px;
161
+ letter-spacing: 0em;
162
+ color: ${(props) => props.$textColor || "var(--black)"};
163
+ `;
164
+ var Text = import_styled_components.default.p`
165
+ font-size: 1rem;
166
+ font-weight: 400;
167
+ line-height: 23px;
168
+ letter-spacing: 0em;
169
+ margin-top: 10px;
170
+ color: ${(props) => props.$textColor || "var(--black)"};
171
+ `;
172
+
173
+ // src/components/styles/global.ts
174
+ var import_styled_components2 = require("styled-components");
175
+ var import_react2 = require("react");
176
+ var GlobalStyles = import_styled_components2.createGlobalStyle`
177
+ :root {
178
+ --red: #e52e4d;
179
+ --white: #FFF;
180
+ --black: #2F2F2F;
181
+ --black-2:#1E1E1E;
182
+ --alphaBlack: #000000;
183
+ --black-2:#1E1E1E;
184
+ --black-3:#353535;
185
+
186
+ --yellow-400:#FFD789;
187
+ --yellow-500: #F6C76B;
188
+ --gray-40:#F0F0F0;
189
+ --gray-45:#767676;
190
+ --gray-50: #686A69;
191
+ --gray-60: #8F8F8F;
192
+ --gray-100: #B6B6B6;
193
+ --gray-150: #B9B9B9;
194
+ --gray-200: #D2D2D2;
195
+ --gray-300: #EBEBEB;
196
+ --gray-400: #ECECEC;
197
+ --gray-500: #F4F4F4;
198
+ --gray-550:#6F6F6F;
199
+ --gray-600:#686868;
200
+ --gray-700: #535353;
201
+ --gray-800:#9D9D9D;
202
+ --shadow-500: 0px 4px 8px rgba(91, 91, 91, 0.2);
203
+ --green:#57C06E;
204
+ --green-2:#2DCE68;
205
+ --blue:#007BFF;
206
+ }
207
+
208
+ * {
209
+ margin: 0;
210
+ padding: 0;
211
+ box-sizing: border-box;
212
+ }
213
+
214
+ html {
215
+ scroll-behavior: smooth;
216
+
217
+ @media (max-width: 1080px) {
218
+ font-size: 93.75%;
219
+ }
220
+ @media (max-width: 720px) {
221
+ font-size: 87.5%;
222
+ }
223
+ }
224
+
225
+ body {
226
+ background: var(--white);
227
+ -webkit-font-smoothing: antialiased;
228
+ }
229
+
230
+ body, input, textarea, select, button {
231
+ font-family: "Montserrat", sans-serif;
232
+ font-weight: 400;
233
+ }
234
+
235
+ h1, h2, h3, h4, h5, h6, strong {
236
+ font-weight: 600;
237
+ }
238
+
239
+ button {
240
+ cursor: pointer;
241
+ }
242
+
243
+ [disabled] {
244
+ opacity: 0.6;
245
+ cursor: not-allowed;
246
+ }
247
+
248
+ .hidden {
249
+ overflow: hidden;
250
+ }
251
+
252
+ ::-webkit-scrollbar {
253
+ -webkit-appearance: none;
254
+ background: var(--gray-500);
255
+ width: 6px;
256
+ height: 10px;
257
+ }
258
+
259
+ ::-webkit-scrollbar-thumb {
260
+ background-color: var(--gray-50);
261
+ }
262
+
263
+ .aligncenter {
264
+ text-align: center;
265
+ }
266
+
267
+ .width-190px {
268
+ width:190px;
269
+ }
270
+
271
+ .hidden-content {
272
+ display:none !important;
273
+ }
274
+
275
+ .global-margin-bottom {
276
+ margin-bottom:20px;
277
+ }
278
+
279
+ .background-light-gray {
280
+ background:#F4F4F4;
281
+ }
282
+
283
+ .full-width-and-height {
284
+ height:100%;
285
+ width:100%;
286
+ }
287
+
288
+ .flex-direction-column {
289
+ flex-direction:column;
290
+ }
291
+
292
+ .bold {
293
+ font-weight:700;
294
+ }
295
+
296
+ .margin-center-x {
297
+ margin:0 auto;
298
+ }
299
+
300
+ .border-none {
301
+ border:none;
302
+ }
303
+
304
+ .text-center {
305
+ text-align:center;
306
+ }
307
+
308
+ .relative {
309
+ position:relative;
310
+ }
311
+
312
+ /* accessibility */
313
+ body ._access-menu p._text-center{
314
+ font-family: "Montserrat", sans-serif;
315
+ font-style: italic;
316
+ font-size: 1.2rem!important;
317
+ margin-top: 6px;
318
+ margin-bottom: 3px;
319
+ }
320
+
321
+ `;
322
+ var FontLoader = () => {
323
+ (0, import_react2.useEffect)(() => {
324
+ const link = document.createElement("link");
325
+ link.href = "https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap";
326
+ link.rel = "stylesheet";
327
+ document.head.appendChild(link);
328
+ }, []);
329
+ return null;
330
+ };
331
+ var global_default = FontLoader;
332
+
333
+ // src/components/Input/index.tsx
334
+ var import_react3 = require("react");
335
+
336
+ // src/components/Input/masks.ts
337
+ function cep(e) {
338
+ e.currentTarget.maxLength = 9;
339
+ let value = e.currentTarget.value;
340
+ value = value.replace(/\D/g, "");
341
+ value = value.replace(/^(\d{5})(\d)/, "$1-$2");
342
+ e.currentTarget.value = value;
343
+ return e;
344
+ }
345
+ function currency(e) {
346
+ let value = e.currentTarget.value;
347
+ value = value.replace(/\D/g, "");
348
+ value = value.replace(/(\d)(\d{2})$/, "$1,$2");
349
+ value = value.replace(/(?=(\d{3})+(\D))\B/g, ".");
350
+ e.currentTarget.value = value;
351
+ return e;
352
+ }
353
+ function cpf(e) {
354
+ e.currentTarget.maxLength = 14;
355
+ let value = e.currentTarget.value;
356
+ if (!value.match(/^(\d{3}).(\d{3}).(\d{3})-(\d{2})$/)) {
357
+ value = value.replace(/\D/g, "");
358
+ value = value.replace(/(\d{3})(\d)/, "$1.$2");
359
+ value = value.replace(/(\d{3})(\d)/, "$1.$2");
360
+ value = value.replace(/(\d{3})(\d{2})$/, "$1-$2");
361
+ e.currentTarget.value = value;
362
+ }
363
+ return e;
364
+ }
365
+ function date(e) {
366
+ let value = e.currentTarget.value;
367
+ value = value.replace(/\D/g, "");
368
+ value = value.replace(/(\d{2})(\d)/, "$1/$2");
369
+ value = value.replace(/(\d{2})(\d)/, "$1/$2");
370
+ e.currentTarget.value = value;
371
+ return e;
372
+ }
373
+
374
+ // src/components/Input/index.tsx
375
+ var import_style = require("react-phone-input-2/lib/style.css");
376
+
377
+ // src/components/Input/styles.ts
378
+ var import_styled_components3 = __toESM(require("styled-components"));
379
+ var import_react_phone_input_2 = __toESM(require("react-phone-input-2"));
380
+ var FormLabel = import_styled_components3.default.label`
381
+ font-family: "Montserrat", sans-serif;
382
+ font-style: normal;
383
+ font-weight: 500;
384
+ font-size: 1rem;
385
+ color: ${(props) => props.isInvalid ? "var(--red)" : props.$textColor || "var(--black)"};
386
+ display: block;
387
+ margin-bottom: 0.5rem;
388
+ text-align: left;
389
+ `;
390
+ var Input = import_styled_components3.default.input`
391
+ font-family: "Montserrat", sans-serif;
392
+ font-style: normal;
393
+ font-weight: 500;
394
+ font-size: 1rem;
395
+ line-height: 1.5rem;
396
+ background: var(--gray-500);
397
+ color: var(--black);
398
+ padding: 0.5rem;
399
+ border-radius: 0.125rem;
400
+ border: 1px solid transparent;
401
+ display: block;
402
+ height: 3.125rem;
403
+ width: 100%;
404
+
405
+ &:focus {
406
+ border-radius: 0.125rem;
407
+ border: 2px solid ${(props) => props.$bordercolor || "var(--yellow-500)"};
408
+ outline: none;
409
+ }
410
+
411
+ &::placeholder {
412
+ font-size: 1rem;
413
+ line-height: 1.5rem;
414
+ color: #b6b6b6;
415
+ font-weight: 800;
416
+ }
417
+
418
+ /* Autofill styles */
419
+ &:-webkit-autofill {
420
+ background: var(--gray-500) !important;
421
+ color: var(--black) !important;
422
+ -webkit-text-fill-color: var(--black) !important;
423
+ transition: background-color 5000s ease-in-out 0s; /* Prevent flashing */
424
+ }
425
+
426
+ &:-webkit-autofill::first-line {
427
+ font-family: "Montserrat", sans-serif;
428
+ font-size: 1rem;
429
+ font-weight: 500;
430
+ }
431
+ `;
432
+ var FormPhoneInput = (0, import_styled_components3.default)(import_react_phone_input_2.default)`
433
+ .form-control {
434
+ background: white;
435
+ color: ${(props) => props.isInvalid ? "var(--red)" : props.$textColor || "var(--black)"};
436
+ padding: 0.5rem;
437
+ border-radius: 0.125rem;
438
+ border: 1px solid transparent;
439
+ height: 3.125rem;
440
+ width: 100%;
441
+ padding-left: 4rem;
442
+ font-family: "Montserrat", sans-serif;
443
+ font-style: normal;
444
+ font-weight: 500;
445
+ font-size: 1rem;
446
+ line-height: 1.5rem;
447
+ text &:focus,
448
+ &:focus-within {
449
+ border-radius: 0.125rem;
450
+ border: 2px solid
451
+ ${(props) => !props.isValid ? "var(--red)" : props.$bordercolor || "var(--yellow-500)"};
452
+ }
453
+
454
+ &::placeholder {
455
+ font-size: 1rem;
456
+ line-height: 1.5rem;
457
+ color: #b6b6b6;
458
+ font-weight: 800;
459
+ }
460
+
461
+ /* Autofill styles */
462
+ &:-webkit-autofill {
463
+ background: var(--gray-500) !important;
464
+ color: var(--black) !important;
465
+ -webkit-text-fill-color: var(--black) !important;
466
+ transition: background-color 5000s ease-in-out 0s; /* Prevent flashing */
467
+ }
468
+
469
+ &:-webkit-autofill::first-line {
470
+ font-family: "Montserrat", sans-serif;
471
+ font-size: 1rem;
472
+ font-weight: 500;
473
+ }
474
+ }
475
+
476
+ &:focus-within {
477
+ .form-control {
478
+ border: 2px solid
479
+ ${(props) => props.isInvalid ? "var(--red)" : props.$bordercolor || "var(--yellow-500)"};
480
+ }
481
+ }
482
+
483
+ .flag-dropdown {
484
+ background: white;
485
+ border: none;
486
+ padding: 0.5rem;
487
+ margin: 0.25rem;
488
+ cursor: pointer;
489
+
490
+ &:focus-within {
491
+ outline: none;
492
+ }
493
+ }
494
+ `;
495
+ var FormErrorMessage = import_styled_components3.default.small`
496
+ font-size: 0.75rem;
497
+ line-height: 1.125rem;
498
+ color: var(--red);
499
+ margin-top: 0.25rem;
500
+ display: block;
501
+ `;
502
+ var FormControl = import_styled_components3.default.div.withConfig({
503
+ shouldForwardProp: (prop) => !["isInvalid", "$bordercolor"].includes(prop)
504
+ })`
505
+ ${FormLabel} {
506
+ ${(props) => props.isInvalid && import_styled_components3.css`
507
+ color: var(--red);
508
+ `};
509
+ }
510
+
511
+ ${Input} {
512
+ ${(props) => props.isInvalid && import_styled_components3.css`
513
+ border: 1px solid var(--red);
514
+
515
+ &:not(:focus)::placeholder {
516
+ color: var(--red);
517
+ font-weight: 600;
518
+ }
519
+ `};
520
+
521
+ &:focus {
522
+ ${(props) => props.isInvalid && import_styled_components3.css`
523
+ border: 1px solid var(--red);
524
+ `};
525
+ }
526
+ }
527
+
528
+ ${FormPhoneInput} {
529
+ ${(props) => props.isInvalid && import_styled_components3.css`
530
+ border: 1px solid var(--red);
531
+
532
+ &:not(:focus)::placeholder {
533
+ color: var(--red);
534
+ font-weight: 600;
535
+ }
536
+ `};
537
+
538
+ &:focus {
539
+ ${(props) => props.isInvalid && import_styled_components3.css`
540
+ border: 1px solid var(--red);
541
+ `};
542
+ }
543
+ }
544
+ `;
545
+
546
+ // src/components/Input/index.tsx
547
+ var import_jsx_runtime = require("react/jsx-runtime");
548
+ var InputBase = ({ id, label, error, showErrorMessage = true, borderColor, textColor, mask = "", type = "text", ...rest }, ref) => {
549
+ const phoneInputRef = (0, import_react3.useRef)(null);
550
+ const { onChange, name } = rest;
551
+ const handleKeyUp = (0, import_react3.useCallback)(
552
+ (e) => {
553
+ if (mask === "cep") cep(e);
554
+ if (mask === "currency") currency(e);
555
+ if (mask === "cpf") cpf(e);
556
+ if (mask === "date") date(e);
557
+ },
558
+ [mask]
559
+ );
560
+ const handlePhoneChange = (0, import_react3.useCallback)((value) => {
561
+ onChange?.({ target: { value, name } });
562
+ if (phoneInputRef.current?.input) {
563
+ phoneInputRef.current.input.value = value;
564
+ }
565
+ }, [onChange, name]);
566
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(FormControl, { isInvalid: !!error, children: [
567
+ !!label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormLabel, { htmlFor: id, $textColor: textColor, children: label }),
568
+ !mask ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
569
+ Input,
570
+ {
571
+ id,
572
+ ref,
573
+ type,
574
+ $bordercolor: borderColor,
575
+ "aria-invalid": !!error && showErrorMessage ? "true" : "false",
576
+ autoComplete: rest.autoComplete || "on",
577
+ ...rest
578
+ }
579
+ ) : mask === "phone" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
580
+ FormPhoneInput,
581
+ {
582
+ country: "br",
583
+ $bordercolor: borderColor,
584
+ placeholder: rest.placeholder,
585
+ "aria-invalid": !!error && showErrorMessage ? "true" : "false",
586
+ isInvalid: !!error,
587
+ onChange: handlePhoneChange,
588
+ masks: {
589
+ br: "(..) .....-...."
590
+ },
591
+ inputProps: {
592
+ id,
593
+ name: "phone",
594
+ required: true,
595
+ autoFocus: true,
596
+ autoComplete: "tel",
597
+ ref: phoneInputRef
598
+ },
599
+ dropdownStyle: {
600
+ color: textColor
601
+ },
602
+ disableCountryGuess: true,
603
+ disableCountryCode: true,
604
+ value: rest.value
605
+ }
606
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
607
+ Input,
608
+ {
609
+ id,
610
+ ref,
611
+ type,
612
+ $bordercolor: borderColor,
613
+ "aria-invalid": !!error && showErrorMessage ? "true" : "false",
614
+ onKeyUp: handleKeyUp,
615
+ autoComplete: rest.autoComplete || "on",
616
+ ...rest
617
+ }
618
+ ),
619
+ !!error && showErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormErrorMessage, { "data-testid": "error-message", children: typeof error === "string" ? error : error.message })
620
+ ] });
621
+ };
622
+ var Input2 = (0, import_react3.forwardRef)(InputBase);
623
+
624
+ // src/components/Button/styles.ts
625
+ var import_polished = require("polished");
626
+ var import_styled_components4 = __toESM(require("styled-components"));
627
+ var Icon = import_styled_components4.default.span`
628
+ font-size: 0;
629
+ line-height: 0;
630
+ transition: all 0.25s ease;
631
+
632
+ transform: translate3d(-30px, 0px, 0px);
633
+ visibility: hidden;
634
+ opacity: 0;
635
+ margin-right: 0.625rem;
636
+ `;
637
+ var Text2 = import_styled_components4.default.span`
638
+ font-family: "Montserrat", sans-serif;
639
+ font-size: 1rem;
640
+ line-height: 1.5rem;
641
+ margin-bottom: -2px;
642
+
643
+ transition: all 0.25s ease;
644
+ `;
645
+ var TextSubmitting = import_styled_components4.default.span`
646
+ font-family: "Montserrat", sans-serif;
647
+ font-weight: 400;
648
+ font-size: 1rem;
649
+
650
+ transition: all 0.25s ease;
651
+ `;
652
+ var LoadingIcon = import_styled_components4.default.span.withConfig({
653
+ shouldForwardProp: (prop) => prop !== "hasText"
654
+ })`
655
+ display: block;
656
+
657
+ width: 1rem;
658
+ height: 1rem;
659
+ border: 0.125rem solid var(--white);
660
+ border-radius: 50%;
661
+ animation: loadingAnimation 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
662
+ border-color: var(--white) transparent transparent transparent;
663
+
664
+ margin-right: ${(props) => props.hasText ? "0.625rem" : "0"};
665
+
666
+ @keyframes loadingAnimation {
667
+ 0% {
668
+ transform: rotate(0deg);
669
+ }
670
+ 100% {
671
+ transform: rotate(360deg);
672
+ }
673
+ }
674
+ `;
675
+ var Button = import_styled_components4.default.button.withConfig({
676
+ shouldForwardProp: (prop) => ![
677
+ "hasIcon",
678
+ "isSubmitting",
679
+ "hasSubmittingMessage",
680
+ "bgColor",
681
+ "bordercolor",
682
+ "color",
683
+ "height"
684
+ ].includes(prop)
685
+ })`
686
+ background: ${(props) => (0, import_polished.darken)(0.1, props?.bgColor || "#F6C76B")};
687
+ color: ${(props) => props?.color || "#2F2F2F"};
688
+ border: 1px solid ${(props) => (0, import_polished.darken)(0.1, props?.bordercolor || "#F6C76B")};
689
+ border-radius: 2px;
690
+
691
+ display: inline-flex;
692
+ align-items: center;
693
+ justify-content: center;
694
+ padding: 0 0.75rem;
695
+ height: ${(props) => props?.height || "3.125rem"};
696
+ position: relative;
697
+ font-size: 0;
698
+ line-height: 0;
699
+
700
+ transition: all 0.25s;
701
+
702
+ ${Icon} {
703
+ display: ${(props) => props?.hasIcon ? "block" : ""};
704
+ }
705
+
706
+ ${Text2} {
707
+ transform: ${(props) => props?.hasIcon ? "translate3d(-4.5px, 0px, 0px)" : "unset"};
708
+
709
+ @media print, screen and (min-width: 40em) {
710
+ transform: ${(props) => props?.hasIcon ? "translate3d(-14.5px, 0px, 0px)" : "unset"};
711
+ }
712
+
713
+ color: ${(props) => props?.color || "#2F2F2F"};
714
+ }
715
+
716
+ &:hover {
717
+ background: ${(props) => (0, import_polished.darken)(0.2, props?.bgColor || "#F6C76B")};
718
+ border-color: ${(props) => (0, import_polished.darken)(0.2, props?.bordercolor || "#F6C76B")};
719
+
720
+ ${Icon} {
721
+ opacity: 1;
722
+ visibility: visible;
723
+ transform: translate3d(0px, 0px, 0px);
724
+ }
725
+
726
+ ${Text2} {
727
+ transform: ${(props) => props?.hasIcon ? "translate3d(-5px, 0px, 0px)" : "unset"};
728
+ }
729
+ }
730
+
731
+ ${Text2} {
732
+ ${(props) => props.isSubmitting && !props.hasSubmittingMessage && import_styled_components4.css`
733
+ transform: unset;
734
+ opacity: 0;
735
+ `}
736
+ }
737
+
738
+ ${LoadingIcon} {
739
+ ${(props) => props.isSubmitting && !props.hasSubmittingMessage && import_styled_components4.css`
740
+ display: flex;
741
+ -webkit-box-align: center;
742
+ align-items: center;
743
+ position: absolute;
744
+ `}
745
+ }
746
+ `;
747
+
748
+ // src/components/Button/index.tsx
749
+ var import_jsx_runtime2 = require("react/jsx-runtime");
750
+ function Button2({
751
+ children,
752
+ icon,
753
+ isSubmitting = false,
754
+ submittingMessage = "",
755
+ disabled = false,
756
+ color = "#2F2F2F",
757
+ ...rest
758
+ }) {
759
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
760
+ Button,
761
+ {
762
+ isSubmitting,
763
+ hasSubmittingMessage: submittingMessage.length > 0,
764
+ disabled: isSubmitting || disabled,
765
+ "aria-disabled": isSubmitting || disabled,
766
+ hasIcon: !!icon,
767
+ color,
768
+ ...rest,
769
+ children: [
770
+ icon && !isSubmitting && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { "data-testid": "button-icon", children: icon }),
771
+ isSubmitting && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LoadingIcon, { hasText: submittingMessage.length > 0 }),
772
+ (!isSubmitting || submittingMessage.length === 0) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text2, { className: "text", children }),
773
+ isSubmitting && submittingMessage.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TextSubmitting, { children: submittingMessage })
774
+ ]
775
+ }
776
+ );
777
+ }
778
+
779
+ // src/components/Alert/index.tsx
780
+ var import_react4 = require("react");
781
+
782
+ // src/components/Alert/styles.ts
783
+ var import_styled_components5 = __toESM(require("styled-components"));
784
+ var fadeIn = import_styled_components5.keyframes`
785
+ from { opacity: 0; transform: translateY(-10px); }
786
+ to { opacity: 1; transform: translateY(0); }
787
+ `;
788
+ var fadeOut = import_styled_components5.keyframes`
789
+ from { opacity: 1; transform: translateY(0); }
790
+ to { opacity: 0; transform: translateY(-10px); }
791
+ `;
792
+ var typeStyles = {
793
+ error: import_styled_components5.css`
794
+ background-color: var(--red);
795
+ border: 1px solid var(--red);
796
+ color: var(--white);
797
+ svg {
798
+ color: var(--white);
799
+ }
800
+ `,
801
+ warning: import_styled_components5.css`
802
+ background-color: var(--yellow-500);
803
+ border: 1px solid var(--yellow-400);
804
+ color: var(--black);
805
+ svg {
806
+ color: var(--black);
807
+ }
808
+ `,
809
+ info: import_styled_components5.css`
810
+ background-color: var(--blue);
811
+ border: 1px solid var(--blue);
812
+ color: var(--white);
813
+ svg {
814
+ color: var(--white);
815
+ }
816
+ `,
817
+ success: import_styled_components5.css`
818
+ background-color: var(--green);
819
+ border: 1px solid var(--green-2);
820
+ color: var(--white);
821
+ svg {
822
+ color: var(--white);
823
+ }
824
+ `
825
+ };
826
+ var AlertContainer = import_styled_components5.default.div`
827
+ position: fixed;
828
+ width: 500px;
829
+ top: 15px;
830
+ right: 15px;
831
+ padding: 1rem ${({ $dismissible }) => $dismissible ? "2.5rem" : "1rem"} 1rem
832
+ 1rem;
833
+ margin-bottom: 1rem;
834
+ animation: ${({ $isClosing }) => $isClosing ? fadeOut : fadeIn} 0.3s
835
+ ease-out;
836
+ animation-fill-mode: forwards;
837
+ align-items: center;
838
+ gap: 0.5rem;
839
+ box-shadow: var(--shadow-500);
840
+ border-radius: 0.5rem;
841
+ font-size: 1rem;
842
+ font-weight: 500;
843
+
844
+ ${({ $type }) => typeStyles[$type]}
845
+ `;
846
+ var DismissButton = import_styled_components5.default.button`
847
+ position: absolute;
848
+ background: transparent;
849
+ right: 10px;
850
+ border: none;
851
+ cursor: pointer;
852
+ color: inherit;
853
+ opacity: 1;
854
+ transition: opacity 0.2s;
855
+
856
+ &:hover {
857
+ opacity: 0.7;
858
+ }
859
+
860
+ svg {
861
+ width: 1rem;
862
+ height: 1rem;
863
+ }
864
+ `;
865
+
866
+ // src/components/Alert/index.tsx
867
+ var import_hi = require("react-icons/hi");
868
+ var import_jsx_runtime3 = require("react/jsx-runtime");
869
+ var Alert = ({
870
+ type = "info",
871
+ children,
872
+ className,
873
+ dismissible = false,
874
+ onDismiss,
875
+ autoDismiss
876
+ }) => {
877
+ const [isClosing, setIsClosing] = (0, import_react4.useState)(false);
878
+ const handleDismiss = (0, import_react4.useCallback)(() => {
879
+ setIsClosing(true);
880
+ setTimeout(() => onDismiss?.(), 300);
881
+ }, [onDismiss]);
882
+ (0, import_react4.useEffect)(() => {
883
+ if (autoDismiss) {
884
+ const timer = setTimeout(handleDismiss, autoDismiss);
885
+ return () => clearTimeout(timer);
886
+ }
887
+ }, [autoDismiss, handleDismiss]);
888
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
889
+ AlertContainer,
890
+ {
891
+ $type: type,
892
+ $dismissible: dismissible,
893
+ $isClosing: isClosing,
894
+ className,
895
+ role: "alert",
896
+ children: [
897
+ children,
898
+ dismissible && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
899
+ DismissButton,
900
+ {
901
+ onClick: handleDismiss,
902
+ "aria-label": "Dismiss alert",
903
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_hi.HiX, {})
904
+ }
905
+ )
906
+ ]
907
+ }
908
+ );
909
+ };
910
+
911
+ // src/components/Form/index.tsx
912
+ var import_jsx_runtime4 = require("react/jsx-runtime");
913
+ var schema = yup.object().shape({
914
+ name: yup.string().required("Nome \xE9 obrigat\xF3rio"),
915
+ email: yup.string().required("Email \xE9 obrigat\xF3rio").email("Email inv\xE1lido"),
916
+ phone: yup.string().required("Telefone \xE9 obrigat\xF3rio").test(
917
+ "min-digits",
918
+ "N\xFAmero de telefone inv\xE1lido!",
919
+ (value) => {
920
+ const digitsOnly = value?.replace(/\D/g, "") || "";
921
+ return digitsOnly.length >= 8;
922
+ }
923
+ )
924
+ });
925
+ var MitreFormComponent = import_react5.default.forwardRef(({
926
+ productId,
927
+ apiUrl,
928
+ apiToken,
929
+ utm_source,
930
+ utm_medium,
931
+ utm_campaign,
932
+ utm_term,
933
+ showHeader = true,
934
+ colorPrimary = "#F6C76B",
935
+ textColor = "#2F2F2F"
936
+ }, ref) => {
937
+ const [loading, setIsLoading] = (0, import_react5.useState)(false);
938
+ const { error, handleError, clearError } = useError();
939
+ const [successMessage, setSuccessMessage] = (0, import_react5.useState)("");
940
+ const { register, handleSubmit, formState: { errors }, reset, watch } = (0, import_react_hook_form.useForm)({
941
+ resolver: (0, import_yup.yupResolver)(schema)
942
+ });
943
+ const phoneValue = watch("phone");
944
+ const sendMessage = async (data) => {
945
+ const { name, email, phone } = data;
946
+ const message = "Gostaria de mais informa\xE7\xF5es sobre o produto";
947
+ try {
948
+ setIsLoading(true);
949
+ if (!productId || !utm_source || !utm_medium || !utm_campaign || !utm_term || !apiToken) {
950
+ throw new Error("Par\xE2metros obrigat\xF3rios n\xE3o informados");
951
+ }
952
+ const response = await fetch(`${apiUrl}/leads`, {
953
+ method: "POST",
954
+ headers: {
955
+ "Content-Type": "application/json",
956
+ Authorization: `Basic ${apiToken}`
957
+ },
958
+ body: JSON.stringify({
959
+ name,
960
+ email,
961
+ phone,
962
+ message,
963
+ productId,
964
+ utm_source,
965
+ utm_medium,
966
+ utm_campaign,
967
+ utm_term
968
+ })
969
+ });
970
+ if (!response.ok) {
971
+ throw new Error("Falha ao enviar a mensagem!");
972
+ }
973
+ setSuccessMessage("Mensagem enviada com sucesso!");
974
+ reset();
975
+ } catch (err) {
976
+ handleError(err);
977
+ } finally {
978
+ setIsLoading(false);
979
+ }
980
+ };
981
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
982
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(global_default, {}),
983
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GlobalStyles, {}),
984
+ error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
985
+ Alert,
986
+ {
987
+ type: "error",
988
+ dismissible: true,
989
+ onDismiss: clearError,
990
+ autoDismiss: 5e3,
991
+ children: error.message
992
+ }
993
+ ),
994
+ successMessage && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
995
+ Alert,
996
+ {
997
+ type: "success",
998
+ dismissible: true,
999
+ onDismiss: () => setSuccessMessage(""),
1000
+ autoDismiss: 5e3,
1001
+ children: successMessage
1002
+ }
1003
+ ),
1004
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(FormContainer, { ref, children: [
1005
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(HeaderContainer, { children: [
1006
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Title, { $textColor: textColor, children: "Atendimento por mensagem" }),
1007
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { $textColor: textColor, children: "Informe seus dados e retornaremos a mensagem." })
1008
+ ] }),
1009
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Form, { $textColor: textColor, onSubmit: handleSubmit(sendMessage), noValidate: true, children: [
1010
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1011
+ Input2,
1012
+ {
1013
+ id: "name",
1014
+ label: "Nome *",
1015
+ placeholder: "Digite seu nome",
1016
+ ...register("name"),
1017
+ borderColor: colorPrimary,
1018
+ textColor,
1019
+ error: errors.name?.message,
1020
+ autoComplete: "name",
1021
+ required: true
1022
+ }
1023
+ ),
1024
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1025
+ Input2,
1026
+ {
1027
+ id: "email",
1028
+ label: "Email *",
1029
+ type: "email",
1030
+ placeholder: "exemplo@email.com",
1031
+ ...register("email"),
1032
+ borderColor: colorPrimary,
1033
+ textColor,
1034
+ error: errors.email?.message,
1035
+ autoComplete: "email",
1036
+ required: true
1037
+ }
1038
+ ),
1039
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1040
+ Input2,
1041
+ {
1042
+ id: "phone",
1043
+ label: "Telefone *",
1044
+ placeholder: "(11) 00000-0000",
1045
+ mask: "phone",
1046
+ ...register("phone"),
1047
+ borderColor: colorPrimary,
1048
+ textColor,
1049
+ error: errors.phone?.message,
1050
+ required: true,
1051
+ value: phoneValue
1052
+ }
1053
+ ),
1054
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h6", { children: "* Campos de preenchimento obrigat\xF3rio." }),
1055
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ButtonContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { bgColor: colorPrimary, color: textColor, type: "submit", isSubmitting: loading, children: "Enviar mensagem" }) }),
1056
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { children: [
1057
+ "A Mitre Realty respeita a sua privacidade e utiliza os seus dados pessoais para contat\xE1-lo por e-mail ou telefone aqui registrados. Para saber mais, acesse a nossa",
1058
+ " ",
1059
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1060
+ "a",
1061
+ {
1062
+ href: "https://www.mitrerealty.com.br/politica-de-privacidade",
1063
+ target: "_blank",
1064
+ rel: "noopener noreferrer",
1065
+ children: "Pol\xEDtica de Privacidade"
1066
+ }
1067
+ ),
1068
+ ". Ao clicar em ",
1069
+ '"',
1070
+ "enviar",
1071
+ '"',
1072
+ ", voc\xEA concorda em permitir que a Mitre Realty, armazene e processe os dados pessoais fornecidos por voc\xEA para finalidade informada"
1073
+ ] })
1074
+ ] })
1075
+ ] })
1076
+ ] });
1077
+ });
1078
+ MitreFormComponent.displayName = "MitreFormComponent";
1079
+ var Form_default = MitreFormComponent;
1080
+ // Annotate the CommonJS export names for ESM import in node:
1081
+ 0 && (module.exports = {
1082
+ MitreFormComponent
1083
+ });
1084
+ //# sourceMappingURL=index.js.map