import { Upload } from 'sud-ui';하나 이상의 파일을 업로드할 때.
드래그 앤 드롭 방식으로 파일을 업로드할 때.
import { Upload, Button } from "sud-ui";
import { Upload as UploadIcon } from "sud-icons";
import React from "react";
export default function App() {
return (
<Upload>
<Button icon={<UploadIcon size={16} />}>File Upload</Button>
</Upload>
);
}import { Upload, Button } from "sud-ui";
import { Upload as UploadIcon } from "sud-icons";
import React from "react";
const allowedExtensions = ["png", "jpg"];
export default function App() {
return (
<Upload multiple ext={allowedExtensions}>
<Button icon={<UploadIcon size={16} />}>Specific File Type Upload</Button>
</Upload>
);
}import { Upload, Button } from "sud-ui";
import { Upload as UploadIcon } from "sud-icons";
import React from "react";
export default function App() {
return (
<Upload disabled>
<Button icon={<UploadIcon size={16} />} disabled>
Disabled
</Button>
</Upload>
);
}import { Upload, Card, Typography } from "sud-ui";
import React, { useState } from "react";
export default function App() {
const [isDragging, setIsDragging] = useState(false);
return (
<Upload
listType="text"
drag
onDrag={(isDrag) => {
setIsDragging(isDrag);
}}
>
<Card
style={{ width: "100%" }}
shadow="none"
borderType="dashed"
borderWeight={2}
borderColor={isDragging ? "sky-6" : "cool-gray-3"}
background={isDragging ? "sky-2" : "cool-gray-1"}
color={isDragging ? "sky-8" : "cool-gray-7"}
>
<div className="flex flex-col gap-[10px] justify-center items-center">
<Typography suite="H" size="lg">
Drag & Drop
</Typography>
<Typography color="cool-gray-5">
You can upload files using the drag and drop method.
</Typography>
</div>
</Card>
</Upload>
);
}import { Upload, Card, Typography } from "sud-ui";
import { Plus } from "sud-icons";
import React, { useState } from "react";
export default function App() {
const [isLoading, setIsLoading] = useState(false);
const [loadingImg, setLoadingImg] = useState(null);
const handleLoading = (img) => {
setLoadingImg(null);
setIsLoading(true);
setTimeout(() => {
setIsLoading(false);
setLoadingImg(URL.createObjectURL(img));
}, 3000);
};
return (
<Upload
listType="none"
onChange={(img) => {
handleLoading(img);
}}
>
{loadingImg ? (
<Image
shape="rounded"
src={loadingImg}
alt="profile"
width={150}
height={150}
preview={false}
mask={
<div className="flex flex-col gap-[10px] justify-center items-center text-center">
<Typography>Profile Update</Typography>
</div>
}
/>
) : (
<Card
shadow="none"
borderType="dashed"
borderWeight={2}
background="cool-gray-1"
width={150}
height={150}
className="justify-center items-center"
>
<div className="flex flex-col gap-[10px] justify-center items-center">
{isLoading ? (
<DotSpinner text="Uploading..." />
) : (
<>
<Plus />
<Typography>Upload</Typography>
</>
)}
</div>
</Card>
)}
</Upload>
);
}import { Upload, Button } from "sud-ui";
import { Upload as UploadIcon } from "sud-icons";
import React from "react";
export default function App() {
return (
<Upload multiple maxCount={3}>
<Button icon={<UploadIcon size={16} />}>Multiple File Upload</Button>
</Upload>
);
}import { Upload, Button } from "sud-ui";
import { Upload as UploadIcon } from "sud-icons";
import React from "react";
const MAX_FILE_SIZE = 1024 * 1024 * 5; // 5MB
export default function App() {
return (
<Upload multiple maxFileSize={MAX_FILE_SIZE}>
<Button icon={<UploadIcon size={16} />}>File Size Limit</Button>
</Upload>
);
}import { Upload, Button, Card, Radio } from "sud-ui";
import { Upload as UploadIcon } from "sud-icons";
import React, { useState } from "react";
const listTypeOptions = [
{ label: "text", value: "text" },
{ label: "thumbnail", value: "thumbnail" },
{ label: "card", value: "card" },
{ label: "none", value: "none" }
];
export default function App() {
const [listType, setListType] = useState("text");
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center w-full">
<Radio.Group
options={listTypeOptions}
direction="horizontal"
value={listType}
onChange={setListType}
/>
</div>
</Card>
<Upload
listType={listType}
multiple
listDirection={listType === "card" ? "row" : "column"}
>
<Button icon={<UploadIcon size={16} />}>File Upload</Button>
</Upload>
</div>
);
}import { Upload, Card, Typography, Image } from "sud-ui";
import { Plus } from "sud-icons";
import React, { useState } from "react";
export default function App() {
const [hasProfile, setHasProfile] = useState(false);
const [profile, setProfile] = useState(null);
return (
<Upload
listType="none"
onChange={(img) => {
if (img) {
setHasProfile(true);
setProfile(URL.createObjectURL(img));
} else {
setHasProfile(false);
setProfile(null);
}
}}
>
{hasProfile ? (
<Image
shape="circle"
src={profile}
alt="profile"
width={150}
height={150}
preview={false}
mask={
<div className="flex flex-col gap-[10px] justify-center items-center text-center">
<Typography>Profile Update</Typography>
</div>
}
/>
) : (
<Card
shadow="none"
borderType="dashed"
borderWeight={2}
background="cool-gray-1"
shape="circle"
width={150}
height={150}
className="justify-center items-center"
>
<div className="flex flex-col gap-[10px] justify-center items-center p-[10px]">
<Plus />
<Typography>Upload</Typography>
</div>
</Card>
)}
</Upload>
);
}import { Upload, Button, Card, Typography } from "sud-ui";
import { TrashOutline, Upload as UploadIcon } from "sud-icons";
import React, { useState } from "react";
export default function App() {
const [fileList, setFileList] = useState([]);
return (
<div className="flex flex-col gap-[20px]">
<Upload
listType="none"
onChange={(files) => {
setFileList(files);
}}
multiple
>
<Button icon={<UploadIcon size={16} />}>File Upload</Button>
</Upload>
<div className="flex flex-col gap-[10px] w-full">
{fileList.map((file, index) => (
<Card
key={`${file.name}-${index}`}
shadow="none"
colorType="sub"
className="flex justify-between items-center p-[10px]"
>
<div className="flex flex-col gap-[5px]">
<Typography>{file.name}</Typography>
<Typography size="sm" color="cool-gray-5">
{(file.size / 1024).toFixed(2)} KB
</Typography>
</div>
<Button
icon={<TrashOutline size={16} />}
colorType="danger"
onClick={() => {
setFileList(fileList.filter((f) => f.name !== file.name));
}}
>
Delete
</Button>
</Card>
))}
</div>
</div>
);
}속성 이름 | 설명 | 타입 | 기본값 |
|---|
| listType | 파일 목록 표시 타입 | text | thumbnail | card | none | text |
| ext | 허용할 파일 확장자 | string[] | - |
| multiple | 다중 파일 업로드 여부 | boolean | false |
| maxCount | 최대 파일 개수 | number | - |
| maxFileSize | 최대 파일 크기 (bytes) | number | - |
| disabled | 비활성화 여부 | boolean | false |
| fileList | 파일 목록 | File[] | [] |
| showUploadList | 파일 목록 표시 여부 | boolean | true |
| onChange | 파일 변경 시 호출되는 함수 | (files: File | File[]) => void | - |
| onRemove | 파일 제거 시 호출되는 함수 | (files: File[]) => void | - |
| onDrag | 드래그 상태 변경 시 호출되는 함수 | (isDragging: boolean) => void | - |
| listColorType | 파일 목록 색상 타입 | default | red | rose | coral | orange | volcano | apricot | yellow | gold | amber | green | lime | mint | blue | sky | cerulean | indigo | cobalt | navy | purple | plum | orchid | forest | sage | warm-gray | cool-gray | neutral | default |
| listErrorColorType | 파일 목록 에러 색상 타입 | 위와 동일 | red |
| listHoverColorType | 파일 목록 호버 색상 타입 | 위와 동일 | sky |
| listDeleteColorType | 파일 목록 삭제 색상 타입 | 위와 동일 | coral |
| listDirection | 파일 목록 방향 | row | column | column |
| thumbnailSize | 썸네일 크기 | number | 50 |
| cardSize | 카드 크기 | number | 200 |
| drag | 드래그 앤 드롭 활성화 여부 | boolean | false |
| className | 추가 클래스명 | string | - |
| ariaLabel | ARIA 라벨 | string | - |
| role | ARIA 역할 | string | button |