eai-frontend-components 2.0.17 → 2.0.18

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
@@ -37,6 +37,7 @@ var SliderPrimitive = require('@radix-ui/react-slider');
37
37
  var SwitchPrimitives = require('@radix-ui/react-switch');
38
38
  var TabsPrimitive = require('@radix-ui/react-tabs');
39
39
  var ToastPrimitives = require('@radix-ui/react-toast');
40
+ var reactColorful = require('react-colorful');
40
41
  var reactTable = require('@tanstack/react-table');
41
42
  var zod$1 = require('@hookform/resolvers/zod');
42
43
  var zod = require('zod');
@@ -2557,6 +2558,130 @@ const formMessage = (FormMessage) => {
2557
2558
  return jsxRuntime.jsx(FormMessage, { className: 'text-red-600 mt-1' });
2558
2559
  };
2559
2560
 
2561
+ const FormInputCheckbox = ({ control, name, label, helpText, className, disabled, onCheckedChange }) => {
2562
+ const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
2563
+ return (jsxRuntime.jsx(FormField, { control: control, name: name, render: ({ field }) => (jsxRuntime.jsxs(FormItem, { className: className, children: [jsxRuntime.jsxs("div", { className: 'flex items-center gap-2', children: [jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Checkbox, { value: field.value, className: `${field.value
2564
+ ? 'bg-purple-700 border border-purple-900 text-white rounded-[3px]'
2565
+ : 'bg-white border border-black text-black'}`, onCheckedChange: (checked) => {
2566
+ field?.onChange?.(checked);
2567
+ onCheckedChange?.(checked);
2568
+ }, disabled: disabled }) }), jsxRuntime.jsxs("div", { className: 'flex h-full items-center space-x-1.5', children: [label && formLabel(FormLabel, label), helpText && formHelpText(helpText)] })] }), formMessage(FormMessage)] })) }));
2569
+ };
2570
+
2571
+ const rgbToHex = ({ r, g, b }) => {
2572
+ const toHex = (n) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0').toUpperCase();
2573
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
2574
+ };
2575
+ const hexToRgb = (hex) => {
2576
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
2577
+ return result
2578
+ ? {
2579
+ r: Number.parseInt(result[1], 16),
2580
+ g: Number.parseInt(result[2], 16),
2581
+ b: Number.parseInt(result[3], 16),
2582
+ }
2583
+ : null;
2584
+ };
2585
+
2586
+ const FormInputColor = ({ control, name, label, subLabel, helpText, placeholder, className, disabled, required }) => {
2587
+ const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
2588
+ const DEFAULT_COLOR = '#000000';
2589
+ const [currentColor, setCurrentColor] = React.useState(DEFAULT_COLOR);
2590
+ const rgb = hexToRgb(currentColor) || { r: 0, g: 0, b: 0 };
2591
+ const handleColorChange = (newColor, onChange) => {
2592
+ onChange?.(newColor);
2593
+ setCurrentColor(newColor);
2594
+ };
2595
+ const handleHexChange = (hex, onChange) => {
2596
+ if (/^#[0-9A-Fa-f]{6}$/.test(hex)) {
2597
+ handleColorChange(hex, onChange);
2598
+ }
2599
+ else {
2600
+ setCurrentColor(hex);
2601
+ }
2602
+ };
2603
+ const handleRgbChange = (key, value, onChange) => {
2604
+ const numValue = Number.parseInt(value);
2605
+ if (!Number.isNaN(numValue) && numValue >= 0 && numValue <= 255) {
2606
+ const newRgb = { ...rgb, [key]: numValue };
2607
+ handleColorChange(rgbToHex(newRgb), onChange);
2608
+ }
2609
+ };
2610
+ return (jsxRuntime.jsx(FormField, { control: control, name: name, render: ({ field, formState }) => (jsxRuntime.jsxs(FormItem, { className: className, children: [jsxRuntime.jsxs("div", { className: 'flex items-center space-x-1.5', children: [label && formLabelAndSubLabel(FormLabel, label, subLabel, required), helpText && formHelpText(helpText)] }), jsxRuntime.jsxs(Popover, { children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Button, { variant: 'outline', className: cn('w-[240px] justify-start text-left font-normal', !field.value && 'text-zinc-500', className), disabled: disabled || formState.isSubmitting, children: jsxRuntime.jsxs("div", { className: 'w-full flex items-center gap-2', children: [field.value ? (jsxRuntime.jsx("div", { className: 'h-4 w-4 rounded !bg-center !bg-cover transition-all border', style: { backgroundColor: field.value } })) : (jsxRuntime.jsx(lucideReact.Paintbrush, { className: 'h-4 w-4' })), jsxRuntime.jsx("div", { className: 'truncate flex-1 text-sm', children: field.value ? field.value : placeholder || 'Selecione uma cor' })] }) }) }) }), jsxRuntime.jsx(PopoverContent, { className: cn('w-80', className), children: jsxRuntime.jsxs("div", { className: 'flex flex-col gap-4', children: [jsxRuntime.jsx("section", { className: '[&_.react-colorful]:w-auto', children: jsxRuntime.jsx(reactColorful.HexColorPicker, { color: field.value ?? DEFAULT_COLOR, onChange: (newColor) => handleColorChange(newColor, field.onChange) }) }), jsxRuntime.jsxs("div", { className: 'flex gap-2', children: [jsxRuntime.jsxs("div", { className: 'flex flex-col gap-1', children: [jsxRuntime.jsx(Label, { children: "Hex" }), jsxRuntime.jsx(Input, { value: currentColor, onChange: (e) => handleHexChange(e.target.value, field.onChange), maxLength: 7 })] }), jsxRuntime.jsxs("div", { className: 'flex gap-2', children: [jsxRuntime.jsxs("div", { className: 'flex flex-col gap-1', children: [jsxRuntime.jsx(Label, { children: "R" }), jsxRuntime.jsx(Input, { value: rgb.r, onChange: (e) => handleRgbChange('r', e.target.value, field.onChange), className: 'w-14' })] }), jsxRuntime.jsxs("div", { className: 'flex flex-col gap-1', children: [jsxRuntime.jsx(Label, { children: "G" }), jsxRuntime.jsx(Input, { value: rgb.g, onChange: (e) => handleRgbChange('g', e.target.value, field.onChange), className: 'w-14' })] }), jsxRuntime.jsxs("div", { className: 'flex flex-col gap-1', children: [jsxRuntime.jsx(Label, { children: "B" }), jsxRuntime.jsx(Input, { value: rgb.b, onChange: (e) => handleRgbChange('b', e.target.value, field.onChange), className: 'w-14' })] })] })] })] }) })] }), formMessage(FormMessage)] })) }));
2611
+ };
2612
+
2613
+ const FormCombobox = ({ control, name, label, subLabel, helpText, placeholder, className, disabled, required, options, selectedOption, iconLeft, iconRight, addEmptyOption, canUnselect = false, closePopUpOnChange = true, runInternalSearch = true, disabledSearch = false, onChange, onSearch, footerAction, }) => {
2614
+ const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
2615
+ const [open, setOpen] = React.useState(false);
2616
+ const [loading, setLoading] = React.useState(false);
2617
+ const [searchString, setSearchString] = React.useState('');
2618
+ const DEFAULT_PLACEHOLDER = 'Digite para buscar...';
2619
+ React.useEffect(() => {
2620
+ setLoading(false);
2621
+ }, [options]);
2622
+ const getOptions = () => {
2623
+ if (options.length === 0) {
2624
+ return [];
2625
+ }
2626
+ let filteredOptions = options;
2627
+ if (runInternalSearch) {
2628
+ filteredOptions = options.filter((option) => {
2629
+ const title = option.title
2630
+ .toLowerCase()
2631
+ .normalize('NFD')
2632
+ .replace(/[^a-z0-9\s]/gi, '');
2633
+ const subTitle = option.subTitle
2634
+ ?.toLowerCase()
2635
+ .normalize('NFD')
2636
+ .replace(/[^a-z0-9\s]/gi, '');
2637
+ const search = searchString
2638
+ .toLowerCase()
2639
+ .normalize('NFD')
2640
+ .replace(/[^a-z0-9\s]/gi, '');
2641
+ return title.includes(search) || subTitle?.includes(search);
2642
+ });
2643
+ }
2644
+ if (addEmptyOption) {
2645
+ filteredOptions.unshift({ value: undefined, title: '--Selecione--', subTitle: '' });
2646
+ }
2647
+ return filteredOptions;
2648
+ };
2649
+ const getSelectedOption = (value) => {
2650
+ const option = options.find((option) => option.value === value);
2651
+ if (option) {
2652
+ return option;
2653
+ }
2654
+ return selectedOption;
2655
+ };
2656
+ const handleSelect = (value, field) => {
2657
+ const option = value ? getSelectedOption(value) : undefined;
2658
+ if (canUnselect) {
2659
+ field.onChange(field.value === value ? undefined : value);
2660
+ }
2661
+ else {
2662
+ field.onChange(value);
2663
+ }
2664
+ if (onChange) {
2665
+ onChange(option);
2666
+ }
2667
+ if (closePopUpOnChange) {
2668
+ setOpen(false);
2669
+ }
2670
+ };
2671
+ const handleKeyUp = (event) => {
2672
+ const searchString = event.target.value;
2673
+ if (onSearch) {
2674
+ setLoading(true);
2675
+ onSearch(searchString);
2676
+ }
2677
+ setSearchString(searchString);
2678
+ };
2679
+ return (jsxRuntime.jsx(FormField, { control: control, name: name, render: ({ field, formState }) => (jsxRuntime.jsxs(FormItem, { className: className, children: [jsxRuntime.jsxs("div", { className: 'flex items-center space-x-1.5', children: [label && formLabelAndSubLabel(FormLabel, label, subLabel, required), helpText && formHelpText(helpText)] }), jsxRuntime.jsxs(Popover, { open: open, onOpenChange: (open) => {
2680
+ if (!disabled)
2681
+ setOpen(open);
2682
+ }, children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx("div", { className: cn(`rounded-sm outline-none ${open ? 'ring-2 ring-ring ring-offset-2' : 'ring-0'}`, className), children: jsxRuntime.jsxs(Button, { type: 'button', variant: 'outline', role: 'combobox', "aria-expanded": open, className: cn('justify-between disabled:border-disabled disabled:cursor-not-allowed disabled:opacity-50', formState.errors[name] ? 'border-red-600' : '', className), disabled: disabled || formState.isSubmitting, children: [iconLeft, jsxRuntime.jsx("div", { className: 'grid flex-1 text-left text-sm leading-tight', children: jsxRuntime.jsx("span", { className: 'truncate font-normal', children: getSelectedOption(field.value) ? (jsxRuntime.jsxs("div", { className: 'flex gap-2', children: [getSelectedOption(field.value)?.icon, getSelectedOption(field.value)?.title] })) : (jsxRuntime.jsx("span", { className: 'text-zinc-500', children: placeholder ?? DEFAULT_PLACEHOLDER })) }) }), iconRight ?? jsxRuntime.jsx(lucideReact.ChevronsUpDown, { size: 20, className: 'stroke-zinc-500' })] }) }) }) }), jsxRuntime.jsxs(PopoverContent, { className: cn('p-0', className, 'w-[--radix-popover-trigger-width]'), children: [jsxRuntime.jsxs(Command, { shouldFilter: false, children: [!disabledSearch && jsxRuntime.jsx(CommandInput, { placeholder: placeholder ?? DEFAULT_PLACEHOLDER, onKeyUp: handleKeyUp }), jsxRuntime.jsxs(CommandList, { children: [jsxRuntime.jsx(CommandEmpty, { className: 'flex flex-col justify-between items-center p-3 font-normal text-sm', children: loading ? (jsxRuntime.jsx(lucideReact.LoaderCircle, { size: 16, className: 'text-muted-foreground animate-spin mr-2' })) : getOptions()?.length === 0 && (searchString !== '' || disabledSearch) ? ('Nenhum resultado encontrado') : ('Utilize o campo de busca acima') }), options.length > 0 && (jsxRuntime.jsx(CommandGroup, { children: getOptions().map((option) => (jsxRuntime.jsxs(CommandItem, { value: option.value, className: 'group', onSelect: () => handleSelect(option.value, field), children: [jsxRuntime.jsxs("div", { className: cn('grid flex-1 text-left text-sm leading-tight', option.className), children: [jsxRuntime.jsxs("div", { className: 'flex gap-2', children: [option.icon, jsxRuntime.jsx("span", { className: 'truncate font-normal', children: option.title })] }), jsxRuntime.jsx("span", { className: 'truncate text-xs text-zinc-500', children: option.subTitle })] }), jsxRuntime.jsxs("div", { className: `ml-auto text-zinc-500 ${field.value === option.value ? 'opacity-100' : 'opacity-0'}`, children: [jsxRuntime.jsx(lucideReact.Check, { className: cn('flex', canUnselect && 'group-hover:hidden hover:hidden'), size: 16 }), jsxRuntime.jsx(lucideReact.X, { className: cn('hidden', canUnselect && 'group-hover:flex hover:flex'), size: 16 })] })] }, `key-opt-${option.value}`))) }))] })] }), footerAction && (jsxRuntime.jsx("div", { className: 'grid w-full p-1 border-t', children: jsxRuntime.jsxs(Button, { type: 'button', variant: 'ghost', className: 'h-8', onClick: () => footerAction.onClick(), children: [footerAction.icon, footerAction.label] }) }))] })] }), formMessage(FormMessage)] })) }));
2683
+ };
2684
+
2560
2685
  const masks$1 = ['999.999.999-999', '99.999.999/9999-99'];
