Skip to content

Commit 094eed4

Browse files
authored
Merge pull request #430 from themesberg/feature--dropzone-placeholder
feature: FwbFileInput editable dropzone placeholder
2 parents a7b6a10 + bf022dc commit 094eed4

File tree

8 files changed

+72
-17
lines changed

8 files changed

+72
-17
lines changed

docs/components/fileInput.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import FwbFileInputExample from './fileInput/examples/FwbFileInputExample.vue'
33
import FwbFileInputExampleHelper from './fileInput/examples/FwbFileInputExampleHelper.vue'
44
import FwbFileInputExampleSize from './fileInput/examples/FwbFileInputExampleSize.vue'
55
import FwbFileInputExampleDropZone from './fileInput/examples/FwbFileInputExampleDropZone.vue'
6+
import FwbFileInputExampleDropZonePlaceholder from './fileInput/examples/FwbFileInputExampleDropZonePlaceholder.vue'
67
import FwbFileInputExampleDropZoneMultiple from './fileInput/examples/FwbFileInputExampleDropZoneMultiple.vue'
78
import FwbFileInputExampleMultiple from './fileInput/examples/FwbFileInputExampleMultiple.vue'
89
</script>
@@ -31,6 +32,7 @@ const file = ref(null)
3132
</script>
3233
```
3334

35+
3436
## Multiple File upload
3537

3638
<fwb-file-input-example-multiple />
@@ -52,6 +54,7 @@ const files = ref([])
5254
</script>
5355
```
5456

57+
5558
## Helper text
5659

5760
<fwb-file-input-example-helper />
@@ -72,6 +75,7 @@ const file = ref(null)
7275
</script>
7376
```
7477

78+
7579
## Sizes
7680

7781
<fwb-file-input-example-size />
@@ -90,8 +94,8 @@ const file = ref(null)
9094
</script>
9195
```
9296

93-
## Dropzone
9497

98+
## Dropzone
9599

96100
<fwb-file-input-example-drop-zone />
97101
```vue
@@ -107,8 +111,32 @@ const file = ref(null)
107111
</script>
108112
```
109113

110-
## Dropzone multiple
111114

115+
## Dropzone with custom placeholder
116+
117+
You can customize the dropzone placeholder text using the `dropzonePlaceholder` slot:
118+
119+
<fwb-file-input-example-drop-zone-placeholder />
120+
```vue
121+
<template>
122+
<fwb-file-input v-model="file" dropzone>
123+
<template #dropzonePlaceholder>
124+
<span class="font-semibold">Choose your file</span>
125+
or drop it here
126+
</template>
127+
</fwb-file-input>
128+
</template>
129+
130+
<script setup>
131+
import { ref } from 'vue'
132+
import { FwbFileInput } from 'flowbite-vue'
133+
134+
const file = ref(null)
135+
</script>
136+
```
137+
138+
139+
## Dropzone multiple
112140

