lecom-ui 4.5.3 → 4.5.4
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/components/Upload/Upload.js +113 -0
- package/dist/index.d.ts +20 -4
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { cn } from '../../lib/utils.js';
|
|
4
|
+
import { ArrowDownToLine, Trash } from 'lucide-react';
|
|
5
|
+
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '../Tooltip/Tooltip.js';
|
|
6
|
+
import { Typography } from '../Typography/Typography.js';
|
|
7
|
+
import { initializeI18n } from '../../i18n/index.js';
|
|
8
|
+
|
|
9
|
+
initializeI18n();
|
|
10
|
+
const Upload = ({
|
|
11
|
+
onFilesSelected,
|
|
12
|
+
className,
|
|
13
|
+
accept,
|
|
14
|
+
multiple
|
|
15
|
+
}) => {
|
|
16
|
+
const [files, setFiles] = React.useState([]);
|
|
17
|
+
const { t } = useTranslation();
|
|
18
|
+
const handleFileChange = (event) => {
|
|
19
|
+
const selectedFiles = event.target.files;
|
|
20
|
+
if (selectedFiles && selectedFiles.length > 0) {
|
|
21
|
+
const newFiles = Array.from(selectedFiles);
|
|
22
|
+
setFiles((prevFiles) => [...prevFiles, ...newFiles]);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const handleDrop = (event) => {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
const droppedFiles = event.dataTransfer.files;
|
|
28
|
+
if (droppedFiles.length > 0) {
|
|
29
|
+
const newFiles = Array.from(droppedFiles);
|
|
30
|
+
setFiles((prevFiles) => [...prevFiles, ...newFiles]);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const handleDownloadFile = (index) => {
|
|
34
|
+
const currentFile = files.find((_, i) => i === index) || {};
|
|
35
|
+
const objectURL = URL.createObjectURL(currentFile);
|
|
36
|
+
const link = document.createElement("a");
|
|
37
|
+
link.download = currentFile.name;
|
|
38
|
+
link.href = objectURL;
|
|
39
|
+
link.click();
|
|
40
|
+
};
|
|
41
|
+
const handleRemoveFile = (index) => {
|
|
42
|
+
setFiles((prevFiles) => prevFiles.filter((_, i) => i !== index));
|
|
43
|
+
};
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
onFilesSelected?.(files);
|
|
46
|
+
}, [files, onFilesSelected]);
|
|
47
|
+
const handleClickUpload = () => {
|
|
48
|
+
if (!hasFile()) {
|
|
49
|
+
document.getElementById("browse")?.click();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const hasFile = () => files.length > 0;
|
|
53
|
+
if (hasFile()) {
|
|
54
|
+
return /* @__PURE__ */ React.createElement(
|
|
55
|
+
"div",
|
|
56
|
+
{
|
|
57
|
+
className: cn(
|
|
58
|
+
"px-4 border border-grey-400 rounded-[4px] w-full h-10 flex items-center",
|
|
59
|
+
className
|
|
60
|
+
)
|
|
61
|
+
},
|
|
62
|
+
files.map((file, index) => /* @__PURE__ */ React.createElement("div", { key: index, className: "flex gap-4 w-full" }, /* @__PURE__ */ React.createElement(
|
|
63
|
+
Typography,
|
|
64
|
+
{
|
|
65
|
+
variant: "body-medium-400",
|
|
66
|
+
textColor: "text-grey-950",
|
|
67
|
+
className: "grow truncate"
|
|
68
|
+
},
|
|
69
|
+
file.name
|
|
70
|
+
), /* @__PURE__ */ React.createElement("div", { className: "flex gap-4 shrink-0" }, /* @__PURE__ */ React.createElement(TooltipProvider, { delayDuration: 0 }, /* @__PURE__ */ React.createElement(Tooltip, null, /* @__PURE__ */ React.createElement(TooltipTrigger, { asChild: true }, /* @__PURE__ */ React.createElement(
|
|
71
|
+
ArrowDownToLine,
|
|
72
|
+
{
|
|
73
|
+
size: 20,
|
|
74
|
+
onClick: () => handleDownloadFile(index),
|
|
75
|
+
className: "text-grey-800 hover:cursor-pointer hover:text-grey-950 transition-all"
|
|
76
|
+
}
|
|
77
|
+
)), /* @__PURE__ */ React.createElement(TooltipContent, { color: "black" }, t("upload.download"))), /* @__PURE__ */ React.createElement(Tooltip, null, /* @__PURE__ */ React.createElement(TooltipTrigger, { asChild: true }, /* @__PURE__ */ React.createElement(
|
|
78
|
+
Trash,
|
|
79
|
+
{
|
|
80
|
+
size: 20,
|
|
81
|
+
onClick: () => handleRemoveFile(index),
|
|
82
|
+
className: "text-grey-800 hover:cursor-pointer hover:text-grey-950 transition-all"
|
|
83
|
+
}
|
|
84
|
+
)), /* @__PURE__ */ React.createElement(TooltipContent, { color: "black" }, t("upload.remove")))))))
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return /* @__PURE__ */ React.createElement(
|
|
88
|
+
"div",
|
|
89
|
+
{
|
|
90
|
+
className: cn(
|
|
91
|
+
"p-4 border border-grey-400 border-dashed rounded-[4px] h-[96px] w-full hover:cursor-pointer hover:border-grey-600 transition-all",
|
|
92
|
+
className
|
|
93
|
+
),
|
|
94
|
+
onDrop: handleDrop,
|
|
95
|
+
onDragOver: (event) => event.preventDefault(),
|
|
96
|
+
onClick: handleClickUpload
|
|
97
|
+
},
|
|
98
|
+
/* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { variant: "body-medium-400", textColor: "text-grey-500" }, t("upload.label")), /* @__PURE__ */ React.createElement(
|
|
99
|
+
"input",
|
|
100
|
+
{
|
|
101
|
+
type: "file",
|
|
102
|
+
hidden: true,
|
|
103
|
+
id: "browse",
|
|
104
|
+
onChange: handleFileChange,
|
|
105
|
+
accept: accept || "*",
|
|
106
|
+
multiple: !!multiple
|
|
107
|
+
}
|
|
108
|
+
))
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
Upload.displayName = "Upload";
|
|
112
|
+
|
|
113
|
+
export { Upload };
|
package/dist/index.d.ts
CHANGED
|
@@ -541,8 +541,8 @@ interface HeaderProps extends React$1.HTMLAttributes<HTMLElement>, VariantProps<
|
|
|
541
541
|
|
|
542
542
|
declare const inputVariants: (props?: ({
|
|
543
543
|
variant?: "default" | "filled" | "borderless" | null | undefined;
|
|
544
|
-
size?: "
|
|
545
|
-
radius?: "
|
|
544
|
+
size?: "small" | "default" | "large" | null | undefined;
|
|
545
|
+
radius?: "small" | "default" | "large" | null | undefined;
|
|
546
546
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
547
547
|
interface InputProps extends Omit<React$1.InputHTMLAttributes<HTMLInputElement>, 'size' | 'sufix' | 'prefix'>, VariantProps<typeof inputVariants> {
|
|
548
548
|
sufix?: React$1.ReactNode;
|
|
@@ -746,6 +746,22 @@ type SidebarContext = {
|
|
|
746
746
|
declare const SidebarContext: React$1.Context<SidebarContext | null>;
|
|
747
747
|
declare function useSidebar(): SidebarContext;
|
|
748
748
|
|
|
749
|
+
interface File {
|
|
750
|
+
name: string;
|
|
751
|
+
size: number;
|
|
752
|
+
type: string;
|
|
753
|
+
}
|
|
754
|
+
interface UploadProps {
|
|
755
|
+
onFilesSelected?: (files: File[]) => void;
|
|
756
|
+
className?: string;
|
|
757
|
+
accept?: string;
|
|
758
|
+
multiple?: boolean;
|
|
759
|
+
}
|
|
760
|
+
declare const Upload: {
|
|
761
|
+
({ onFilesSelected, className, accept, multiple, }: UploadProps): React$1.JSX.Element;
|
|
762
|
+
displayName: string;
|
|
763
|
+
};
|
|
764
|
+
|
|
749
765
|
declare function useIsMobile(): boolean;
|
|
750
766
|
|
|
751
767
|
declare enum Translations {
|
|
@@ -768,5 +784,5 @@ declare const fonts: {
|
|
|
768
784
|
ibm: string[];
|
|
769
785
|
};
|
|
770
786
|
|
|
771
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Button, CadastroFacil, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, DataTable, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, ErrorEmptyDisplay, Input, Layout, LogoLecom, LogoLecomBrand, ModoTeste, Notification, Pagination, PaginationContent, PaginationEllipsis, PaginationFirst, PaginationIndex, PaginationItem, PaginationLast, PaginationNext, PaginationPrevious, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, Rpa, ScrollArea, ScrollBar, Skeleton, Spin, Switch, TOAST_REMOVE_DELAY, Tag, Tooltip, TooltipArrow, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger, Translations, TypeMessageNotification, Typography, accordionVariants, buttonVariants, colors, fonts, getPositionClass, initializeI18n, inputVariants, notificationVariants, reducer, tagVariants, toast, typographyVariants, useIsMobile, useNotificationToast, usePagination, useSidebar };
|
|
772
|
-
export type { BgColor, BuildCellSelect, BuildColumns, BuildHeaderSelect, ButtonProps, CadastroFacilProps, CalloutNotificationProps, CheckboxProps, CheckedCell, CheckedCellChange, CheckedHeader, CheckedHeaderChange, Color, ColorToken, Column, ColumnRender, ColumnSort, ColumnTitle, CustomStyles$1 as CustomStyles, DataTableProps, ErrorEmptyDisplayProps, FillColor, Fonts, Header, HeaderProps, InlineNotificationProps, InputProps, LayoutProps, LogoLecomBrandProps, LogoLecomProps, Meta, ModoTesteProps, NotificationProps, PaginationProps, Row, RpaProps, SideBarProps, SpinProps, TagProps, TextColor, ToastNotificationProps, ToasterToast, TooltipContentProps, TypographyProps, UsePaginationItem };
|
|
787
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Button, CadastroFacil, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, DataTable, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, ErrorEmptyDisplay, Input, Layout, LogoLecom, LogoLecomBrand, ModoTeste, Notification, Pagination, PaginationContent, PaginationEllipsis, PaginationFirst, PaginationIndex, PaginationItem, PaginationLast, PaginationNext, PaginationPrevious, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, Rpa, ScrollArea, ScrollBar, Skeleton, Spin, Switch, TOAST_REMOVE_DELAY, Tag, Tooltip, TooltipArrow, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger, Translations, TypeMessageNotification, Typography, Upload, accordionVariants, buttonVariants, colors, fonts, getPositionClass, initializeI18n, inputVariants, notificationVariants, reducer, tagVariants, toast, typographyVariants, useIsMobile, useNotificationToast, usePagination, useSidebar };
|
|
788
|
+
export type { BgColor, BuildCellSelect, BuildColumns, BuildHeaderSelect, ButtonProps, CadastroFacilProps, CalloutNotificationProps, CheckboxProps, CheckedCell, CheckedCellChange, CheckedHeader, CheckedHeaderChange, Color, ColorToken, Column, ColumnRender, ColumnSort, ColumnTitle, CustomStyles$1 as CustomStyles, DataTableProps, ErrorEmptyDisplayProps, FillColor, Fonts, Header, HeaderProps, InlineNotificationProps, InputProps, LayoutProps, LogoLecomBrandProps, LogoLecomProps, Meta, ModoTesteProps, NotificationProps, PaginationProps, Row, RpaProps, SideBarProps, SpinProps, TagProps, TextColor, ToastNotificationProps, ToasterToast, TooltipContentProps, TypographyProps, UploadProps, UsePaginationItem };
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export { RadioGroup, RadioGroupItem } from './components/RadioGroup/RadioGroup.j
|
|
|
26
26
|
export { ScrollArea, ScrollBar } from './components/ScrollArea/ScrollArea.js';
|
|
27
27
|
export { Spin } from './components/Spin/Spin.js';
|
|
28
28
|
export { useSidebar } from './components/Sidebar/Sidebar.js';
|
|
29
|
+
export { Upload } from './components/Upload/Upload.js';
|
|
29
30
|
export { useIsMobile } from './hooks/useIsMobile.js';
|
|
30
31
|
export { usePagination } from './hooks/usePagination.js';
|
|
31
32
|
export { Translations, initializeI18n } from './i18n/index.js';
|