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