qucoon-components 0.0.8 → 0.1.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/dist/index.cjs.js +144 -144
- package/dist/index.es.js +14984 -14962
- package/dist/style.css +1 -1
- package/dist/types/components/custom/BaseFileUpload.d.ts +56 -16
- package/dist/types/components/custom/FilePreview.d.ts +21 -7
- package/dist/types/components/icon/FileFormatsIcon.d.ts +1 -1
- package/dist/types/components/ui/modal/v2/BaseModal.d.ts +1 -2
- package/dist/types/components/ui/select/ModernSelect.d.ts +3 -2
- package/dist/types/utilities/fileUploadUtil.d.ts +18 -0
- package/dist/types/utilities/hooks/index.d.ts +2 -0
- package/dist/types/utilities/hooks/useFileUploadState.d.ts +13 -0
- package/dist/types/utilities/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Base file representation - works for both new uploads and existing files
|
|
4
|
+
* Single responsibility: Represent a file in the system
|
|
5
|
+
*/
|
|
6
|
+
export interface FileItem {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
size?: number;
|
|
10
|
+
type?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
file?: File;
|
|
13
|
+
metadata?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Upload state for files being processed
|
|
17
|
+
* Single responsibility: Track upload progress and status
|
|
18
|
+
*/
|
|
19
|
+
export interface FileUploadState {
|
|
20
|
+
fileId: string;
|
|
21
|
+
status: 'pending' | 'uploading' | 'completed' | 'failed' | 'cancelled';
|
|
3
22
|
progress: number;
|
|
4
|
-
status: string;
|
|
5
|
-
reason?: string;
|
|
6
|
-
uploadId: string;
|
|
7
|
-
};
|
|
8
|
-
type BaseFileUploadProps = {
|
|
9
|
-
files: UploadFileWithProgress[];
|
|
10
|
-
onFilesChange: (updater: UploadFileWithProgress[] | ((prev: UploadFileWithProgress[]) => UploadFileWithProgress[])) => void;
|
|
11
|
-
label?: string;
|
|
12
23
|
error?: string;
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
startedAt?: Date;
|
|
25
|
+
completedAt?: Date;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Upload handler function type
|
|
29
|
+
* Interface segregation: Separate concerns of upload logic
|
|
30
|
+
*/
|
|
31
|
+
export type FileUploadHandler = (file: File, fileId: string, onProgress: (progress: number) => void, onStatusChange: (status: FileUploadState['status'], error?: string) => void) => Promise<{
|
|
32
|
+
url?: string;
|
|
33
|
+
metadata?: any;
|
|
34
|
+
}>;
|
|
35
|
+
export interface FileUploadProps {
|
|
36
|
+
files: FileItem[];
|
|
37
|
+
onChange: (files: FileItem[]) => void;
|
|
38
|
+
uploadHandler?: FileUploadHandler;
|
|
15
39
|
autoUpload?: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
multiple?: boolean;
|
|
41
|
+
maxFiles?: number;
|
|
42
|
+
maxSize?: number;
|
|
43
|
+
accept?: string[];
|
|
44
|
+
showProgress?: boolean;
|
|
45
|
+
showFileSize?: boolean;
|
|
46
|
+
allowReorder?: boolean;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
validate?: (files: FileItem[]) => string | null;
|
|
49
|
+
error?: string;
|
|
50
|
+
isTouched?: boolean;
|
|
51
|
+
label?: string;
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
onUploadComplete?: (fileItem: FileItem, result: any) => void;
|
|
54
|
+
onUploadError?: (fileItem: FileItem, error: string) => void;
|
|
55
|
+
onFileRemove?: (fileItem: FileItem) => void;
|
|
56
|
+
className?: string;
|
|
57
|
+
style?: React.CSSProperties;
|
|
58
|
+
}
|
|
59
|
+
declare const BaseFileUpload: React.FC<FileUploadProps>;
|
|
20
60
|
export default BaseFileUpload;
|
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
import { CSSProperties } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { default as React, CSSProperties } from 'react';
|
|
2
|
+
import { FileItem, FileUploadState } from '..';
|
|
3
|
+
export interface FilePreviewProps {
|
|
4
|
+
file: File | string | FileItem;
|
|
5
|
+
status?: FileUploadState['status'];
|
|
5
6
|
progress?: number;
|
|
6
|
-
|
|
7
|
+
error?: string;
|
|
8
|
+
showProgress?: boolean;
|
|
9
|
+
showFileSize?: boolean;
|
|
10
|
+
showDownload?: boolean;
|
|
11
|
+
showDelete?: boolean;
|
|
7
12
|
onDelete?: () => void;
|
|
8
13
|
onDownload?: () => void;
|
|
14
|
+
onRetry?: () => void;
|
|
9
15
|
statusStyle?: CSSProperties;
|
|
10
16
|
containerStyle?: CSSProperties;
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Enhanced FilePreview component with better separation of concerns
|
|
21
|
+
* - Handles multiple file input types
|
|
22
|
+
* - Flexible display options
|
|
23
|
+
* - Clear action handling
|
|
24
|
+
* - Better accessibility
|
|
25
|
+
*/
|
|
26
|
+
declare const FilePreview: React.FC<FilePreviewProps>;
|
|
13
27
|
export default FilePreview;
|
|
@@ -2,5 +2,5 @@ import { SVGProps } from 'react';
|
|
|
2
2
|
export type FileFormatTypes = "pdf" | "png" | "jpg" | "doc" | "xls";
|
|
3
3
|
declare function FileFormatsIcon({ fileFormatType, ...props }: SVGProps<SVGSVGElement> & {
|
|
4
4
|
fileFormatType: FileFormatTypes;
|
|
5
|
-
}): import("react/jsx-runtime").JSX.Element
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export default FileFormatsIcon;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { default as React, ReactNode } from 'react';
|
|
2
2
|
import { ModalPosition } from '../../../../utilities/types/modalTypes';
|
|
3
3
|
export interface BaseModalProps {
|
|
4
|
-
ref: React.RefObject<HTMLDivElement>;
|
|
5
4
|
id: string;
|
|
6
5
|
zIndex?: number;
|
|
7
6
|
backdrop?: 'blur' | 'solid' | 'transparent';
|
|
@@ -22,5 +21,5 @@ export interface BaseModalProps {
|
|
|
22
21
|
size?: 'sm' | 'md' | 'lg' | 'xl' | 'auto';
|
|
23
22
|
cssProps?: Record<string, string>;
|
|
24
23
|
}
|
|
25
|
-
export declare
|
|
24
|
+
export declare const BaseModal: React.ForwardRefExoticComponent<BaseModalProps & React.RefAttributes<HTMLDivElement>>;
|
|
26
25
|
export default BaseModal;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as React, CSSProperties } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { FormikValues } from 'formik';
|
|
3
3
|
import { EnhancedLabelProps } from '../label/EnhancedLabel';
|
|
4
|
+
import { Formik } from '../../../utilities';
|
|
4
5
|
export type ModernSelectOption = {
|
|
5
6
|
value: string;
|
|
6
7
|
label: string;
|
|
@@ -28,7 +29,7 @@ export type ModernSelectProps<T extends FormikValues = any> = {
|
|
|
28
29
|
isLoading?: boolean;
|
|
29
30
|
};
|
|
30
31
|
containerStyle?: CSSProperties;
|
|
31
|
-
formik?:
|
|
32
|
+
formik?: Formik<T>;
|
|
32
33
|
value?: string;
|
|
33
34
|
addDefaultSelectOption?: boolean;
|
|
34
35
|
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FileItem } from '../components';
|
|
2
|
+
export declare class FileUploadUtil {
|
|
3
|
+
/**
|
|
4
|
+
* Generate unique file ID
|
|
5
|
+
* DRY principle: Centralized ID generation
|
|
6
|
+
*/
|
|
7
|
+
static generateFileId: () => string;
|
|
8
|
+
/**
|
|
9
|
+
* Create FileItem from File object
|
|
10
|
+
* Factory pattern: Consistent file item creation
|
|
11
|
+
*/
|
|
12
|
+
static createFileItemFromFile: (file: File, id?: string) => FileItem;
|
|
13
|
+
/**
|
|
14
|
+
* Create FileItem from URL (for existing files)
|
|
15
|
+
* Factory pattern: Consistent file item creation
|
|
16
|
+
*/
|
|
17
|
+
static createFileItemFromUrl: (url: string, name: string, id?: string, metadata?: Record<string, any>) => FileItem;
|
|
18
|
+
}
|
|
@@ -5,6 +5,8 @@ export { default as useBulkUpload } from './useBulkUpload';
|
|
|
5
5
|
export * from './useBulkUpload';
|
|
6
6
|
export { default as useFetchOnStageChange } from './useFetchOnStageChange';
|
|
7
7
|
export * from './useFetchOnStageChange';
|
|
8
|
+
export { default as useFileUploadState } from './useFileUploadState';
|
|
9
|
+
export * from './useFileUploadState';
|
|
8
10
|
export { default as useFirstRender } from './useFirstRender';
|
|
9
11
|
export * from './useFirstRender';
|
|
10
12
|
export { default as useModal } from './useModal';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FileUploadState } from '../../components';
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook for managing file upload state
|
|
4
|
+
* Single responsibility: Manage upload state and provide actions
|
|
5
|
+
*/
|
|
6
|
+
export declare function useFileUploadState(): {
|
|
7
|
+
uploadStates: Map<string, FileUploadState>;
|
|
8
|
+
updateUploadState: (fileId: string, updates: Partial<FileUploadState>) => void;
|
|
9
|
+
removeUploadState: (fileId: string) => void;
|
|
10
|
+
clearAllStates: () => void;
|
|
11
|
+
getUploadState: (fileId: string) => FileUploadState | undefined;
|
|
12
|
+
};
|
|
13
|
+
export default useFileUploadState;
|