@lets-events/react 11.6.2 → 11.6.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.
Files changed (75) hide show
  1. package/.eslintrc.json +2 -2
  2. package/.turbo/turbo-build.log +20 -18
  3. package/CHANGELOG.md +6 -0
  4. package/dist/index.d.mts +33 -5
  5. package/dist/index.d.ts +33 -5
  6. package/dist/index.js +9 -3
  7. package/dist/index.mjs +7 -3
  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 +16 -16
  14. package/src/components/Button/styledComponents.ts +287 -287
  15. package/src/components/ButtonGroup.tsx +484 -484
  16. package/src/components/Calendar/index.tsx +136 -136
  17. package/src/components/Calendar/styledComponents.ts +209 -209
  18. package/src/components/Card.tsx +48 -48
  19. package/src/components/CheckboxGroup.tsx +176 -176
  20. package/src/components/Container.tsx +39 -39
  21. package/src/components/Drawer/index.tsx +48 -48
  22. package/src/components/Drawer/styledComponents.ts +46 -46
  23. package/src/components/Dropdown.tsx +194 -192
  24. package/src/components/Filter.tsx +164 -164
  25. package/src/components/Flex.tsx +118 -118
  26. package/src/components/FormFields/AddressFormFields/CityFormField.tsx +111 -111
  27. package/src/components/FormFields/AddressFormFields/CountryFormField.tsx +33 -33
  28. package/src/components/FormFields/AddressFormFields/PostalCodeFormField.tsx +45 -45
  29. package/src/components/FormFields/AddressFormFields/StateFormField.tsx +32 -32
  30. package/src/components/FormFields/AddressFormFields/index.tsx +139 -139
  31. package/src/components/FormFields/BirthDateFormField.tsx +87 -87
  32. package/src/components/FormFields/CNPJFormField.tsx +89 -89
  33. package/src/components/FormFields/CPFFormField.tsx +79 -79
  34. package/src/components/FormFields/CheckboxGroupFormField.tsx +90 -90
  35. package/src/components/FormFields/ErrorFormMessage.tsx +36 -36
  36. package/src/components/FormFields/Form.tsx +29 -29
  37. package/src/components/FormFields/FormLabel.tsx +29 -29
  38. package/src/components/FormFields/IdentityDocumentNumberFormField.tsx +42 -42
  39. package/src/components/FormFields/MultiSelectFormField.tsx +59 -59
  40. package/src/components/FormFields/PhoneFormField.tsx +130 -130
  41. package/src/components/FormFields/RadioGroupFormField.tsx +84 -84
  42. package/src/components/FormFields/SelectFormField.tsx +93 -93
  43. package/src/components/FormFields/TextAreaFormField.tsx +48 -48
  44. package/src/components/FormFields/TextFormField.tsx +76 -76
  45. package/src/components/Grid.tsx +137 -137
  46. package/src/components/Icon.tsx +47 -47
  47. package/src/components/MenuDropdown/index.tsx +30 -30
  48. package/src/components/MenuDropdown/styledComponents.ts +31 -31
  49. package/src/components/Modal.tsx +90 -90
  50. package/src/components/MultiSelect.tsx +218 -218
  51. package/src/components/RadioGroup.tsx +210 -210
  52. package/src/components/Section.tsx +33 -33
  53. package/src/components/Step.tsx +164 -164
  54. package/src/components/Switch.tsx +108 -108
  55. package/src/components/Text.tsx +38 -38
  56. package/src/components/TextField.tsx +312 -312
  57. package/src/components/TextareaField.tsx +128 -128
  58. package/src/components/TimePicker.tsx +298 -298
  59. package/src/components/Toast/components/ToastItem.tsx +41 -41
  60. package/src/components/Toast/components/ToastProvider.tsx +63 -63
  61. package/src/components/Toast/hooks/useToast.ts +12 -12
  62. package/src/components/Toast/index.tsx +5 -5
  63. package/src/components/Toast/styles/index.ts +135 -135
  64. package/src/components/Toast/types/index.ts +46 -46
  65. package/src/components/Tooltip/index.tsx +66 -66
  66. package/src/components/Tooltip/styles.ts +77 -77
  67. package/src/hooks/useCountries.ts +41 -41
  68. package/src/hooks/useOnClickOutside.tsx +20 -20
  69. package/src/index.tsx +54 -52
  70. package/src/styles/index.ts +38 -38
  71. package/src/types/typographyValues.ts +178 -178
  72. package/src/utils/getNestedValue.ts +3 -3
  73. package/src/utils/states.ts +29 -29
  74. package/tsconfig.json +3 -3
  75. package/dist/index.css +0 -171
