From 63d04f0788950d5e4fc22e7710bed752aa682882 Mon Sep 17 00:00:00 2001 From: tugcekucukoglu Date: Thu, 9 May 2024 17:46:20 +0300 Subject: [PATCH] Fixed #5715 - FileUpload: basic mode button label & file label changes --- components/lib/config/PrimeVue.d.ts | 2 ++ components/lib/config/PrimeVue.js | 2 ++ components/lib/fileupload/FileUpload.d.ts | 19 ++++++++++++- components/lib/fileupload/FileUpload.vue | 28 ++++++++++++++----- .../lib/fileupload/style/FileUploadStyle.js | 8 ++++++ 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/components/lib/config/PrimeVue.d.ts b/components/lib/config/PrimeVue.d.ts index e7bcda180..cdfd259e9 100644 --- a/components/lib/config/PrimeVue.d.ts +++ b/components/lib/config/PrimeVue.d.ts @@ -392,6 +392,8 @@ export interface PrimeVueLocaleOptions { emptySelectionMessage?: string; emptySearchMessage?: string; emptyMessage?: string; + fileChosenMessage?: string; + emptyFileChosenMessage?: string; aria?: PrimeVueLocaleAriaOptions; } diff --git a/components/lib/config/PrimeVue.js b/components/lib/config/PrimeVue.js index 47ae6c070..c03feb622 100644 --- a/components/lib/config/PrimeVue.js +++ b/components/lib/config/PrimeVue.js @@ -72,6 +72,8 @@ export const defaultOptions = { selectionMessage: '{0} items selected', emptySelectionMessage: 'No selected item', emptySearchMessage: 'No results found', + fileChosenMessage: '{0} files', + emptyFileChosenMessage: 'No file chosen', emptyMessage: 'No available options', aria: { trueLabel: 'True', diff --git a/components/lib/fileupload/FileUpload.d.ts b/components/lib/fileupload/FileUpload.d.ts index 09c13b397..7bfbea930 100755 --- a/components/lib/fileupload/FileUpload.d.ts +++ b/components/lib/fileupload/FileUpload.d.ts @@ -557,6 +557,16 @@ export interface FileUploadSlots { */ index: number; }): VNode[]; + /** + * Custom file label template. + * @param {Object} scope - filelabel slot's params. + */ + filelabel(scope: { + /** + * File to upload. + */ + files: File[]; + }): VNode[]; } export interface FileUploadEmits { @@ -623,7 +633,14 @@ export interface FileUploadEmits { * @group Component * */ -declare class FileUpload extends ClassComponent {} +declare class FileUpload extends ClassComponent { + /** + * Upload file. + * + * @memberof FileUpload + */ + basicUpload(): void; +} declare module 'vue' { export interface GlobalComponents { diff --git a/components/lib/fileupload/FileUpload.vue b/components/lib/fileupload/FileUpload.vue index eac2001e8..cf86db9d0 100755 --- a/components/lib/fileupload/FileUpload.vue +++ b/components/lib/fileupload/FileUpload.vue @@ -39,14 +39,14 @@ -
+
{{ msg }} - + + + {{ basicChooseButtonLabel }} + +
@@ -89,6 +94,12 @@ export default { }; }, methods: { + basicUpload() { + if (this.hasFiles) this.upload(); + }, + onBasicUploaderClick(event) { + if (event.button === 0 && !this.hasFiles) this.$refs.fileInput.click(); + }, onFileSelect(event) { if (event.type !== 'drop' && this.isIE11() && this.duplicateIEEvent) { this.duplicateIEEvent = false; @@ -302,10 +313,6 @@ export default { } } }, - onBasicUploaderClick(event) { - if (this.hasFiles) this.upload(); - else if (event.button === 0) this.$refs.fileInput.click(); - }, remove(index) { this.clearInputElement(); let removedFile = this.files.splice(index, 1)[0]; @@ -375,7 +382,14 @@ export default { return [this.cx('pcChooseButton'), this.class]; }, basicChooseButtonLabel() { - return this.auto ? this.chooseButtonLabel : this.hasFiles ? this.files.map((f) => f.name).join(', ') : this.chooseButtonLabel; + if (this.auto) return this.chooseButtonLabel; + else if (this.hasFiles) { + if (this.files && this.files.length === 1) return this.files[0].name; + + return this.$primevue.config.locale?.fileChosenMessage?.replace('{0}', this.files.length); + } + + return this.$primevue.config.locale?.emptyFileChosenMessage || ''; }, hasFiles() { return this.files && this.files.length > 0; diff --git a/components/lib/fileupload/style/FileUploadStyle.js b/components/lib/fileupload/style/FileUploadStyle.js index 73fababb4..477ab179c 100644 --- a/components/lib/fileupload/style/FileUploadStyle.js +++ b/components/lib/fileupload/style/FileUploadStyle.js @@ -76,6 +76,14 @@ const theme = ({ dt }) => ` .p-fileupload-advanced .p-message { margin-top: 0; } + +.p-fileupload-basic { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + gap: 0.5rem; +} `; const classes = {