@majapisoftwares/ui 4.1.3 → 4.1.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.
|
@@ -19,7 +19,7 @@ export type FileUrl = {
|
|
|
19
19
|
size: number;
|
|
20
20
|
};
|
|
21
21
|
export type FileInputFile = FileFile | FileUrl;
|
|
22
|
-
declare function FileInput({ error, className, helpText, onChange, name, limit, label, id, required, onMouseOver, onMouseOut, readOnly, value, emptyText, downloadText, openText, fileDisplay, asyncUpload, onRejectFiles, loading, maxConcurrentUploads, fileAdditionalInfo, ref, fileSelectClassName, previewFileClassName, filesPerPage, previewFileComponent, ...props }: Pick<InputProps<false>, "error" | "className" | "helpText" | "name" | "label" | "id" | "required" | "onMouseOver" | "onMouseOut"> & Omit<FileSelectProps, "onAcceptFiles" | "onRejectFiles"> & {
|
|
22
|
+
declare function FileInput<PFP extends object>({ error, className, helpText, onChange, name, limit, label, id, required, onMouseOver, onMouseOut, readOnly, value, emptyText, downloadText, openText, fileDisplay, asyncUpload, onRejectFiles, loading, maxConcurrentUploads, fileAdditionalInfo, ref, fileSelectClassName, previewFileClassName, filesPerPage, previewFileComponent, previewFileProps, ...props }: Pick<InputProps<false>, "error" | "className" | "helpText" | "name" | "label" | "id" | "required" | "onMouseOver" | "onMouseOut"> & Omit<FileSelectProps, "onAcceptFiles" | "onRejectFiles"> & {
|
|
23
23
|
readOnly?: boolean;
|
|
24
24
|
value?: FileInputFile[];
|
|
25
25
|
onChange?: (event: {
|
|
@@ -43,7 +43,8 @@ declare function FileInput({ error, className, helpText, onChange, name, limit,
|
|
|
43
43
|
fileSelectClassName?: string;
|
|
44
44
|
previewFileClassName?: string;
|
|
45
45
|
filesPerPage?: number;
|
|
46
|
-
previewFileComponent?: ComponentType<PreviewFileProps>;
|
|
46
|
+
previewFileComponent?: ComponentType<PreviewFileProps & PFP>;
|
|
47
|
+
previewFileProps?: PFP;
|
|
47
48
|
}): import("react").JSX.Element;
|
|
48
49
|
export type FileInputProps = ComponentPropsWithRef<typeof FileInput>;
|
|
49
50
|
export default FileInput;
|
|
@@ -10,7 +10,7 @@ import { PreviewFile } from "./PreviewFile";
|
|
|
10
10
|
import concurrentForOf from "@majapisoftwares/next/utils/concurrentForOf";
|
|
11
11
|
import paginated from "@majapisoftwares/next/utils/paginated";
|
|
12
12
|
import Pagination from "../Pagination";
|
|
13
|
-
function FileInput({ error, className, helpText, onChange, name, limit, label, id, required, onMouseOver, onMouseOut, readOnly, value, emptyText = "No files", downloadText = "Download", openText = "Open", fileDisplay, asyncUpload, onRejectFiles, loading, maxConcurrentUploads = 1, fileAdditionalInfo, ref, fileSelectClassName, previewFileClassName, filesPerPage = 10, previewFileComponent, ...props }) {
|
|
13
|
+
function FileInput({ error, className, helpText, onChange, name, limit, label, id, required, onMouseOver, onMouseOut, readOnly, value, emptyText = "No files", downloadText = "Download", openText = "Open", fileDisplay, asyncUpload, onRejectFiles, loading, maxConcurrentUploads = 1, fileAdditionalInfo, ref, fileSelectClassName, previewFileClassName, filesPerPage = 10, previewFileComponent, previewFileProps, ...props }) {
|
|
14
14
|
const [uploading, setUploading] = useState(false);
|
|
15
15
|
const [innerValue, setInnerValue] = useState(value || []);
|
|
16
16
|
const [currentPage, setCurrentPage] = useState(1);
|
|
@@ -131,7 +131,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
|
|
|
131
131
|
"md:grid-cols-2": !!innerValue.length,
|
|
132
132
|
"min-h-[140px]": !!innerValue.length || !readOnly,
|
|
133
133
|
})}>
|
|
134
|
-
{paginatedValue.map((file, index) => (<PreviewFileComponent 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
|
+
{paginatedValue.map((file, index) => (<PreviewFileComponent 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} {...previewFileProps}/>))}
|
|
135
135
|
{innerValue.length > filesPerPage && (<Pagination className="col-span-2 mx-auto" currentPage={currentPage} totalItems={innerValue.length} onChangePage={setCurrentPage} itemsPerPage={filesPerPage}/>)}
|
|
136
136
|
{readOnly && !innerValue.length && (<Text variant="secondary">{emptyText}</Text>)}
|
|
137
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}/>)}
|