@lets-events/react 12.3.10 → 12.4.1

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.
Files changed (91) hide show
  1. package/.eslintrc.json +2 -2
  2. package/.turbo/turbo-build.log +19 -21
  3. package/CHANGELOG.md +12 -0
  4. package/dist/index.d.mts +35 -3
  5. package/dist/index.d.ts +35 -3
  6. package/dist/index.js +562 -344
  7. package/dist/index.mjs +535 -319
  8. package/package.json +1 -1
  9. package/src/components/Alert.tsx +303 -303
  10. package/src/components/Avatar.tsx +55 -55
  11. package/src/components/Badge.tsx +125 -125
  12. package/src/components/Box.tsx +3 -3
  13. package/src/components/Button/index.tsx +45 -45
  14. package/src/components/Button/styledComponents.ts +313 -313
  15. package/src/components/ButtonGroup.tsx +484 -484
  16. package/src/components/Calendar/index.tsx +148 -148
  17. package/src/components/Calendar/styledComponents.ts +259 -250
  18. package/src/components/Card.tsx +67 -67
  19. package/src/components/CheckboxGroup.tsx +176 -176
  20. package/src/components/Container.tsx +39 -39
  21. package/src/components/Divider.tsx +7 -7
  22. package/src/components/DoubleCalendar/index.tsx +166 -0
  23. package/src/components/Drawer/index.tsx +98 -98
  24. package/src/components/Drawer/styledComponents.ts +103 -103
  25. package/src/components/Dropdown.tsx +302 -302
  26. package/src/components/Filter.tsx +164 -164
  27. package/src/components/Flex.tsx +118 -118
  28. package/src/components/FormFields/AddressFormFields/CityFormField.tsx +111 -111
  29. package/src/components/FormFields/AddressFormFields/CountryFormField.tsx +33 -33
  30. package/src/components/FormFields/AddressFormFields/PostalCodeFormField.tsx +39 -39
  31. package/src/components/FormFields/AddressFormFields/StateFormField.tsx +32 -32
  32. package/src/components/FormFields/AddressFormFields/index.tsx +141 -141
  33. package/src/components/FormFields/BirthDateFormField.tsx +84 -84
  34. package/src/components/FormFields/CNPJFormField.tsx +87 -87
  35. package/src/components/FormFields/CPFFormField.tsx +78 -78
  36. package/src/components/FormFields/CalendarFormField.tsx +95 -95
  37. package/src/components/FormFields/CheckboxGroupFormField.tsx +91 -91
  38. package/src/components/FormFields/DoubleCalendarFormField.tsx +90 -0
  39. package/src/components/FormFields/EmailFormField.tsx +27 -27
  40. package/src/components/FormFields/Form.tsx +39 -39
  41. package/src/components/FormFields/IdentityDocumentNumberFormField.tsx +32 -32
  42. package/src/components/FormFields/MultiSelectFormField.tsx +64 -64
  43. package/src/components/FormFields/PhoneFormField.tsx +40 -40
  44. package/src/components/FormFields/RadioGroupFormField.tsx +84 -84
  45. package/src/components/FormFields/RichEditorFormField.tsx +103 -103
  46. package/src/components/FormFields/SelectFormField.tsx +93 -93
  47. package/src/components/FormFields/SwitchFormField.tsx +46 -46
  48. package/src/components/FormFields/TextAreaFormField.tsx +59 -57
  49. package/src/components/FormFields/TextFormField.tsx +112 -112
  50. package/src/components/FormFields/TimePickerFormField.tsx +88 -88
  51. package/src/components/FormFields/subComponents/ErrorFormMessage.tsx +36 -36
  52. package/src/components/FormFields/subComponents/FormLabel.tsx +29 -29
  53. package/src/components/FormFields/utils/validation.ts +23 -23
  54. package/src/components/Grid.tsx +137 -137
  55. package/src/components/Icon.tsx +47 -47
  56. package/src/components/MenuDropdown/index.tsx +38 -38
  57. package/src/components/MenuDropdown/styledComponents.ts +31 -31
  58. package/src/components/Modal.tsx +110 -110
  59. package/src/components/MultiSelect/index.tsx +243 -243
  60. package/src/components/MultiSelect/styledComponents.ts +160 -160
  61. package/src/components/RadioGroup.tsx +210 -210
  62. package/src/components/RichEditor/QuillComponent.tsx +457 -457
  63. package/src/components/RichEditor/RichEditor.tsx +49 -49
  64. package/src/components/RichEditor/index.ts +2 -2
  65. package/src/components/RichEditor/styledComponents.ts +1151 -1151
  66. package/src/components/Section.tsx +33 -33
  67. package/src/components/Step.tsx +164 -164
  68. package/src/components/Switch.tsx +108 -108
  69. package/src/components/Text.tsx +38 -38
  70. package/src/components/TextField.tsx +372 -372
  71. package/src/components/TextareaField.tsx +138 -127
  72. package/src/components/TimePicker.tsx +328 -328
  73. package/src/components/Toast/components/ToastItem.tsx +41 -41
  74. package/src/components/Toast/components/ToastProvider.tsx +63 -63
  75. package/src/components/Toast/hooks/useToast.ts +12 -12
  76. package/src/components/Toast/index.tsx +5 -5
  77. package/src/components/Toast/styles/index.ts +135 -135
  78. package/src/components/Toast/types/index.ts +46 -46
  79. package/src/components/Tooltip/index.tsx +66 -66
  80. package/src/components/Tooltip/styles.ts +77 -77
  81. package/src/hooks/useCountries.ts +41 -41
  82. package/src/hooks/useImageUpload.ts +139 -139
  83. package/src/hooks/useOnClickOutside.tsx +42 -42
  84. package/src/index.tsx +71 -69
  85. package/src/styles/index.ts +41 -41
  86. package/src/types/typographyValues.ts +178 -178
  87. package/src/utils/getNestedValue.ts +3 -3
  88. package/src/utils/states.ts +29 -29
  89. package/src/utils/uploadService.ts +180 -180
  90. package/tsconfig.json +3 -3
  91. package/tsup.config.ts +38 -38