113141
<fwb-file-input-example-drop-zone-multiple />
114142
```vue
@@ -120,6 +148,7 @@ const file = ref(null)
120148
import { ref } from 'vue'
121149
import { FwbFileInput } from 'flowbite-vue'
122150

151+
const file = ref(null)
123152
const files = ref([])
124153
</script>
125-
```
154+
```

docs/components/fileInput/examples/FwbFileInputExampleDropZoneMultiple.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/>
88
<div
99
v-if="files.length !== 0"
10-
class="mt-4 rounded-md border border-gray-300 p-2 dark:border-gray-600"
10+
class="mt-4 p-2 border border-gray-300 dark:border-gray-600 rounded-md"
1111
>
1212
<div
1313
v-for="file in files"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div class="vp-raw">
3+
<fwb-file-input
4+
v-model="file"
5+
dropzone
6+
>
7+
<template #dropzonePlaceholder>
8+
<span class="font-semibold">Choose your file</span>
9+
or drop it here
10+
</template>
11+
</fwb-file-input>
12+
</div>
13+
</template>
14+
15+
<script lang="ts" setup>
16+
import { ref } from 'vue'
17+
18+
import { FwbFileInput } from '../../../../src/index'
19+
20+
const file = ref(null)
21+
</script>

docs/components/fileInput/examples/FwbFileInputExampleHelper.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v-model="file"
55
label="Upload file"
66
>
7-
<p class="mt-1! text-sm text-gray-500 dark:text-gray-300">
7+
<p class="mt-1! text-gray-500 dark:text-gray-300 text-sm">
88
SVG, PNG, JPG or GIF (MAX. 800x400px).
99
</p>
1010
</fwb-file-input>

docs/components/fileInput/examples/FwbFileInputExampleMultiple.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/>
88
<div
99
v-if="files.length !== 0"
10-
class="mt-4 rounded-md border border-gray-300 p-2 dark:border-gray-600"
10+
class="mt-4 p-2 border border-gray-300 dark:border-gray-600 rounded-md"
1111
>
1212
<div
1313
v-for="file in files"

docs/components/fileInput/examples/FwbFileInputExampleSize.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="vp-raw grid gap-2">
2+
<div class="gap-2 grid vp-raw">
33
<fwb-file-input
44
v-model="file"
55
size="xs"

src/components/FwbFileInput/FwbFileInput.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
<div
1717
v-else
18-
class="flex flex-col items-start justify-center"
18+
class="flex flex-col justify-center items-center"
1919
@dragover="dragOverHandler"
2020
@drop="dropFileHandler"
2121
>
@@ -40,14 +40,19 @@
4040
stroke="currentColor"
4141
/>
4242
</svg>
43-
<div v-if="!model">
43+
<div v-if="(!model || (Array.isArray(model) && model.length === 0))">
4444
<p :class="dropzoneTextClasses">
45-
<span class="font-semibold">Click to upload</span>
46-
or drag and drop
45+
<slot name="dropzonePlaceholder">
46+
<span class="font-semibold">Click to upload</span>
47+
or drag and drop
48+
</slot>
4749
</p>
4850
<slot />
4951
</div>
50-
<p v-else>File: {{ dropZoneText }}</p>
52+
<p
53+
v-else
54+
class="text-center"
55+
>File: {{ dropZoneText }}</p>
5156
</div>
5257
<input
5358
:accept="accept"

src/components/FwbFileInput/composables/useFileInputClasses.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { computed } from 'vue'
22

33
import { useMergeClasses } from '@/composables/useMergeClasses'
44

5-
const fileInpDefaultClasses = 'block w-full py-1 px-2 text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400'
6-
const fileInpLabelClasses = 'block mb-2 text-sm font-medium text-gray-900 dark:text-white'
7-
const fileInpDropzoneClasses = 'flex flex-col items-center justify-center w-full h-64 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 dark:hover:bg-bray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600'
8-
const fileDropzoneWrapClasses = 'flex flex-col items-center justify-center pt-5 pb-6'
9-
const fileDropzoneDefaultTextClasses = '-mb-2! text-sm text-gray-500 dark:text-gray-400'
5+
const fileInpDefaultClasses = 'block bg-gray-50 dark:bg-gray-700 px-2 py-1 border border-gray-300 dark:border-gray-600 rounded-lg focus:outline-none w-full text-gray-900 dark:text-gray-400 text-sm cursor-pointer dark:placeholder-gray-400'
6+
const fileInpLabelClasses = 'block mb-2 font-medium text-gray-900 dark:text-white text-sm'
7+
const fileInpDropzoneClasses = 'flex flex-col justify-center items-center bg-gray-50 hover:bg-gray-100 dark:bg-gray-700 dark:hover:bg-gray-600 border-2 border-gray-300 dark:border-gray-600 dark:hover:border-gray-500 border-dashed rounded-lg w-full h-64 cursor-pointer'
8+
const fileDropzoneWrapClasses = 'flex flex-col justify-center items-center pt-5 pb-6'
9+
const fileDropzoneDefaultTextClasses = '-mb-2! text-gray-500 dark:text-gray-400 text-sm'
1010

1111
export function useFileInputClasses (size: string) {
1212
const fileInpClasses = computed(() => useMergeClasses([

0 commit comments

Comments
 (0)