eai-frontend-components 2.0.5 → 2.0.7

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 (104) hide show
  1. package/dist/index.esm.js +2 -2
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.js +2 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +3 -3
  6. package/src/components/ui/accordion.tsx +0 -48
  7. package/src/components/ui/alert-dialog.tsx +0 -138
  8. package/src/components/ui/alert.tsx +0 -36
  9. package/src/components/ui/avatar.tsx +0 -48
  10. package/src/components/ui/badge.tsx +0 -35
  11. package/src/components/ui/breadcrumb.tsx +0 -115
  12. package/src/components/ui/button.tsx +0 -43
  13. package/src/components/ui/calendar.tsx +0 -142
  14. package/src/components/ui/card.tsx +0 -35
  15. package/src/components/ui/carousel.tsx +0 -257
  16. package/src/components/ui/chart.tsx +0 -363
  17. package/src/components/ui/checkbox.tsx +0 -26
  18. package/src/components/ui/collapsible.tsx +0 -9
  19. package/src/components/ui/command.tsx +0 -145
  20. package/src/components/ui/context-menu.tsx +0 -198
  21. package/src/components/ui/custom/date-picker.tsx +0 -97
  22. package/src/components/ui/custom/form/checkbox.tsx +0 -53
  23. package/src/components/ui/custom/form/color.tsx +0 -140
  24. package/src/components/ui/custom/form/combobox.tsx +0 -259
  25. package/src/components/ui/custom/form/cpf-cnpj.tsx +0 -85
  26. package/src/components/ui/custom/form/currency.tsx +0 -51
  27. package/src/components/ui/custom/form/date-range.tsx +0 -110
  28. package/src/components/ui/custom/form/date.tsx +0 -109
  29. package/src/components/ui/custom/form/decimal.tsx +0 -50
  30. package/src/components/ui/custom/form/file.tsx +0 -65
  31. package/src/components/ui/custom/form/form-help-text.tsx +0 -20
  32. package/src/components/ui/custom/form/form-label.tsx +0 -24
  33. package/src/components/ui/custom/form/form-message.tsx +0 -10
  34. package/src/components/ui/custom/form/ghost.tsx +0 -28
  35. package/src/components/ui/custom/form/input.tsx +0 -69
  36. package/src/components/ui/custom/form/mask.tsx +0 -78
  37. package/src/components/ui/custom/form/multi-select.tsx +0 -209
  38. package/src/components/ui/custom/form/password.tsx +0 -70
  39. package/src/components/ui/custom/form/percent.tsx +0 -52
  40. package/src/components/ui/custom/form/phone.tsx +0 -79
  41. package/src/components/ui/custom/form/radio-group.tsx +0 -94
  42. package/src/components/ui/custom/form/select.tsx +0 -62
  43. package/src/components/ui/custom/form/step-new-form.tsx +0 -49
  44. package/src/components/ui/custom/form/switch.tsx +0 -51
  45. package/src/components/ui/custom/form/text.tsx +0 -71
  46. package/src/components/ui/custom/form/textarea.tsx +0 -71
  47. package/src/components/ui/custom/form/utils.ts +0 -100
  48. package/src/components/ui/custom/header.tsx +0 -128
  49. package/src/components/ui/custom/label.tsx +0 -79
  50. package/src/components/ui/custom/not-found.tsx +0 -30
  51. package/src/components/ui/custom/sidebar/module-switcher.tsx +0 -58
  52. package/src/components/ui/custom/sidebar/nav-footer.tsx +0 -35
  53. package/src/components/ui/custom/sidebar/nav-main.tsx +0 -64
  54. package/src/components/ui/custom/sidebar/nav-submenu-collapsible.tsx +0 -60
  55. package/src/components/ui/custom/sidebar/nav-submenu-dropdown.tsx +0 -56
  56. package/src/components/ui/custom/sidebar/nav-user.tsx +0 -77
  57. package/src/components/ui/custom/sidebar/sidebar-button.tsx +0 -30
  58. package/src/components/ui/custom/sidebar/sidebar-item-two-lines.tsx +0 -25
  59. package/src/components/ui/custom/sidebar/sidebar-item.tsx +0 -19
  60. package/src/components/ui/custom/sidebar/types/sidebar.ts +0 -31
  61. package/src/components/ui/custom/table/data-table-export.tsx +0 -126
  62. package/src/components/ui/custom/table/data-table-footer.tsx +0 -148
  63. package/src/components/ui/custom/table/data-table-header.tsx +0 -58
  64. package/src/components/ui/custom/table/data-table-rows.tsx +0 -94
  65. package/src/components/ui/custom/table/data-table.tsx +0 -285
  66. package/src/components/ui/custom/table/types/data-table.ts +0 -31
  67. package/src/components/ui/custom/theme-provider.tsx +0 -121
  68. package/src/components/ui/dateRangePicker.tsx +0 -63
  69. package/src/components/ui/dialog.tsx +0 -84
  70. package/src/components/ui/drawer.tsx +0 -116
  71. package/src/components/ui/dropdown-menu.tsx +0 -173
  72. package/src/components/ui/form.tsx +0 -114
  73. package/src/components/ui/hover-card.tsx +0 -27
  74. package/src/components/ui/input.tsx +0 -265
  75. package/src/components/ui/label.tsx +0 -15
  76. package/src/components/ui/masks.ts +0 -35
  77. package/src/components/ui/pagination.tsx +0 -78
  78. package/src/components/ui/popover.tsx +0 -32
  79. package/src/components/ui/progress.tsx +0 -22
  80. package/src/components/ui/radio-group.tsx +0 -36
  81. package/src/components/ui/scroll-area.tsx +0 -46
  82. package/src/components/ui/select.tsx +0 -130
  83. package/src/components/ui/separator.tsx +0 -29
  84. package/src/components/ui/sheet.tsx +0 -90
  85. package/src/components/ui/sidebar.tsx +0 -598
  86. package/src/components/ui/skeleton.tsx +0 -15
  87. package/src/components/ui/slider.tsx +0 -18
  88. package/src/components/ui/switch.tsx +0 -26
  89. package/src/components/ui/table.tsx +0 -53
  90. package/src/components/ui/tabs.tsx +0 -47
  91. package/src/components/ui/textarea.tsx +0 -27
  92. package/src/components/ui/toast.tsx +0 -88
  93. package/src/components/ui/toaster.tsx +0 -49
  94. package/src/components/ui/tooltip.tsx +0 -31
  95. package/src/components/ui/use-calendar.tsx +0 -61
  96. package/src/components/ui/use-toast.ts +0 -186
  97. package/src/hooks/use-mobile.tsx +0 -19
  98. package/src/index.ts +0 -299
  99. package/src/lib/help/date-utils.ts +0 -41
  100. package/src/lib/help/format.ts +0 -171
  101. package/src/lib/help/theme.ts +0 -346
  102. package/src/lib/help/uuid.ts +0 -4
  103. package/src/lib/utils.ts +0 -6
  104. package/src/styles/globals.css +0 -59