@@ -1,79 +1,79 @@
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
- validation={{
57
- validate: (value: string) => {
58
- if (!required || foreigner) return true;
59
- return isValidCPF(value) || validationErrorMessage;
60
- },
61
- }}
62
- disabled={foreigner}
63
- />
64
-
65
- <CheckboxGroup
66
- name="foreigner"
67
- onValueChange={(value) => {
68
- const isForeigner = value.includes("true");
69
- setValue("foreigner", isForeigner);
70
- if (isForeigner) {
71
- setValue(name, "");
72
- }
73
- }}
74
- >
75
- <CheckboxItem value="true">{foreignerLabel}</CheckboxItem>
76
- </CheckboxGroup>
77
- </Flex>
78
- );
79
- };
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
+ validation={{
57
+ validate: (value: string) => {
58
+ if (!required || foreigner) return true;
59
+ return isValidCPF(value) || validationErrorMessage;
60
+ },
61
+ }}
62
+ disabled={foreigner}
63
+ />
64
+
65
+ <CheckboxGroup
66
+ name="foreigner"
67
+ onValueChange={(value) => {
68
+ const isForeigner = value.includes("true");
69
+ setValue("foreigner", isForeigner);
70
+ if (isForeigner) {
71
+ setValue(name, "");
72
+ }
73
+ }}
74
+ >
75
+ <CheckboxItem value="true">{foreignerLabel}</CheckboxItem>
76
+ </CheckboxGroup>
77
+ </Flex>
78
+ );
79
+ };
@@ -1,90 +1,90 @@
1
- import { Controller, useFormContext } from "react-hook-form";
2
- import { Flex } from "../Flex";
3
- import { FormLabel } from "./FormLabel";
4
- import { ErrorFormMessage } from "./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
- onValueChange={field.onChange}
70
- color={haveError ? "error" : color}
71
- fontWeight={fontWeight}
72
- disabled={disabled}
73
- >
74
- {options.map((option) => (
75
- <CheckboxItem
76
- key={option.value}
77
- value={option.value}
78
- disabled={disabled}
79
- >
80
- {option.label}
81
- </CheckboxItem>
82
- ))}
83
- </CheckboxGroup>
84
- )}
85
- />
86
-
87
- <ErrorFormMessage message={errorMsg} />
88
- </Flex>
89
- );
90
- };
1
+ import { Controller, useFormContext } from "react-hook-form";
2
+ import { Flex } from "../Flex";
3
+ import { FormLabel } from "./FormLabel";
4
+ import { ErrorFormMessage } from "./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
+ onValueChange={field.onChange}
70
+ color={haveError ? "error" : color}
71
+ fontWeight={fontWeight}
72
+ disabled={disabled}
73
+ >
74
+ {options.map((option) => (
75
+ <CheckboxItem
76
+ key={option.value}
77
+ value={option.value}
78
+ disabled={disabled}
79
+ >
80
+ {option.label}
81
+ </CheckboxItem>
82
+ ))}
83
+ </CheckboxGroup>
84
+ )}
85
+ />
86
+
87
+ <ErrorFormMessage message={errorMsg} />
88
+ </Flex>
89
+ );
90
+ };
@@ -1,36 +1,36 @@
1
- import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
2
- import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3
- import { colors } from "@lets-events/tokens";
4
- import { Flex } from "../Flex";
5
- import { Text } from "../Text";
6
- import {
7
- FieldError,
8
- FieldErrorsImpl,
9
- FieldValues,
10
- Merge,
11
- } from "react-hook-form";
12
-
13
- export type ErrorFormMessageProps = {
14
- message?:
15
- | string
16
- | FieldError
17
- | Merge<FieldError, FieldErrorsImpl<any>>
18
- | undefined;
19
- };
20
-
21
- export const ErrorFormMessage = ({ message }: ErrorFormMessageProps) => {
22
- if (!message) return null;
23
-
24
- if (typeof message !== "string") {
25
- return null;
26
- }
27
-
28
- return (
29
- <Flex justify={"start"} align={"center"} gap={6}>
30
- <FontAwesomeIcon icon={faXmarkCircle} color={colors.error600} size="1x" />
31
- <Text typography={"bodyXS"} fontWeight={"medium"} color="error600">
32
- {message}
33
- </Text>
34
- </Flex>
35
- );
36
- };
1
+ import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
2
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3
+ import { colors } from "@lets-events/tokens";
4
+ import { Flex } from "../Flex";
5
+ import { Text } from "../Text";
6
+ import {
7
+ FieldError,
8
+ FieldErrorsImpl,
9
+ FieldValues,
10
+ Merge,
11
+ } from "react-hook-form";
12
+
13
+ export type ErrorFormMessageProps = {
14
+ message?:
15
+ | string
16
+ | FieldError
17
+ | Merge<FieldError, FieldErrorsImpl<any>>
18
+ | undefined;
19
+ };
20
+
21
+ export const ErrorFormMessage = ({ message }: ErrorFormMessageProps) => {
22
+ if (!message) return null;
23
+
24
+ if (typeof message !== "string") {
25
+ return null;
26
+ }
27
+
28
+ return (
29
+ <Flex justify={"start"} align={"center"} gap={6}>
30
+ <FontAwesomeIcon icon={faXmarkCircle} color={colors.error600} size="1x" />
31
+ <Text typography={"bodyXS"} fontWeight={"medium"} color="error600">
32
+ {message}
33
+ </Text>
34
+ </Flex>
35
+ );
36
+ };
@@ -1,29 +1,29 @@
1
- import { JSX } from "react";
2
- import {
3
- FormProvider,
4
- useForm,
5
- SubmitHandler,
6
- FieldValues,
7
- UseFormProps,
8
- } from "react-hook-form";
9
-
10
- export type FormProps<T extends FieldValues = FieldValues> = UseFormProps<T> & {
11
- onSubmit: SubmitHandler<T>;
12
- children: JSX.Element;
13
- methods?: ReturnType<typeof useForm<T>>;
14
- };
15
-
16
- export const Form = <T extends FieldValues = FieldValues>({
17
- onSubmit,
18
- children,
19
- methods,
20
- ...props
21
- }: FormProps<T>) => {
22
- const formMethods = methods || useForm<T>(props);
23
-
24
- return (
25
- <FormProvider {...formMethods}>
26
- <form onSubmit={formMethods.handleSubmit(onSubmit)}>{children}</form>
27
- </FormProvider>
28
- );
29
- };
1
+ import { JSX } from "react";
2
+ import {
3
+ FormProvider,
4
+ useForm,
5
+ SubmitHandler,
6
+ FieldValues,
7
+ UseFormProps,
8
+ } from "react-hook-form";
9
+
10
+ export type FormProps<T extends FieldValues = FieldValues> = UseFormProps<T> & {
11
+ onSubmit: SubmitHandler<T>;
12
+ children: JSX.Element;
13
+ methods?: ReturnType<typeof useForm<T>>;
14
+ };
15
+
16
+ export const Form = <T extends FieldValues = FieldValues>({
17
+ onSubmit,
18
+ children,
19
+ methods,
20
+ ...props
21
+ }: FormProps<T>) => {
22
+ const formMethods = methods || useForm<T>(props);
23
+
24
+ return (
25
+ <FormProvider {...formMethods}>
26
+ <form onSubmit={formMethods.handleSubmit(onSubmit)}>{children}</form>
27
+ </FormProvider>
28
+ );
29
+ };
@@ -1,29 +1,29 @@
1
- import { Text } from "../Text";
2
-
3
- export type FormLabelProps = {
4
- name: string;
5
- label?: string;
6
- haveError?: boolean;
7
- required?: boolean;
8
- };
9
-
10
- export const FormLabel = ({
11
- name,
12
- label,
13
- haveError,
14
- required,
15
- }: FormLabelProps) => {
16
- if (!label) return null;
17
-
18
- return (
19
- <Text
20
- typography={"labelMedium"}
21
- fontWeight={"medium"}
22
- color={haveError ? "error600" : "dark700"}
23
- id={`${name}-label`}
24
- >
25
- {label}
26
- {!required && <Text color="dark500"> (opcional)</Text>}
27
- </Text>
28
- );
29
- };
1
+ import { Text } from "../Text";
2
+
3
+ export type FormLabelProps = {
4
+ name: string;
5
+ label?: string;
6
+ haveError?: boolean;
7
+ required?: boolean;
8
+ };
9
+
10
+ export const FormLabel = ({
11
+ name,
12
+ label,
13
+ haveError,
14
+ required,
15
+ }: FormLabelProps) => {
16
+ if (!label) return null;
17
+
18
+ return (
19
+ <Text
20
+ typography={"labelMedium"}
21
+ fontWeight={"medium"}
22
+ color={haveError ? "error600" : "dark700"}
23
+ id={`${name}-label`}
24
+ >
25
+ {label}
26
+ {!required && <Text color="dark500"> (opcional)</Text>}
27
+ </Text>
28
+ );
29
+ };
@@ -1,42 +1,42 @@
1
- import { TextFormField } from "./TextFormField";
2
-
3
- type IdentityDocumentNumberFormFieldProps = {
4
- name: string;
5
- label: string;
6
- required?: boolean;
7
- placeholder?: string;
8
- validationErrorMessage: string;
9
- };
10
-
11
- const isValidRG = (rg: string): boolean => {
12
- const cleaned = rg.replace(/[^\d]/g, "");
13
- return /^\d{9}$/.test(cleaned);
14
- };
15
-
16
- export const IdentityDocumentNumberFormField = ({
17
- name,
18
- label,
19
- required,
20
- placeholder,
21
- validationErrorMessage,
22
- }: IdentityDocumentNumberFormFieldProps) => {
23
- return (
24
- <TextFormField
25
- name={name}
26
- label={label}
27
- required={required}
28
- placeholder={placeholder || "__.___.___-_"}
29
- mask={{
30
- mask: "__.___.___-_",
31
- replacement: { _: /[0-9]/ },
32
- }}
33
- validation={{
34
- validate: (value: string) => {
35
- const isEmpty = value.replace(/[^\d]/g, "").length === 0;
36
- if (!required && isEmpty) return true;
37
- return isValidRG(value) || validationErrorMessage;
38
- },
39
- }}
40
- />
41
- );
42
- };
1
+ import { TextFormField } from "./TextFormField";
2
+
3
+ type IdentityDocumentNumberFormFieldProps = {
4
+ name: string;
5
+ label: string;
6
+ required?: boolean;
7
+ placeholder?: string;
8
+ validationErrorMessage: string;
9
+ };
10
+
11
+ const isValidRG = (rg: string): boolean => {
12
+ const cleaned = rg.replace(/[^\d]/g, "");
13
+ return /^\d{9}$/.test(cleaned);
14
+ };
15
+
16
+ export const IdentityDocumentNumberFormField = ({
17
+ name,
18
+ label,
19
+ required,
20
+ placeholder,
21
+ validationErrorMessage,
22
+ }: IdentityDocumentNumberFormFieldProps) => {
23
+ return (
24
+ <TextFormField
25
+ name={name}
26
+ label={label}
27
+ required={required}
28
+ placeholder={placeholder || "__.___.___-_"}
29
+ mask={{
30
+ mask: "__.___.___-_",
31
+ replacement: { _: /[0-9]/ },
32
+ }}
33
+ validation={{
34
+ validate: (value: string) => {
35
+ const isEmpty = value.replace(/[^\d]/g, "").length === 0;
36
+ if (!required && isEmpty) return true;
37
+ return isValidRG(value) || validationErrorMessage;
38
+ },
39
+ }}
40
+ />
41
+ );
42
+ };