@poodle-kit/ui 0.1.0 → 0.3.0
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/LICENSE +21 -0
- package/README.md +148 -0
- package/dist/components/image-uploader/image-uploader.d.mts +4 -0
- package/dist/components/image-uploader/image-uploader.d.ts +4 -0
- package/dist/components/image-uploader/image-uploader.js +471 -0
- package/dist/components/image-uploader/image-uploader.js.map +1 -0
- package/dist/components/image-uploader/image-uploader.mjs +452 -0
- package/dist/components/image-uploader/image-uploader.mjs.map +1 -0
- package/dist/image-uploader-BFvQ4s0a.d.mts +100 -0
- package/dist/image-uploader-BFvQ4s0a.d.ts +100 -0
- package/dist/index.css +557 -49
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +84 -13
- package/dist/index.d.ts +84 -13
- package/dist/index.js +976 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +975 -33
- package/dist/index.mjs.map +1 -1
- package/dist/lib/cn.d.mts +5 -0
- package/dist/lib/cn.d.ts +5 -0
- package/dist/lib/cn.js +35 -0
- package/dist/lib/cn.js.map +1 -0
- package/dist/lib/cn.mjs +10 -0
- package/dist/lib/cn.mjs.map +1 -0
- package/dist/theme/index.d.mts +287 -0
- package/dist/theme/index.d.ts +287 -0
- package/dist/theme/index.js +386 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/index.mjs +355 -0
- package/dist/theme/index.mjs.map +1 -0
- package/dist/theme/theme.css +110 -0
- package/package.json +27 -9
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
4
|
+
import { VariantProps } from 'class-variance-authority';
|
|
5
|
+
|
|
6
|
+
/** 서버에서 받은 기존 이미지 */
|
|
7
|
+
interface ExistingImage {
|
|
8
|
+
id: number | string;
|
|
9
|
+
url: string;
|
|
10
|
+
/** 이미지 순서 (정렬에 사용) */
|
|
11
|
+
sequence?: number;
|
|
12
|
+
}
|
|
13
|
+
/** 새로 선택한 파일 (미리보기 포함) */
|
|
14
|
+
interface NewImageFile {
|
|
15
|
+
file: File;
|
|
16
|
+
/** `URL.createObjectURL()` 로 생성된 미리보기 URL */
|
|
17
|
+
preview: string;
|
|
18
|
+
/** React key / 삭제 식별자 */
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
/** 유효성 검사 에러 Union 타입 */
|
|
22
|
+
type ImageUploaderError = {
|
|
23
|
+
type: 'MAX_IMAGES';
|
|
24
|
+
message: string;
|
|
25
|
+
maxImages: number;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'MAX_SIZE';
|
|
28
|
+
message: string;
|
|
29
|
+
maxSizeMb: number;
|
|
30
|
+
file: File;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'INVALID_TYPE';
|
|
33
|
+
message: string;
|
|
34
|
+
file: File;
|
|
35
|
+
accept: string;
|
|
36
|
+
};
|
|
37
|
+
interface UseImageUploaderOptions {
|
|
38
|
+
/** 수정 모드에서 서버 이미지를 전달해요 */
|
|
39
|
+
initialImages?: ExistingImage[];
|
|
40
|
+
/** 최대 업로드 가능 이미지 수 (기본값: 4) */
|
|
41
|
+
maxImages?: number;
|
|
42
|
+
/** 파일 1개의 최대 크기 (MB). 미설정 시 제한 없음 */
|
|
43
|
+
maxSizeMb?: number;
|
|
44
|
+
/** 허용할 파일 형식 (기본값: 'image/*') */
|
|
45
|
+
accept?: string;
|
|
46
|
+
/** 현재 선택된 전체 File[] 배열이 변경될 때 호출돼요 */
|
|
47
|
+
onFileSelect?: (files: File[]) => void;
|
|
48
|
+
/** 기존 이미지가 삭제될 때 삭제된 id 배열을 전달해요 */
|
|
49
|
+
onDeleteExisting?: (deletedIds: Array<number | string>) => void;
|
|
50
|
+
/** 유효성 검사 실패 시 호출돼요 (toast 등 직접 처리) */
|
|
51
|
+
onError?: (error: ImageUploaderError) => void;
|
|
52
|
+
}
|
|
53
|
+
interface UseImageUploaderReturn {
|
|
54
|
+
/** 삭제되지 않은 기존 이미지 */
|
|
55
|
+
existingImages: ExistingImage[];
|
|
56
|
+
/** 새로 선택한 이미지 (미리보기 포함) */
|
|
57
|
+
newImages: NewImageFile[];
|
|
58
|
+
/** 기존 + 새 이미지 합산 개수 */
|
|
59
|
+
totalCount: number;
|
|
60
|
+
/** 드래그 활성 여부 */
|
|
61
|
+
isDragActive: boolean;
|
|
62
|
+
/** 파일 input 요소의 ref */
|
|
63
|
+
inputRef: react__default.RefObject<HTMLInputElement>;
|
|
64
|
+
/** 파일 선택 다이얼로그 열기 */
|
|
65
|
+
openFilePicker: () => void;
|
|
66
|
+
/** 기존 이미지 삭제 */
|
|
67
|
+
removeExisting: (id: number | string) => void;
|
|
68
|
+
/** 새로 선택한 이미지 삭제 */
|
|
69
|
+
removeNew: (id: string) => void;
|
|
70
|
+
/** drop zone에 spread할 drag 이벤트 핸들러 */
|
|
71
|
+
dragHandlers: {
|
|
72
|
+
onDragOver: react__default.DragEventHandler;
|
|
73
|
+
onDragLeave: react__default.DragEventHandler;
|
|
74
|
+
onDrop: react__default.DragEventHandler;
|
|
75
|
+
};
|
|
76
|
+
/** file input에 spread할 props */
|
|
77
|
+
inputProps: {
|
|
78
|
+
onChange: react__default.ChangeEventHandler<HTMLInputElement>;
|
|
79
|
+
accept: string;
|
|
80
|
+
multiple: boolean;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
declare function useImageUploader({ initialImages, maxImages, maxSizeMb, accept, onFileSelect, onDeleteExisting, onError, }: UseImageUploaderOptions): UseImageUploaderReturn;
|
|
84
|
+
|
|
85
|
+
declare const imageUploaderVariants: (props?: ({
|
|
86
|
+
layout?: "grid" | "row" | null | undefined;
|
|
87
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
88
|
+
interface ImageUploaderProps extends UseImageUploaderOptions, VariantProps<typeof imageUploaderVariants> {
|
|
89
|
+
className?: string;
|
|
90
|
+
/** true이면 모든 인터랙션을 비활성화해요 */
|
|
91
|
+
disabled?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* 이미지 추가 버튼의 내용을 교체할 수 있어요.
|
|
94
|
+
* 기본값은 + 아이콘과 현재/최대 개수를 표시해요.
|
|
95
|
+
*/
|
|
96
|
+
placeholder?: ReactNode;
|
|
97
|
+
}
|
|
98
|
+
declare const ImageUploader: react.ForwardRefExoticComponent<ImageUploaderProps & react.RefAttributes<HTMLDivElement>>;
|
|
99
|
+
|
|
100
|
+
export { type ExistingImage as E, ImageUploader as I, type NewImageFile as N, type UseImageUploaderOptions as U, type ImageUploaderError as a, type ImageUploaderProps as b, type UseImageUploaderReturn as c, imageUploaderVariants as i, useImageUploader as u };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
4
|
+
import { VariantProps } from 'class-variance-authority';
|
|
5
|
+
|
|
6
|
+
/** 서버에서 받은 기존 이미지 */
|
|
7
|
+
interface ExistingImage {
|
|
8
|
+
id: number | string;
|
|
9
|
+
url: string;
|
|
10
|
+
/** 이미지 순서 (정렬에 사용) */
|
|
11
|
+
sequence?: number;
|
|
12
|
+
}
|
|
13
|
+
/** 새로 선택한 파일 (미리보기 포함) */
|
|
14
|
+
interface NewImageFile {
|
|
15
|
+
file: File;
|
|
16
|
+
/** `URL.createObjectURL()` 로 생성된 미리보기 URL */
|
|
17
|
+
preview: string;
|
|
18
|
+
/** React key / 삭제 식별자 */
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
/** 유효성 검사 에러 Union 타입 */
|
|
22
|
+
type ImageUploaderError = {
|
|
23
|
+
type: 'MAX_IMAGES';
|
|
24
|
+
message: string;
|
|
25
|
+
maxImages: number;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'MAX_SIZE';
|
|
28
|
+
message: string;
|
|
29
|
+
maxSizeMb: number;
|
|
30
|
+
file: File;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'INVALID_TYPE';
|
|
33
|
+
message: string;
|
|
34
|
+
file: File;
|
|
35
|
+
accept: string;
|
|
36
|
+
};
|
|
37
|
+
interface UseImageUploaderOptions {
|
|
38
|
+
/** 수정 모드에서 서버 이미지를 전달해요 */
|
|
39
|
+
initialImages?: ExistingImage[];
|
|
40
|
+
/** 최대 업로드 가능 이미지 수 (기본값: 4) */
|
|
41
|
+
maxImages?: number;
|
|
42
|
+
/** 파일 1개의 최대 크기 (MB). 미설정 시 제한 없음 */
|
|
43
|
+
maxSizeMb?: number;
|
|
44
|
+
/** 허용할 파일 형식 (기본값: 'image/*') */
|
|
45
|
+
accept?: string;
|
|
46
|
+
/** 현재 선택된 전체 File[] 배열이 변경될 때 호출돼요 */
|
|
47
|
+
onFileSelect?: (files: File[]) => void;
|
|
48
|
+
/** 기존 이미지가 삭제될 때 삭제된 id 배열을 전달해요 */
|
|
49
|
+
onDeleteExisting?: (deletedIds: Array<number | string>) => void;
|
|
50
|
+
/** 유효성 검사 실패 시 호출돼요 (toast 등 직접 처리) */
|
|
51
|
+
onError?: (error: ImageUploaderError) => void;
|
|
52
|
+
}
|
|
53
|
+
interface UseImageUploaderReturn {
|
|
54
|
+
/** 삭제되지 않은 기존 이미지 */
|
|
55
|
+
existingImages: ExistingImage[];
|
|
56
|
+
/** 새로 선택한 이미지 (미리보기 포함) */
|
|
57
|
+
newImages: NewImageFile[];
|
|
58
|
+
/** 기존 + 새 이미지 합산 개수 */
|
|
59
|
+
totalCount: number;
|
|
60
|
+
/** 드래그 활성 여부 */
|
|
61
|
+
isDragActive: boolean;
|
|
62
|
+
/** 파일 input 요소의 ref */
|
|
63
|
+
inputRef: react__default.RefObject<HTMLInputElement>;
|
|
64
|
+
/** 파일 선택 다이얼로그 열기 */
|
|
65
|
+
openFilePicker: () => void;
|
|
66
|
+
/** 기존 이미지 삭제 */
|
|
67
|
+
removeExisting: (id: number | string) => void;
|
|
68
|
+
/** 새로 선택한 이미지 삭제 */
|
|
69
|
+
removeNew: (id: string) => void;
|
|
70
|
+
/** drop zone에 spread할 drag 이벤트 핸들러 */
|
|
71
|
+
dragHandlers: {
|
|
72
|
+
onDragOver: react__default.DragEventHandler;
|
|
73
|
+
onDragLeave: react__default.DragEventHandler;
|
|
74
|
+
onDrop: react__default.DragEventHandler;
|
|
75
|
+
};
|
|
76
|
+
/** file input에 spread할 props */
|
|
77
|
+
inputProps: {
|
|
78
|
+
onChange: react__default.ChangeEventHandler<HTMLInputElement>;
|
|
79
|
+
accept: string;
|
|
80
|
+
multiple: boolean;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
declare function useImageUploader({ initialImages, maxImages, maxSizeMb, accept, onFileSelect, onDeleteExisting, onError, }: UseImageUploaderOptions): UseImageUploaderReturn;
|
|
84
|
+
|
|
85
|
+
declare const imageUploaderVariants: (props?: ({
|
|
86
|
+
layout?: "grid" | "row" | null | undefined;
|
|
87
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
88
|
+
interface ImageUploaderProps extends UseImageUploaderOptions, VariantProps<typeof imageUploaderVariants> {
|
|
89
|
+
className?: string;
|
|
90
|
+
/** true이면 모든 인터랙션을 비활성화해요 */
|
|
91
|
+
disabled?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* 이미지 추가 버튼의 내용을 교체할 수 있어요.
|
|
94
|
+
* 기본값은 + 아이콘과 현재/최대 개수를 표시해요.
|
|
95
|
+
*/
|
|
96
|
+
placeholder?: ReactNode;
|
|
97
|
+
}
|
|
98
|
+
declare const ImageUploader: react.ForwardRefExoticComponent<ImageUploaderProps & react.RefAttributes<HTMLDivElement>>;
|
|
99
|
+
|
|
100
|
+
export { type ExistingImage as E, ImageUploader as I, type NewImageFile as N, type UseImageUploaderOptions as U, type ImageUploaderError as a, type ImageUploaderProps as b, type UseImageUploaderReturn as c, imageUploaderVariants as i, useImageUploader as u };
|