@@ -1,259 +0,0 @@
1
- import { Check, ChevronsUpDown, LoaderCircle, X } from 'lucide-react';
2
- import { useEffect, useState } from 'react';
3
- import { ControllerRenderProps, FieldValues } from 'react-hook-form';
4
- import { cn } from '../../../../lib/utils';
5
- import { Button } from '../../button';
6
- import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '../../command';
7
- import * as FormComponents from '../../form';
8
- import { Popover, PopoverContent, PopoverTrigger } from '../../popover';
9
- import { formHelpText } from './form-help-text';
10
- import { formLabelAndSubLabel } from './form-label';
11
- import { formMessage } from './form-message';
12
-
13
- export interface ComboboxOption {
14
- value: string | undefined;
15
- icon?: React.ReactNode | undefined;
16
- title: string;
17
- subTitle?: string;
18
- className?: string;
19
- }
20
-
21
- interface Props {
22
- control: any;
23
- name: string;
24
- label?: string;
25
- subLabel?: string;
26
- helpText?: JSX.Element;
27
- placeholder?: string;
28
- className?: string;
29
- disabled?: boolean;
30
- required?: boolean;
31
- options: ComboboxOption[];
32
- selectedOption?: ComboboxOption;
33
- iconLeft?: React.ReactNode | null;
34
- iconRight?: React.ReactNode | null;
35
- addEmptyOption?: boolean;
36
- canUnselect?: boolean;
37
- closePopUpOnChange?: boolean;
38
- runInternalSearch?: boolean;
39
- disabledSearch?: boolean;
40
- onChange?: (option: ComboboxOption | undefined) => void;
41
- onSearch?: (searchString: string) => void;
42
- footerAction?: {
43
- label: string;
44
- icon?: React.ReactNode;
45
- onClick: () => void;
46
- };
47
- }
48
-
49
- export const FormCombobox: React.FC<Props> = ({
50
- control,
51
- name,
52
- label,
53
- subLabel,
54
- helpText,
55
- placeholder,
56
- className,
57
- disabled,
58
- required,
59
- options,
60
- selectedOption,
61
- iconLeft,
62
- iconRight,
63
- addEmptyOption,
64
- canUnselect = false,
65
- closePopUpOnChange = true,
66
- runInternalSearch = true,
67
- disabledSearch = false,
68
- onChange,
69
- onSearch,
70
- footerAction,
71
- }) => {
72
- const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
73
-
74
- const [open, setOpen] = useState(false);
75
- const [loading, setLoading] = useState<boolean>(false);
76
- const [searchString, setSearchString] = useState<string>('');
77
- const DEFAULT_PLACEHOLDER = 'Digite para buscar...';
78
-
79
- useEffect(() => {
80
- setLoading(false);
81
- }, [options]);
82
-
83
- const getOptions = () => {
84
- if (options.length === 0) {
85
- return [];
86
- }
87
-
88
- let filteredOptions = options;
89
- if (runInternalSearch) {
90
- filteredOptions = options.filter((option) => {
91
- const title = option.title
92
- .toLowerCase()
93
- .normalize('NFD')
94
- .replace(/[^a-z0-9\s]/gi, '');
95
- const subTitle = option.subTitle
96
- ?.toLowerCase()
97
- .normalize('NFD')
98
- .replace(/[^a-z0-9\s]/gi, '');
99
- const search = searchString
100
- .toLowerCase()
101
- .normalize('NFD')
102
- .replace(/[^a-z0-9\s]/gi, '');
103
-
104
- return title.includes(search) || subTitle?.includes(search);
105
- });
106
- }
107
-
108
- if (addEmptyOption) {
109
- filteredOptions.unshift({ value: undefined, title: '--Selecione--', subTitle: '' });
110
- }
111
-
112
- return filteredOptions;
113
- };
114
-
115
- const getSelectedOption = (value: string | undefined): ComboboxOption | undefined => {
116
- const option = options.find((option) => option.value === value);
117
-
118
- if (option) {
119
- return option;
120
- }
121
-
122
- return selectedOption;
123
- };
124
-
125
- const handleSelect = (value: string | undefined, field: ControllerRenderProps<FieldValues, string>) => {
126
- const option = value ? getSelectedOption(value) : undefined;
127
-
128
- if (canUnselect) {
129
- field.onChange(field.value === value ? undefined : value);
130
- } else {
131
- field.onChange(value);
132
- }
133
-
134
- if (onChange) {
135
- onChange(option);
136
- }
137
- if (closePopUpOnChange) {
138
- setOpen(false);
139
- }
140
- };
141
-
142
- const handleKeyUp = (event: React.KeyboardEvent<HTMLInputElement>) => {
143
- const searchString = (event.target as HTMLInputElement).value;
144
-
145
- if (onSearch) {
146
- setLoading(true);
147
- onSearch(searchString);
148
- }
149
- setSearchString(searchString);
150
- };
151
-
152
- return (
153
- <FormField
154
- control={control}
155
- name={name}
156
- render={({ field, formState }) => (
157
- <FormItem className={className}>
158
- <div className='flex items-center space-x-1.5'>
159
- {label && formLabelAndSubLabel(FormLabel, label, subLabel, required)}
160
- {helpText && formHelpText(helpText)}
161
- </div>
162
- <Popover
163
- open={open}
164
- onOpenChange={(open) => {
165
- if (!disabled) setOpen(open);
166
- }}
167
- >
168
- <PopoverTrigger asChild>
169
- <FormControl>
170
- <div className={cn(`rounded-sm outline-none ${open ? 'ring-2 ring-ring ring-offset-2' : 'ring-0'}`, className)}>
171
- <Button
172
- type='button'
173
- variant='outline'
174
- role='combobox'
175
- aria-expanded={open}
176
- className={cn(
177
- 'justify-between disabled:border-disabled disabled:cursor-not-allowed disabled:opacity-50',
178
- formState.errors[name] ? 'border-red-600' : '',
179
- className,
180
- )}
181
- disabled={disabled || formState.isSubmitting}
182
- >
183
- {iconLeft}
184
- <div className='grid flex-1 text-left text-sm leading-tight'>
185
- <span className='truncate font-normal'>
186
- {getSelectedOption(field.value) ? (
187
- <div className='flex gap-2'>
188
- {getSelectedOption(field.value)?.icon}
189
- {getSelectedOption(field.value)?.title}
190
- </div>
191
- ) : (
192
- <span className='text-zinc-500'>{placeholder ?? DEFAULT_PLACEHOLDER}</span>
193
- )}
194
- </span>
195
- </div>
196
- {iconRight ?? <ChevronsUpDown size={20} className='stroke-zinc-500' />}
197
- </Button>
198
- </div>
199
- </FormControl>
200
- </PopoverTrigger>
201
- <PopoverContent className={cn('p-0', className, 'w-[--radix-popover-trigger-width]')}>
202
- <Command shouldFilter={false}>
203
- {!disabledSearch && <CommandInput placeholder={placeholder ?? DEFAULT_PLACEHOLDER} onKeyUp={handleKeyUp} />}
204
- <CommandList>
205
- <CommandEmpty className='flex flex-col justify-between items-center p-3 font-normal text-sm'>
206
- {loading ? (
207
- <LoaderCircle size={16} className='text-sidebar-foreground animate-spin mr-2' />
208
- ) : getOptions()?.length === 0 && (searchString !== '' || disabledSearch) ? (
209
- 'Nenhum resultado encontrado'
210
- ) : (
211
- 'Utilize o campo de busca acima'
212
- )}
213
- </CommandEmpty>
214
- {options.length > 0 && (
215
- <CommandGroup>
216
- {getOptions().map((option) => (
217
- <CommandItem
218
- key={`key-opt-${option.value}`}
219
- value={option.value}
220
- className='group'
221
- onSelect={() => handleSelect(option.value, field)}
222
- >
223
- <div className={cn('grid flex-1 text-left text-sm leading-tight', option.className)}>
224
- <div className='flex gap-2'>
225
- {option.icon}
226
- <span className='truncate font-normal'>{option.title}</span>
227
- </div>
228
- <span className='truncate text-xs text-zinc-500'>{option.subTitle}</span>
229
- </div>
230
- <div
231
- className={`ml-auto text-zinc-500 ${
232
- field.value === option.value ? 'opacity-100' : 'opacity-0'
233
- }`}
234
- >
235
- <Check className={cn('flex', canUnselect && 'group-hover:hidden hover:hidden')} size={16} />
236
- <X className={cn('hidden', canUnselect && 'group-hover:flex hover:flex')} size={16} />
237
- </div>
238
- </CommandItem>
239
- ))}
240
- </CommandGroup>
241
- )}
242
- </CommandList>
243
- </Command>
244
- {footerAction && (
245
- <div className='grid w-full p-1 border-t'>
246
- <Button type='button' variant='ghost' className='h-8' onClick={() => footerAction.onClick()}>
247
- {footerAction.icon}
248
- {footerAction.label}
249
- </Button>
250
- </div>
251
- )}
252
- </PopoverContent>
253
- </Popover>
254
- {formMessage(FormMessage)}
255
- </FormItem>
256
- )}
257
- />
258
- );
259
- };
@@ -1,85 +0,0 @@
1
- import { useState } from 'react';
2
- import * as FormComponents from '../../form';
3
- import { MaskInputCpfCnpj } from '../../input';
4
- import { formHelpText } from './form-help-text';
5
- import { formLabelAndSubLabel } from './form-label';
6
- import { formMessage } from './form-message';
7
-
8
- interface Props {
9
- control: any;
10
- name: string;
11
- label: string;
12
- subLabel?: string;
13
- helpText?: JSX.Element;
14
- placeholder?: string;
15
- className?: string;
16
- disabled?: boolean;
17
- required?: boolean;
18
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
19
- onKeyUp?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
20
- }
21
-
22
- const masks = ['999.999.999-999', '99.999.999/9999-99'];
23
-
24
- export const FormInputCpfCnpj: React.FC<Props> = ({
25
- control,
26
- name,
27
- label,
28
- subLabel,
29
- helpText,
30
- placeholder,
31
- className,
32
- disabled,
33
- required,
34
- onChange,
35
- onKeyUp,
36
- }) => {
37
- const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
38
- const [mask, setMask] = useState(masks[0]);
39
-
40
- const handleMaskChange = (value: string) => {
41
- const numericValue = value.replace(/\D/g, '');
42
- if (numericValue.length > 11) {
43
- setMask(masks[1]);
44
- } else {
45
- setMask(masks[0]);
46
- }
47
- };
48
-
49
- return (
50
- <FormField
51
- control={control}
52
- name={name}
53
- render={({ field, formState }) => (
54
- <FormItem className={className}>
55
- <div className='flex items-center space-x-1.5'>
56
- {label && formLabelAndSubLabel(FormLabel, label, subLabel, required)}
57
- {helpText && formHelpText(helpText)}
58
- </div>
59
- <FormControl>
60
- <MaskInputCpfCnpj
61
- {...field}
62
- className={`${className}`}
63
- placeholder={placeholder}
64
- disabled={disabled || formState.isSubmitting}
65
- mask={mask}
66
- onChange={(e) => {
67
- field.onChange(e);
68
- handleMaskChange(e.target.value);
69
- if (onChange) {
70
- onChange(e);
71
- }
72
- }}
73
- onKeyUp={(e) => {
74
- if (onKeyUp) {
75
- onKeyUp(e);
76
- }
77
- }}
78
- />
79
- </FormControl>
80
- {formMessage(FormMessage)}
81
- </FormItem>
82
- )}
83
- />
84
- );
85
- };
@@ -1,51 +0,0 @@
1
- import * as FormComponents from '../../form';
2
- import { MaskInputDecimal } from '../../input';
3
- import { formHelpText } from './form-help-text';
4
- import { formLabelAndSubLabel } from './form-label';
5
- import { formMessage } from './form-message';
6
-
7
- interface Props {
8
- control: any;
9
- name: string;
10
- label: string;
11
- subLabel?: string;
12
- helpText?: JSX.Element;
13
- className?: string;
14
- disabled?: boolean;
15
- required?: boolean;
16
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
17
- }
18
-
19
- export const FormInputCurrency: React.FC<Props> = ({ control, name, label, subLabel, helpText, className, disabled, required, onChange }) => {
20
- const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
21
-
22
- return (
23
- <FormField
24
- control={control}
25
- name={name}
26
- render={({ field, formState }) => (
27
- <FormItem className={className}>
28
- <div className='flex items-center space-x-1.5'>
29
- {label && formLabelAndSubLabel(FormLabel, label, subLabel, required)}
30
- {helpText && formHelpText(helpText)}
31
- </div>
32
- <FormControl>
33
- <MaskInputDecimal
34
- {...field}
35
- symbol='R$'
36
- className={`${className}`}
37
- disabled={disabled || formState.isSubmitting}
38
- onChange={(e) => {
39
- field.onChange(e);
40
- if (onChange) {
41
- onChange(e);
42
- }
43
- }}
44
- />
45
- </FormControl>
46
- {formMessage(FormMessage)}
47
- </FormItem>
48
- )}
49
- />
50
- );
51
- };
@@ -1,110 +0,0 @@
1
- import { format } from 'date-fns';
2
- import { CalendarIcon } from 'lucide-react';
3
- import { useState } from 'react';
4
- import { DateRange } from 'react-day-picker';
5
- import { cn } from '../../../../lib/utils';
6
- import { Button } from '../../button';
7
- import { Calendar } from '../../calendar';
8
- import * as FormComponents from '../../form';
9
- import { Popover, PopoverContent, PopoverTrigger } from '../../popover';
10
- import { formHelpText } from './form-help-text';
11
- import { formLabelAndSubLabel } from './form-label';
12
- import { formMessage } from './form-message';
13
-
14
- interface Props {
15
- control: any;
16
- name: string;
17
- label: string;
18
- subLabel?: string;
19
- helpText?: JSX.Element;
20
- placeholder?: string;
21
- className?: string;
22
- disabled?: boolean;
23
- required?: boolean;
24
- onChange?: (event: React.ChangeEvent<HTMLInputElement> | DateRange | undefined) => void;
25
- }
26
-
27
- export const FormDataRange: React.FC<Props> = ({
28
- control,
29
- name,
30
- label,
31
- subLabel,
32
- helpText,
33
- placeholder,
34
- className,
35
- disabled,
36
- required,
37
- onChange,
38
- }) => {
39
- const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
40
-
41
- // const [date, setDate] = useState<DateRange | undefined>(field.value);
42
- const [open, setOpen] = useState(false);
43
-
44
- const handleDateChange = (newDate: DateRange | undefined, field: any) => {
45
- // setDate(newDate);
46
- field.onChange(newDate);
47
- if (onChange) onChange(newDate);
48
- };
49
-
50
- return (
51
- <FormField
52
- control={control}
53
- name={name}
54
- render={({ field, formState }) => (
55
- <FormItem className={className}>
56
- <div className='flex items-center space-x-1.5'>
57
- {label && formLabelAndSubLabel(FormLabel, label, subLabel, required)}
58
- {helpText && formHelpText(helpText)}
59
- </div>
60
- <FormControl>
61
- <Popover open={open} onOpenChange={setOpen}>
62
- <PopoverTrigger asChild className='w-full'>
63
- <div className={` rounded-sm outline-none ${open ? 'ring-2 ring-ring ring-offset-2' : 'ring-0'}`}>
64
- <Button
65
- type='button'
66
- variant='outline'
67
- role='combobox'
68
- aria-expanded={open}
69
- className={cn(
70
- ` ${className} justify-start disabled:border-disabled disabled:cursor-not-allowed disabled:opacity-50`,
71
- formState.errors[name] ? 'border-red-600' : '',
72
- )}
73
- disabled={disabled || formState.isSubmitting}
74
- >
75
- <CalendarIcon className='text-zinc-500' />
76
- {field.value?.from ? (
77
- field.value?.to ? (
78
- <>
79
- {format(field.value?.from, 'dd/MM/yyyy')} - {format(field.value?.to, 'dd/MM/yyyy')}
80
- </>
81
- ) : (
82
- format(field.value?.from, 'dd/MM/yyyy')
83
- )
84
- ) : (
85
- <span className='font-normal text-zinc-500'>Escolha um Período</span>
86
- )}
87
- </Button>
88
- </div>
89
- </PopoverTrigger>
90
- <PopoverContent className='flex w-auto p-0' align='start'>
91
- <div className='flex flex-row space-x-4'>
92
- <Calendar
93
- initialFocus
94
- mode='range'
95
- defaultMonth={field.value?.from}
96
- selected={field.value}
97
- numberOfMonths={2}
98
- className='flex'
99
- onSelect={(newDate) => handleDateChange(newDate, field)}
100
- />
101
- </div>
102
- </PopoverContent>
103
- </Popover>
104
- </FormControl>
105
- {formMessage(FormMessage)}
106
- </FormItem>
107
- )}
108
- />
109
- );
110
- };
@@ -1,109 +0,0 @@
1
- import { ptBR } from 'date-fns/locale';
2
- import { CalendarIcon } from 'lucide-react';
3
- import { useState } from 'react';
4
- import { stringToDate } from '../../../../lib/help/date-utils';
5
- import { cn } from '../../../../lib/utils';
6
- import { Calendar } from '../../calendar';
7
- import * as FormComponents from '../../form';
8
- import { MaskInput } from '../../input';
9
- import { Popover, PopoverContent, PopoverTrigger } from '../../popover';
10
- import { formHelpText } from './form-help-text';
11
- import { formLabelAndSubLabel } from './form-label';
12
- import { formMessage } from './form-message';
13
-
14
- interface Props {
15
- control: any;
16
- name: string;
17
- label: string;
18
- subLabel?: string;
19
- helpText?: JSX.Element;
20
- placeholder?: string;
21
- className?: string;
22
- disabled?: boolean;
23
- required?: boolean;
24
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
25
- onKeyUp?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
26
- }
27
-
28
- export const FormInputDate: React.FC<Props> = ({
29
- control,
30
- name,
31
- label,
32
- subLabel,
33
- helpText,
34
- placeholder = '01/01/2023',
35
- className,
36
- disabled,
37
- required,
38
- onChange,
39
- onKeyUp,
40
- }) => {
41
- const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
42
- const [open, setOpen] = useState(false);
43
-
44
- return (
45
- <FormField
46
- control={control}
47
- name={name}
48
- render={({ field, formState }) => (
49
- <FormItem className={className}>
50
- <div className='flex items-center space-x-1.5'>
51
- {label && formLabelAndSubLabel(FormLabel, label, subLabel, required)}
52
- {helpText && formHelpText(helpText)}
53
- </div>
54
- <FormControl>
55
- <div className='relative w-full'>
56
- <MaskInput
57
- {...field}
58
- mask={'99/99/9999'}
59
- maskPlaceholder={null}
60
- placeholder={placeholder}
61
- disabled={disabled || formState.isSubmitting}
62
- className={cn('pl-9', className)}
63
- onChange={(e) => {
64
- field.onChange(e);
65
- if (onChange) {
66
- onChange(e);
67
- }
68
- }}
69
- onKeyUp={(e) => {
70
- if (onKeyUp) {
71
- onKeyUp(e);
72
- }
73
- }}
74
- />
75
-
76
- <div className='absolute left-3 top-1/2 -translate-y-1/2 cursor-pointer'>
77
- <Popover open={open} onOpenChange={setOpen}>
78
- <PopoverTrigger asChild>
79
- <CalendarIcon size={16} className='cursor-pointer text-gray-500' />
80
- </PopoverTrigger>
81
- <PopoverContent className='w-[250px] p-0' align='start'>
82
- <Calendar
83
- mode='single'
84
- locale={ptBR}
85
- required={true}
86
- selected={stringToDate(field.value) ?? new Date()}
87
- onSelect={(date) => {
88
- field.onChange(date ? date.toLocaleDateString('pt-BR') : '');
89
- if (onChange) {
90
- onChange({
91
- target: { value: date ? date.toLocaleDateString('pt-BR') : '' },
92
- } as React.ChangeEvent<HTMLInputElement>);
93
- }
94
- setOpen(false);
95
- }}
96
- className='rounded-md'
97
- captionLayout='dropdown'
98
- />
99
- </PopoverContent>
100
- </Popover>
101
- </div>
102
- </div>
103
- </FormControl>
104
- {formMessage(FormMessage)}
105
- </FormItem>
106
- )}
107
- />
108
- );
109
- };
@@ -1,50 +0,0 @@
1
- import * as FormComponents from '../../form';
2
- import { MaskInputDecimal } from '../../input';
3
- import { formHelpText } from './form-help-text';
4
- import { formLabelAndSubLabel } from './form-label';
5
- import { formMessage } from './form-message';
6
-
7
- interface Props {
8
- control: any;
9
- name: string;
10
- label: string;
11
- subLabel?: string;
12
- helpText?: JSX.Element;
13
- className?: string;
14
- disabled?: boolean;
15
- required?: boolean;
16
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
17
- }
18
-
19
- export const FormInputDecimal: React.FC<Props> = ({ control, name, label, subLabel, helpText, className, disabled, required, onChange }) => {
20
- const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
21
-
22
- return (
23
- <FormField
24
- control={control}
25
- name={name}
26
- render={({ field, formState }) => (
27
- <FormItem className={className}>
28
- <div className='flex items-center space-x-1.5'>
29
- {label && formLabelAndSubLabel(FormLabel, label, subLabel, required)}
30
- {helpText && formHelpText(helpText)}
31
- </div>
32
- <FormControl>
33
- <MaskInputDecimal
34
- {...field}
35
- className={`${className}`}
36
- disabled={disabled || formState.isSubmitting}
37
- onChange={(e) => {
38
- field.onChange(e);
39
- if (onChange) {
40
- onChange(e);
41
- }
42
- }}
43
- />
44
- </FormControl>
45
- {formMessage(FormMessage)}
46
- </FormItem>
47
- )}
48
- />
49
- );
50
- };