@@ -1,78 +1,78 @@
1
- import { useFormContext, useWatch } from "react-hook-form";
2
- import { CheckboxGroup, CheckboxItem } from "../CheckboxGroup";
3
- import { Flex } from "../Flex";
4
- import { TextFormField } from "./TextFormField";
5
-
6
- type CPFFormFieldProps = {
7
- name: string;
8
- label: string;
9
- required?: boolean;
10
- placeholder?: string;
11
- validationErrorMessage: string;
12
- foreignerLabel: string;
13
- };
14
-
15
- const isValidCPF = (cpf: string) => {
16
- cpf = cpf.replace(/[^\d]+/g, "");
17
- if (cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) return false;
18
-
19
- let sum = 0;
20
- for (let i = 0; i < 9; i++) sum += parseInt(cpf.charAt(i)) * (10 - i);
21
- let rest = (sum * 10) % 11;
22
- if (rest === 10 || rest === 11) rest = 0;
23
- if (rest !== parseInt(cpf.charAt(9))) return false;
24
-
25
- sum = 0;
26
- for (let i = 0; i < 10; i++) sum += parseInt(cpf.charAt(i)) * (11 - i);
27
- rest = (sum * 10) % 11;
28
- if (rest === 10 || rest === 11) rest = 0;
29
- if (rest !== parseInt(cpf.charAt(10))) return false;
30
-
31
- return true;
32
- };
33
-
34
- export const CPFFormField = ({
35
- name,
36
- label,
37
- required,
38
- placeholder,
39
- validationErrorMessage,
40
- foreignerLabel,
41
- }: CPFFormFieldProps) => {
42
- const { control, setValue } = useFormContext();
43
- const foreigner = useWatch({ name: "foreigner", control });
44
-
45
- return (
46
- <Flex direction="column">
47
- <TextFormField
48
- name={name}
49
- label={label}
50
- required={required && !foreigner}
51
- placeholder={placeholder || "000.000.000-00"}
52
- mask={{
53
- mask: "___.___.___-__",
54
- replacement: { _: /[0-9]/ },
55
- }}
56
- validate={(value: string) => {
57
- if (!required || foreigner) return true;
58
- return isValidCPF(value) || validationErrorMessage;
59
- }}
60
- disabled={foreigner}
61
- />
62
-
63
- <CheckboxGroup
64
- value={foreigner ? ["true"] : []}
65
- name="foreigner"
66
- onValueChange={(value) => {
67
- const isForeigner = value.includes("true");
68
- setValue("foreigner", isForeigner);
69
- if (isForeigner) {
70
- setValue(name, "");
71
- }
72
- }}
73
- >
74
- <CheckboxItem value="true">{foreignerLabel}</CheckboxItem>
75
- </CheckboxGroup>
76
- </Flex>
77
- );
78
- };
1
+ import { useFormContext, useWatch } from "react-hook-form";
2
+ import { CheckboxGroup, CheckboxItem } from "../CheckboxGroup";
3
+ import { Flex } from "../Flex";
4
+ import { TextFormField } from "./TextFormField";
5
+
6
+ type CPFFormFieldProps = {
7
+ name: string;
8
+ label: string;
9
+ required?: boolean;
10
+ placeholder?: string;
11
+ validationErrorMessage: string;
12
+ foreignerLabel: string;
13
+ };
14
+
15
+ const isValidCPF = (cpf: string) => {
16
+ cpf = cpf.replace(/[^\d]+/g, "");
17
+ if (cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) return false;
18
+
19
+ let sum = 0;
20
+ for (let i = 0; i < 9; i++) sum += parseInt(cpf.charAt(i)) * (10 - i);
21
+ let rest = (sum * 10) % 11;
22
+ if (rest === 10 || rest === 11) rest = 0;
23
+ if (rest !== parseInt(cpf.charAt(9))) return false;
24
+
25
+ sum = 0;
26
+ for (let i = 0; i < 10; i++) sum += parseInt(cpf.charAt(i)) * (11 - i);
27
+ rest = (sum * 10) % 11;
28
+ if (rest === 10 || rest === 11) rest = 0;
29
+ if (rest !== parseInt(cpf.charAt(10))) return false;
30
+
31
+ return true;
32
+ };
33
+
34
+ export const CPFFormField = ({
35
+ name,
36
+ label,
37
+ required,
38
+ placeholder,
39
+ validationErrorMessage,
40
+ foreignerLabel,
41
+ }: CPFFormFieldProps) => {
42
+ const { control, setValue } = useFormContext();
43
+ const foreigner = useWatch({ name: "foreigner", control });
44
+
45
+ return (
46
+ <Flex direction="column">
47
+ <TextFormField
48
+ name={name}
49
+ label={label}
50
+ required={required && !foreigner}
51
+ placeholder={placeholder || "000.000.000-00"}
52
+ mask={{
53
+ mask: "___.___.___-__",
54
+ replacement: { _: /[0-9]/ },
55
+ }}
56
+ validate={(value: string) => {
57
+ if (!required || foreigner) return true;
58
+ return isValidCPF(value) || validationErrorMessage;
59
+ }}
60
+ disabled={foreigner}
61
+ />
62
+
63
+ <CheckboxGroup
64
+ value={foreigner ? ["true"] : []}
65
+ name="foreigner"
66
+ onValueChange={(value) => {
67
+ const isForeigner = value.includes("true");
68
+ setValue("foreigner", isForeigner);
69
+ if (isForeigner) {
70
+ setValue(name, "");
71
+ }
72
+ }}
73
+ >
74
+ <CheckboxItem value="true">{foreignerLabel}</CheckboxItem>
75
+ </CheckboxGroup>
76
+ </Flex>
77
+ );
78
+ };
@@ -1,95 +1,95 @@
1
- import React from "react";
2
- import { FieldValues, useController, RegisterOptions } from "react-hook-form";
3
- import { Flex } from "../Flex";
4
- import { FormLabel } from "./subComponents/FormLabel";
5
- import { ErrorFormMessage } from "./subComponents/ErrorFormMessage";
6
- import { Calendar, CalendarProps } from "../Calendar";
7
- import { useCallback } from "react";
8
-
9
- export type CalendarFormFieldProps = Omit<
10
- CalendarProps,
11
- "selected" | "setSelected"
12
- > & {
13
- name: string;
14
- label?: string;
15
- required?: boolean;
16
- validate?: (value: Date | undefined) => boolean | string;
17
- validationErrorMessage?: string;
18
- rules?: Omit<
19
- RegisterOptions<FieldValues, string>,
20
- "valueAsNumber" | "valueAsDate" | "setValueAs" | "disabled"
21
- >;
22
- allowPastDates?: boolean;
23
- maxYearsFromNow?: number;
24
- };
25
-
26
- export const CalendarFormField = ({
27
- name,
28
- label,
29
- required,
30
- validate,
31
- validationErrorMessage = "Este campo é obrigatório.",
32
- rules,
33
- onChange,
34
- allowPastDates,
35
- maxYearsFromNow = 20,
36
- ...calendarProps
37
- }: CalendarFormFieldProps) => {
38
- const handleValidate = useCallback(
39
- (value?: Date) => {
40
- if (value === undefined || value === null) {
41
- if (required) return validationErrorMessage;
42
- return true;
43
- }
44
- return validate?.(value) ?? true;
45
- },
46
- [validate, required, validationErrorMessage]
47
- );
48
-
49
- const { field, fieldState } = useController({
50
- name,
51
- rules: {
52
- required: required ? validationErrorMessage : false,
53
- validate: handleValidate,
54
- ...rules,
55
- },
56
- defaultValue: undefined,
57
- });
58
-
59
- const fieldError = fieldState.error;
60
- const haveError = !!fieldError;
61
- const errorMsg = fieldError?.message;
62
-
63
- const { value: selected, onChange: setSelected } = field;
64
-
65
- const handleCalendarChange = (date: Date | undefined) => {
66
- setSelected(date);
67
- };
68
-
69
- return (
70
- <Flex direction="column" style={{ flex: "1" }}>
71
- {label && (
72
- <FormLabel
73
- name={name}
74
- label={label}
75
- required={required}
76
- haveError={haveError}
77
- />
78
- )}
79
-
80
- <Calendar
81
- selected={selected}
82
- setSelected={(value) => {
83
- const date = typeof value === "function" ? value(selected) : value;
84
- handleCalendarChange(date);
85
- }}
86
- hasError={haveError}
87
- allowPastDates={allowPastDates}
88
- maxYearsFromNow={maxYearsFromNow}
89
- {...calendarProps}
90
- />
91
-
92
- <ErrorFormMessage message={errorMsg} />
93
- </Flex>
94
- );
95
- };
1
+ import React from "react";
2
+ import { FieldValues, useController, RegisterOptions } from "react-hook-form";
3
+ import { Flex } from "../Flex";
4
+ import { FormLabel } from "./subComponents/FormLabel";
5
+ import { ErrorFormMessage } from "./subComponents/ErrorFormMessage";
6
+ import { Calendar, CalendarProps } from "../Calendar";
7
+ import { useCallback } from "react";
8
+
9
+ export type CalendarFormFieldProps = Omit<
10
+ CalendarProps,
11
+ "selected" | "setSelected"
12
+ > & {
13
+ name: string;
14
+ label?: string;
15
+ required?: boolean;
16
+ validate?: (value: Date | undefined) => boolean | string;
17
+ validationErrorMessage?: string;
18
+ rules?: Omit<
19
+ RegisterOptions<FieldValues, string>,
20
+ "valueAsNumber" | "valueAsDate" | "setValueAs" | "disabled"
21
+ >;
22
+ allowPastDates?: boolean;
23
+ maxYearsFromNow?: number;
24
+ };
25
+
26
+ export const CalendarFormField = ({
27
+ name,
28
+ label,
29
+ required,
30
+ validate,
31
+ validationErrorMessage = "Este campo é obrigatório.",
32
+ rules,
33
+ onChange,
34
+ allowPastDates,
35
+ maxYearsFromNow = 20,
36
+ ...calendarProps
37
+ }: CalendarFormFieldProps) => {
38
+ const handleValidate = useCallback(
39
+ (value?: Date) => {
40
+ if (value === undefined || value === null) {
41
+ if (required) return validationErrorMessage;
42
+ return true;
43
+ }
44
+ return validate?.(value) ?? true;
45
+ },
46
+ [validate, required, validationErrorMessage]
47
+ );
48
+
49
+ const { field, fieldState } = useController({
50
+ name,
51
+ rules: {
52
+ required: required ? validationErrorMessage : false,
53
+ validate: handleValidate,
54
+ ...rules,
55
+ },
56
+ defaultValue: undefined,
57
+ });
58
+
59
+ const fieldError = fieldState.error;
60
+ const haveError = !!fieldError;
61
+ const errorMsg = fieldError?.message;
62
+
63
+ const { value: selected, onChange: setSelected } = field;
64
+
65
+ const handleCalendarChange = (date: Date | undefined) => {
66
+ setSelected(date);
67
+ };
68
+
69
+ return (
70
+ <Flex direction="column" style={{ flex: "1" }}>
71
+ {label && (
72
+ <FormLabel
73
+ name={name}
74
+ label={label}
75
+ required={required}
76
+ haveError={haveError}
77
+ />
78
+ )}
79
+
80
+ <Calendar
81
+ selected={selected}
82
+ setSelected={(value) => {
83
+ const date = typeof value === "function" ? value(selected) : value;
84
+ handleCalendarChange(date);
85
+ }}
86
+ hasError={haveError}
87
+ allowPastDates={allowPastDates}
88
+ maxYearsFromNow={maxYearsFromNow}
89
+ {...calendarProps}
90
+ />
91
+
92
+ <ErrorFormMessage message={errorMsg} />
93
+ </Flex>
94
+ );
95
+ };
@@ -1,91 +1,91 @@
1
- import { Controller, useFormContext } from "react-hook-form";
2
- import { Flex } from "../Flex";
3
- import { FormLabel } from "./subComponents/FormLabel";
4
- import { ErrorFormMessage } from "./subComponents/ErrorFormMessage";
5
- import { CheckboxGroup, CheckboxItem } from "../CheckboxGroup";
6
- import { getNestedValue } from "../../utils/getNestedValue";
7
-
8
- type Option = {
9
- label: string;
10
- value: string;
11
- };
12
-
13
- export type CheckboxGroupFormFieldProps = {
14
- name: string;
15
- label: string;
16
- options: Option[];
17
- required?: boolean;
18
- validationErrorMessage?: string;
19
- defaultValue?: string[];
20
- color?: "blue" | "success" | "error";
21
- fontWeight?: "regular" | "medium" | "semibold" | "bold";
22
- disabled?: boolean;
23
- };
24
-
25
- export const CheckboxGroupFormField = ({
26
- name,
27
- label,
28
- options,
29
- required,
30
- validationErrorMessage = "Selecione pelo menos uma opção.",
31
- defaultValue = [],
32
- color = "blue",
33
- fontWeight = "regular",
34
- disabled = false,
35
- }: CheckboxGroupFormFieldProps) => {
36
- const {
37
- control,
38
- formState: { errors },
39
- } = useFormContext();
40
-
41
- const fieldError = getNestedValue(errors, name);
42
- const haveError = !!fieldError;
43
- const errorMsg = fieldError?.message;
44
-
45
- const validationRules = {
46
- required: required ? validationErrorMessage : false,
47
- validate: required
48
- ? (value: string[]) => value?.length > 0 || validationErrorMessage
49
- : undefined,
50
- };
51
-
52
- return (
53
- <Flex direction="column">
54
- <FormLabel
55
- name={name}
56
- label={label}
57
- required={required}
58
- haveError={haveError}
59
- />
60
-
61
- <Controller
62
- name={name}
63
- control={control}
64
- rules={validationRules}
65
- defaultValue={defaultValue}
66
- render={({ field }) => (
67
- <CheckboxGroup
68
- name={name}
69
- value={field.value}
70
- onValueChange={field.onChange}
71
- color={haveError ? "error" : color}
72
- fontWeight={fontWeight}
73
- disabled={disabled}
74
- >
75
- {options.map((option) => (
76
- <CheckboxItem
77
- key={option.value}
78
- value={option.value}
79
- disabled={disabled}
80
- >
81
- {option.label}
82
- </CheckboxItem>
83
- ))}
84
- </CheckboxGroup>
85
- )}
86
- />
87
-
88
- <ErrorFormMessage message={errorMsg} />
89
- </Flex>
90
- );
91
- };
1
+ import { Controller, useFormContext } from "react-hook-form";
2
+ import { Flex } from "../Flex";
3
+ import { FormLabel } from "./subComponents/FormLabel";
4
+ import { ErrorFormMessage } from "./subComponents/ErrorFormMessage";
5
+ import { CheckboxGroup, CheckboxItem } from "../CheckboxGroup";
6
+ import { getNestedValue } from "../../utils/getNestedValue";
7
+
8
+ type Option = {
9
+ label: string;
10
+ value: string;
11
+ };
12
+
13
+ export type CheckboxGroupFormFieldProps = {
14
+ name: string;
15
+ label: string;
16
+ options: Option[];
17
+ required?: boolean;
18
+ validationErrorMessage?: string;
19
+ defaultValue?: string[];
20
+ color?: "blue" | "success" | "error";
21
+ fontWeight?: "regular" | "medium" | "semibold" | "bold";
22
+ disabled?: boolean;
23
+ };
24
+
25
+ export const CheckboxGroupFormField = ({
26
+ name,
27
+ label,
28
+ options,
29
+ required,
30
+ validationErrorMessage = "Selecione pelo menos uma opção.",
31
+ defaultValue = [],
32
+ color = "blue",
33
+ fontWeight = "regular",
34
+ disabled = false,
35
+ }: CheckboxGroupFormFieldProps) => {
36
+ const {
37
+ control,
38
+ formState: { errors },
39
+ } = useFormContext();
40
+
41
+ const fieldError = getNestedValue(errors, name);
42
+ const haveError = !!fieldError;
43
+ const errorMsg = fieldError?.message;
44
+
45
+ const validationRules = {
46
+ required: required ? validationErrorMessage : false,
47
+ validate: required
48
+ ? (value: string[]) => value?.length > 0 || validationErrorMessage
49
+ : undefined,
50
+ };
51
+
52
+ return (
53
+ <Flex direction="column">
54
+ <FormLabel
55
+ name={name}
56
+ label={label}
57
+ required={required}
58
+ haveError={haveError}
59
+ />
60
+
61
+ <Controller
62
+ name={name}
63
+ control={control}
64
+ rules={validationRules}
65
+ defaultValue={defaultValue}
66
+ render={({ field }) => (
67
+ <CheckboxGroup
68
+ name={name}
69
+ value={field.value}
70
+ onValueChange={field.onChange}
71
+ color={haveError ? "error" : color}
72
+ fontWeight={fontWeight}
73
+ disabled={disabled}
74
+ >
75
+ {options.map((option) => (
76
+ <CheckboxItem
77
+ key={option.value}
78
+ value={option.value}
79
+ disabled={disabled}
80
+ >
81
+ {option.label}
82
+ </CheckboxItem>
83
+ ))}
84
+ </CheckboxGroup>
85
+ )}
86
+ />
87
+
88
+ <ErrorFormMessage message={errorMsg} />
89
+ </Flex>
90
+ );
91
+ };
@@ -0,0 +1,90 @@
1
+ import { useCallback } from "react";
2
+ import { FieldValues, useController, RegisterOptions } from "react-hook-form";
3
+ import { Flex } from "../Flex";
4
+ import { FormLabel } from "./subComponents/FormLabel";
5
+ import { ErrorFormMessage } from "./subComponents/ErrorFormMessage";
6
+ import { DoubleCalendar, DateRange, DoubleCalendarProps } from "../DoubleCalendar";
7
+
8
+ export type DoubleCalendarFormFieldProps = Omit<
9
+ DoubleCalendarProps,
10
+ "selected" | "setSelected"
11
+ > & {
12
+ name: string;
13
+ label?: string;
14
+ required?: boolean;
15
+ validate?: (value: DateRange) => boolean | string;
16
+ validationErrorMessage?: string;
17
+ rules?: Omit<
18
+ RegisterOptions<FieldValues, string>,
19
+ "valueAsNumber" | "valueAsDate" | "setValueAs" | "disabled"
20
+ >;
21
+ allowPastDates?: boolean;
22
+ maxYearsFromNow?: number;
23
+ };
24
+
25
+ export const DoubleCalendarFormField = ({
26
+ name,
27
+ label,
28
+ required,
29
+ validate,
30
+ validationErrorMessage = "Este campo é obrigatório.",
31
+ rules,
32
+ allowPastDates,
33
+ maxYearsFromNow = 20,
34
+ ...calendarProps
35
+ }: DoubleCalendarFormFieldProps) => {
36
+ const handleValidate = useCallback(
37
+ (value?: DateRange) => {
38
+ if (value === undefined || value === null) {
39
+ if (required) return validationErrorMessage;
40
+ return true;
41
+ }
42
+ return validate?.(value) ?? true;
43
+ },
44
+ [validate, required, validationErrorMessage]
45
+ );
46
+
47
+ const { field, fieldState } = useController({
48
+ name,
49
+ rules: {
50
+ required: required ? validationErrorMessage : false,
51
+ validate: handleValidate,
52
+ ...rules,
53
+ },
54
+ defaultValue: undefined,
55
+ });
56
+
57
+ const fieldError = fieldState.error;
58
+ const haveError = !!fieldError;
59
+ const errorMsg = fieldError?.message;
60
+
61
+ const { value: selected, onChange: setSelected } = field as any;
62
+
63
+ const handleCalendarChange = (range: DateRange) => {
64
+ setSelected(range);
65
+ };
66
+
67
+ return (
68
+ <Flex direction="column" style={{ flex: "1" }}>
69
+ {label && (
70
+ <FormLabel name={name} label={label} required={required} haveError={haveError} />
71
+ )}
72
+
73
+ <DoubleCalendar
74
+ selected={selected}
75
+ setSelected={(value) => {
76
+ const newValue = typeof value === "function" ? value(selected) : value;
77
+ handleCalendarChange(newValue);
78
+ }}
79
+ hasError={haveError}
80
+ allowPastDates={allowPastDates}
81
+ maxYearsFromNow={maxYearsFromNow}
82
+ {...calendarProps}
83
+ />
84
+
85
+ <ErrorFormMessage message={errorMsg} />
86
+ </Flex>
87
+ );
88
+ };
89
+
90
+ export default DoubleCalendarFormField;
@@ -1,27 +1,27 @@
1
- import { TextFormField } from "./TextFormField";
2
- import { validateEmail } from "./utils/validation";
3
-
4
- export type EmailFormFieldProps = {
5
- name: string;
6
- label?: string;
7
- required?: boolean;
8
- placeholder?: string;
9
- };
10
-
11
- export const EmailFormField = ({
12
- name,
13
- label,
14
- required,
15
- placeholder,
16
- }: EmailFormFieldProps) => {
17
- return (
18
- <TextFormField
19
- name={name}
20
- label={label}
21
- required={required}
22
- placeholder={placeholder}
23
- type="email"
24
- validate={validateEmail("E-mail inválido.")}
25
- />
26
- );
27
- };
1
+ import { TextFormField } from "./TextFormField";
2
+ import { validateEmail } from "./utils/validation";
3
+
4
+ export type EmailFormFieldProps = {
5
+ name: string;
6
+ label?: string;
7
+ required?: boolean;
8
+ placeholder?: string;
9
+ };
10
+
11
+ export const EmailFormField = ({
12
+ name,
13
+ label,
14
+ required,
15
+ placeholder,
16
+ }: EmailFormFieldProps) => {
17
+ return (
18
+ <TextFormField
19
+ name={name}
20
+ label={label}
21
+ required={required}
22
+ placeholder={placeholder}
23
+ type="email"
24
+ validate={validateEmail("E-mail inválido.")}
25
+ />
26
+ );
27
+ };