@majapisoftwares/ui 4.1.3 → 4.1.5
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}/>)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ComponentProps } from "react";
|
|
2
2
|
import FileInput from "../FileInput";
|
|
3
|
-
declare function ImageInput({ icon, uploadAFileText, allowedFileTypes, fileDisplay, ...props }: ComponentProps<typeof FileInput
|
|
3
|
+
declare function ImageInput<PFP extends object>({ icon, uploadAFileText, allowedFileTypes, fileDisplay, ...props }: ComponentProps<typeof FileInput<PFP>>): import("react").JSX.Element;
|
|
4
4
|
export default ImageInput;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import FileInput from "../FileInput";
|
|
2
|
-
const defaultIcon = (<svg stroke="currentColor" fill="none" viewBox="0 0 48 48" aria-hidden="true">
|
|
3
|
-
<path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round"/>
|
|
2
|
+
const defaultIcon = (<svg stroke="currentColor" fill="none" viewBox="0 0 48 48" aria-hidden="true">
|
|
3
|
+
<path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round"/>
|
|
4
4
|
</svg>);
|
|
5
5
|
function ImageInput({ icon = defaultIcon, uploadAFileText = "Upload an image", allowedFileTypes = [".png", ".jpg", ".jpeg", ".webp"], fileDisplay = "preview", ...props }) {
|
|
6
6
|
return (<FileInput {...props} icon={icon} uploadAFileText={uploadAFileText} allowedFileTypes={allowedFileTypes} fileDisplay={fileDisplay}/>);
|