Skip to content

Commit 7c0384a

Browse files
committed
feat-#221: tags in CldUploadWidget
1 parent dd79eb0 commit 7c0384a

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

docs/content/2.components/CldUploadWidget.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description:
2+
description:
33
---
44

55
The CldUploadWidget creates a new instance of the [Cloudinary Upload Widget](https://cloudinary.com/documentation/upload_widget) giving you an easy way to add upload capabilities to your Nuxt app.
@@ -68,12 +68,13 @@ To use the above, create a Node-based API route, add the snippet, and use that e
6868

6969
## General Props
7070

71-
| Prop Name | Type | Example |
72-
| ----------------- | -------- | ---------------------------------- |
73-
| children | function | `{ (options) => {} }` |
74-
| options | object | `{ encryption: {...} }` |
75-
| signatureEndpoint | string | `"/api/sign-cloudinary-params.js"` |
76-
| uploadPreset | string | `"my-upload-preset"` |
71+
| Prop Name | Type | Example |
72+
| ----------------- | ------ | ---------------------------------- |
73+
| options | object | `{ encryption: {...} }` |
74+
| signatureEndpoint | string | `"/api/sign-cloudinary-params.js"` |
75+
| uploadPreset | string | `"my-upload-preset"` |
76+
| config | object | `{ cloud: {}, url: {} }` |
77+
| tags | array | `['music', 'sad']` |
7778

7879
## Event Props
7980

playground/app.vue

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
<script lang="ts" setup>
22
// Usage of `useCldImageUrl` composable
3-
const { url } = useCldImageUrl({ options: { src: '/cld-sample-5.jpg' } })
4-
console.log(url)
3+
const { url } = useCldImageUrl({ options: { src: "/cld-sample-5.jpg" } });
4+
console.log(url);
55
66
const { url: videoUrl } = useCldVideoUrl({
7-
options: { src: 'videos/mountain-stars' },
8-
})
9-
console.log(videoUrl)
7+
options: { src: "videos/mountain-stars" },
8+
});
9+
console.log(videoUrl);
1010
1111
const mediaAssets = [
12-
{ tag: 'electric_car_product_gallery_demo' }, // by default mediaType: "image"
13-
{ tag: 'electric_car_product_gallery_demo', mediaType: 'video' },
14-
{ tag: 'electric_car_360_product_gallery_demo', mediaType: 'spin' },
15-
]
12+
{ tag: "electric_car_product_gallery_demo" }, // by default mediaType: "image"
13+
{ tag: "electric_car_product_gallery_demo", mediaType: "video" },
14+
{ tag: "electric_car_360_product_gallery_demo", mediaType: "spin" },
15+
];
1616
17-
const buttonId = 'open-btn'
17+
const buttonId = "open-btn";
1818
19-
const cldVideoRef = ref()
19+
const cldVideoRef = ref();
2020
2121
const chapters = {
22-
0: 'Chapter 1',
23-
6: 'Chapter 2',
24-
9: 'Chapter 3',
25-
}
22+
0: "Chapter 1",
23+
6: "Chapter 2",
24+
9: "Chapter 3",
25+
};
2626
2727
const colors = {
28-
accent: '#ff0000',
29-
base: '#00ff00',
30-
text: '#0000ff',
31-
}
28+
accent: "#ff0000",
29+
base: "#00ff00",
30+
text: "#0000ff",
31+
};
3232
</script>
3333

3434
<template>
35-
<button :id="buttonId">
36-
Select Image or Video
37-
</button>
35+
<button :id="buttonId">Select Image or Video</button>
3836
<CldMediaLibrary
3937
api-key="12345"
4038
:button-id="buttonId"
@@ -45,10 +43,7 @@ const colors = {
4543
cloud-name="demo"
4644
:button-id="buttonId"
4745
/>
48-
<CldOgImage
49-
src="cld-sample-2"
50-
twitter-title="test"
51-
/>
46+
<CldOgImage src="cld-sample-2" twitter-title="test" />
5247
<CldVideoPlayer
5348
ref="cldVideoRef"
5449
width="1620"
@@ -63,13 +58,9 @@ const colors = {
6358
<CldUploadWidget
6459
v-slot="{ open }"
6560
upload-preset="nuxt-cloudinary-unsigned"
61+
:tags="['sad', 'music']"
6662
>
67-
<button
68-
type="button"
69-
@click="open"
70-
>
71-
Upload an Image
72-
</button>
63+
<button type="button" @click="open">Upload an Image</button>
7364
</CldUploadWidget>
7465
<CldUploadButton upload-preset="nuxt-cloudinary-unsigned">
7566
Upload

src/runtime/components/CldUploadWidget.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface CldUploadWidgetProps {
4141
signatureEndpoint?: URL | RequestInfo
4242
uploadPreset?: string
4343
config?: ConfigOptions
44+
tags?: Array<string>
4445
}
4546
4647
// Parameters sourced from:
@@ -250,6 +251,14 @@ if (signed) {
250251
}
251252
}
252253
254+
if (props.tags?.length) {
255+
uploadOptions.showAdvancedOptions = true
256+
257+
// eslint-disable-next-line @typescript-eslint/ban-types
258+
uploadOptions.getTags = (cb: Function, prefix: string) =>
259+
cb(prefix ? props.tags?.filter(t => !t.indexOf(prefix)) : props.tags)
260+
}
261+
253262
// Handle result states and callbacks
254263
255264
watch(results, () => {

0 commit comments

Comments
 (0)