Skip to content

Commit 6a93593

Browse files
committed
feat: conditional image placeholder
1 parent 64a4041 commit 6a93593

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

packages/common-types/src/plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export interface iPluginOptions<ComponentType = unknown> {
5151
* Optional image optimization component
5252
*/
5353
imageComponent?: ComponentType | string;
54+
/**
55+
* Url to an image to be used as placeholder for images that failed to load
56+
*/
57+
imagePlaceholder?: string;
5458
/**
5559
* Host that contain images
5660
* Treat the url within them as images

packages/common-types/src/values.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export interface iProperty<
5050
* Render using this component instead
5151
*/
5252
component?: ComponentType;
53+
/**
54+
* Url to an image to be used as placeholder for images that failed to load
55+
* Overrides the plugin's imagePlaceholder
56+
*/
57+
imagePlaceholder?: string;
5358
}
5459

5560
export type tPropertyOrderFn = (a: [string, any], b: [string, any]) => -1 | 0 | 1;

packages/components-vue/src/components/base/Img.vue

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<template>
2-
<component :is="imageComponent" v-bind="{ ...$attrs, ...props }" />
2+
<component
3+
:is="imageComponent"
4+
v-bind="{ ...$attrs, ...props }"
5+
:placeholder="placeholder || imagePlaceholder"
6+
/>
37
</template>
48

59
<script setup lang="ts">
610
import { type PropType, inject } from "vue";
711
8-
import type { iPluginOptions } from "@open-xamu-co/ui-common-types";
9-
10-
import type { vComponent } from "../../types/plugin";
12+
import type { iVuePluginOptions } from "../../types/plugin";
1113
1214
/**
1315
* Img Prototype
@@ -39,7 +41,15 @@
3941
type: String as PropType<"eager" | "lazy">,
4042
default: "lazy",
4143
},
44+
/**
45+
* Url to an image to be used as placeholder for images that failed to load
46+
* Overrides the plugin's imagePlaceholder
47+
*/
48+
placeholder: {
49+
type: String,
50+
default: null,
51+
},
4252
});
4353
44-
const { imageComponent = "img" } = inject<iPluginOptions<vComponent>>("xamu") || {};
54+
const { imageComponent = "img", imagePlaceholder } = inject<iVuePluginOptions>("xamu") || {};
4555
</script>

packages/components-vue/src/components/box/Action.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class="--bgColor-light --width-100 --height-100"
1313
:src="src"
1414
:alt="label"
15+
:placeholder="imagePlaceholder"
1516
/>
1617
</div>
1718
<p>
@@ -62,6 +63,11 @@
6263
* @required true
6364
*/
6465
label: string;
66+
/**
67+
* Url to an image to be used as placeholder for images that failed to load
68+
* Overrides the plugin's imagePlaceholder
69+
*/
70+
imagePlaceholder?: string;
6571
}
6672
6773
/**

packages/components-vue/src/components/value/Simple.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@
4545
:href="value"
4646
target="_blank"
4747
>
48-
<BaseImg preset="avatar" :src="value" :alt="value" class="--bgColor-none" />
48+
<BaseImg
49+
preset="avatar"
50+
:src="value"
51+
:alt="value"
52+
:placeholder="property?.imagePlaceholder"
53+
class="--bgColor-none"
54+
/>
4955
</BaseAction>
5056
<!-- String, URL -->
5157
<ActionLink

0 commit comments

Comments
 (0)