2561
2686
  const FormInputCpfCnpj = ({ control, name, label, subLabel, helpText, placeholder, className, disabled, required, onChange, onKeyUp, }) => {
2562
2687
  const { FormField, FormItem, FormLabel, FormControl, FormMessage } = FormComponents;
@@ -3399,11 +3524,14 @@ exports.DropdownMenuSubContent = DropdownMenuSubContent;
3399
3524
  exports.DropdownMenuSubTrigger = DropdownMenuSubTrigger;
3400
3525
  exports.DropdownMenuTrigger = DropdownMenuTrigger;
3401
3526
  exports.Form = Form;
3527
+ exports.FormCombobox = FormCombobox;
3402
3528
  exports.FormControl = FormControl;
3403
3529
  exports.FormDataRange = FormDataRange;
3404
3530
  exports.FormDescription = FormDescription;
3405
3531
  exports.FormField = FormField;
3406
3532
  exports.FormInput = FormInput;
3533
+ exports.FormInputCheckbox = FormInputCheckbox;
3534
+ exports.FormInputColor = FormInputColor;
3407
3535
  exports.FormInputCpfCnpj = FormInputCpfCnpj;
3408
3536
  exports.FormInputCurrency = FormInputCurrency;
3409
3537
  exports.FormInputDate = FormInputDate;