mitre-form-component 0.0.11 → 0.0.12

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