Skip to content

Commit

Permalink
feat-#221: tags in CldUploadWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Jun 24, 2024
1 parent dd79eb0 commit 7c0384a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
15 changes: 8 additions & 7 deletions docs/content/2.components/CldUploadWidget.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description:
description:
---

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.
Expand Down Expand Up @@ -68,12 +68,13 @@ To use the above, create a Node-based API route, add the snippet, and use that e

## General Props

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

## Event Props

Expand Down
55 changes: 23 additions & 32 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
<script lang="ts" setup>
// Usage of `useCldImageUrl` composable
const { url } = useCldImageUrl({ options: { src: '/cld-sample-5.jpg' } })
console.log(url)
const { url } = useCldImageUrl({ options: { src: "/cld-sample-5.jpg" } });
console.log(url);
const { url: videoUrl } = useCldVideoUrl({
options: { src: 'videos/mountain-stars' },
})
console.log(videoUrl)
options: { src: "videos/mountain-stars" },
});
console.log(videoUrl);
const mediaAssets = [
{ tag: 'electric_car_product_gallery_demo' }, // by default mediaType: "image"
{ tag: 'electric_car_product_gallery_demo', mediaType: 'video' },
{ tag: 'electric_car_360_product_gallery_demo', mediaType: 'spin' },
]
{ tag: "electric_car_product_gallery_demo" }, // by default mediaType: "image"
{ tag: "electric_car_product_gallery_demo", mediaType: "video" },
{ tag: "electric_car_360_product_gallery_demo", mediaType: "spin" },
];
const buttonId = 'open-btn'
const buttonId = "open-btn";
const cldVideoRef = ref()
const cldVideoRef = ref();
const chapters = {
0: 'Chapter 1',
6: 'Chapter 2',
9: 'Chapter 3',
}
0: "Chapter 1",
6: "Chapter 2",
9: "Chapter 3",
};
const colors = {
accent: '#ff0000',
base: '#00ff00',
text: '#0000ff',
}
accent: "#ff0000",
base: "#00ff00",
text: "#0000ff",
};
</script>

<template>
<button :id="buttonId">
Select Image or Video
</button>
<button :id="buttonId">Select Image or Video</button>
<CldMediaLibrary
api-key="12345"
:button-id="buttonId"
Expand All @@ -45,10 +43,7 @@ const colors = {
cloud-name="demo"
:button-id="buttonId"
/>
<CldOgImage
src="cld-sample-2"
twitter-title="test"
/>
<CldOgImage src="cld-sample-2" twitter-title="test" />
<CldVideoPlayer
ref="cldVideoRef"
width="1620"
Expand All @@ -63,13 +58,9 @@ const colors = {
<CldUploadWidget
v-slot="{ open }"
upload-preset="nuxt-cloudinary-unsigned"
:tags="['sad', 'music']"
>
<button
type="button"
@click="open"
>
Upload an Image
</button>
<button type="button" @click="open">Upload an Image</button>
</CldUploadWidget>
<CldUploadButton upload-preset="nuxt-cloudinary-unsigned">
Upload
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/components/CldUploadWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface CldUploadWidgetProps {
signatureEndpoint?: URL | RequestInfo
uploadPreset?: string
config?: ConfigOptions
tags?: Array<string>
}
// Parameters sourced from:
Expand Down Expand Up @@ -250,6 +251,14 @@ if (signed) {
}
}
if (props.tags?.length) {
uploadOptions.showAdvancedOptions = true
// eslint-disable-next-line @typescript-eslint/ban-types
uploadOptions.getTags = (cb: Function, prefix: string) =>
cb(prefix ? props.tags?.filter(t => !t.indexOf(prefix)) : props.tags)
}
// Handle result states and callbacks
watch(results, () => {
Expand Down

0 comments on commit 7c0384a

Please sign in to comment.