@majapisoftwares/ui 4.1.1 → 4.1.2
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.
|
@@ -112,33 +112,32 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
|
|
|
112
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
115
|
}, [innerValue]);
|
|
117
116
|
const handleDeleteClick = useCallback((clickedFile) => () => {
|
|
118
117
|
setInnerValue((value) => [
|
|
119
118
|
...value.filter((file) => file !== clickedFile),
|
|
120
119
|
]);
|
|
121
120
|
}, []);
|
|
122
|
-
return (<div data-input-name={name} data-error={error ? "" : undefined} data-loading={loading ? "" : undefined} className={clsx("relative data-loading:animate-pulse", className)} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>
|
|
123
|
-
{label && (<label htmlFor={id} className={defaultLabelClassName}>
|
|
124
|
-
{label}
|
|
125
|
-
{required && (<>
|
|
126
|
-
{" "}
|
|
127
|
-
<span className="text-red-500">*</span>
|
|
128
|
-
</>)}
|
|
129
|
-
</label>)}
|
|
121
|
+
return (<div data-input-name={name} data-error={error ? "" : undefined} data-loading={loading ? "" : undefined} className={clsx("relative data-loading:animate-pulse", className)} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>
|
|
122
|
+
{label && (<label htmlFor={id} className={defaultLabelClassName}>
|
|
123
|
+
{label}
|
|
124
|
+
{required && (<>
|
|
125
|
+
{" "}
|
|
126
|
+
<span className="text-red-500">*</span>
|
|
127
|
+
</>)}
|
|
128
|
+
</label>)}
|
|
130
129
|
<div className={clsx("grid grid-cols-1 gap-4", {
|
|
131
130
|
"md:grid-cols-2": !!innerValue.length,
|
|
132
131
|
"min-h-[140px]": !!innerValue.length || !readOnly,
|
|
133
|
-
})}>
|
|
134
|
-
{paginatedValue.map((file, index) => (<PreviewFile key={index} file={file} readOnly={readOnly} handleDeleteClick={handleDeleteClick(file)} downloadText={downloadText} display={fileDisplay} openText={openText} additionalInfo={fileAdditionalInfo} index={index} className={previewFileClassName}/>))}
|
|
135
|
-
{innerValue.length > filesPerPage && (<Pagination className="col-span-2 mx-auto" currentPage={currentPage} totalItems={innerValue.length} onChangePage={setCurrentPage} itemsPerPage={filesPerPage}/>)}
|
|
136
|
-
{readOnly && !innerValue.length && (<Text variant="secondary">{emptyText}</Text>)}
|
|
137
|
-
{!readOnly && (!limit || innerValue.length < limit) && (<FileSelect {...props} className={fileSelectClassName} id={id} onAcceptFiles={handleAcceptFiles} limit={limit ? limit - innerValue.length : undefined} uploading={uploading} onRejectFiles={onRejectFiles} error={error}/>)}
|
|
138
|
-
</div>
|
|
139
|
-
{helpText && (<div className={clsx(defaultHelpTextClassName, "in-data-error:text-error-500")}>
|
|
140
|
-
{helpText}
|
|
141
|
-
</div>)}
|
|
132
|
+
})}>
|
|
133
|
+
{paginatedValue.map((file, index) => (<PreviewFile key={index} file={file} readOnly={readOnly} handleDeleteClick={handleDeleteClick(file)} downloadText={downloadText} display={fileDisplay} openText={openText} additionalInfo={fileAdditionalInfo} index={index} className={previewFileClassName} filesPerPage={filesPerPage} currentPage={currentPage}/>))}
|
|
134
|
+
{innerValue.length > filesPerPage && (<Pagination className="col-span-2 mx-auto" currentPage={currentPage} totalItems={innerValue.length} onChangePage={setCurrentPage} itemsPerPage={filesPerPage}/>)}
|
|
135
|
+
{readOnly && !innerValue.length && (<Text variant="secondary">{emptyText}</Text>)}
|
|
136
|
+
{!readOnly && (!limit || innerValue.length < limit) && (<FileSelect {...props} className={fileSelectClassName} id={id} onAcceptFiles={handleAcceptFiles} limit={limit ? limit - innerValue.length : undefined} uploading={uploading} onRejectFiles={onRejectFiles} error={error}/>)}
|
|
137
|
+
</div>
|
|
138
|
+
{helpText && (<div className={clsx(defaultHelpTextClassName, "in-data-error:text-error-500")}>
|
|
139
|
+
{helpText}
|
|
140
|
+
</div>)}
|
|
142
141
|
</div>);
|
|
143
142
|
}
|
|
144
143
|
export default FileInput;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileInputFile } from "./FileInput";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
|
-
export declare function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display, additionalInfo, index, className, }: {
|
|
3
|
+
export declare function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display, additionalInfo, index, className, filesPerPage, currentPage, }: {
|
|
4
4
|
file: FileInputFile;
|
|
5
5
|
readOnly?: boolean;
|
|
6
6
|
handleDeleteClick: () => void;
|
|
@@ -10,4 +10,6 @@ export declare function PreviewFile({ file, readOnly, handleDeleteClick, downloa
|
|
|
10
10
|
additionalInfo?: (file: FileInputFile, index: number) => ReactNode;
|
|
11
11
|
index: number;
|
|
12
12
|
className?: string;
|
|
13
|
+
filesPerPage: number;
|
|
14
|
+
currentPage: number;
|
|
13
15
|
}): import("react").JSX.Element;
|
|
@@ -8,7 +8,7 @@ import { ArrowTopRightOnSquareIcon, TrashIcon, } from "@heroicons/react/20/solid
|
|
|
8
8
|
import clsx from "../../utils/clsx";
|
|
9
9
|
const videoExtensions = [".mp4"];
|
|
10
10
|
const imageExtensions = [".png", ".jpg", ".jpeg", ".webp"];
|
|
11
|
-
export function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display = "info", additionalInfo, index, className, }) {
|
|
11
|
+
export function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display = "info", additionalInfo, index, className, filesPerPage, currentPage, }) {
|
|
12
12
|
const url = file.file
|
|
13
13
|
? URL.createObjectURL(file.file)
|
|
14
14
|
: file.url;
|
|
@@ -45,7 +45,9 @@ export function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, o
|
|
|
45
45
|
</Button>
|
|
46
46
|
</Group>)}
|
|
47
47
|
</Stack>
|
|
48
|
-
{additionalInfo &&
|
|
48
|
+
{additionalInfo &&
|
|
49
|
+
additionalInfo(file, index + (currentPage - 1) * filesPerPage)}
|
|
50
|
+
{/*{additionalInfo && additionalInfo(file, index)}*/}
|
|
49
51
|
</Stack>
|
|
50
52
|
</Group>)}
|
|
51
53
|
{!readOnly && (<Button icon variant="filled" color="default" className="absolute top-2 right-2 group-hover:opacity-100 sm:opacity-0" onClick={handleDeleteClick}>
|