diff --git a/docs/pages/kimg.vue b/docs/pages/kimg.vue
index 1a93b70d7..1b1fbb6af 100644
--- a/docs/pages/kimg.vue
+++ b/docs/pages/kimg.vue
@@ -198,6 +198,74 @@
/>
+
+
Placeholder
+
+ You can use the #placeholder
slot to place its content to the placeholder area. The area is gray by default and respects set dimensions of the image container. You can change its color via the the backgroundColor
prop.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Show elements on top of an image
+
+ You can use #topLeft
, #topRight
, #bottomLeft
, and #bottomRight
slots to place elements on top of an image or placeholder area.
+
+
+
+
+
+ Top left
+
+
+
+
+
+
+
+
+ Top left
+
+
+
+
+
+
diff --git a/lib/KImg.vue b/lib/KImg.vue
index 721b852e1..db8cd3852 100644
--- a/lib/KImg.vue
+++ b/lib/KImg.vue
@@ -7,8 +7,43 @@
:alt="alternativeText"
:style="imgStyles"
>
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -137,6 +172,24 @@
default: 'centerInside', // needs to be duplicated rather than using ScaleTypes.CENTER_INSIDE, otherwise it doesn't render correctly in the auto-generated Props documentation
validator: isValidScaleType,
},
+ /**
+ * A color to be displayed instead or behind an image.
+ * It creates a background area which respects the dimensions
+ * set on the container.
+ *
+ * It can serve as (1) a color of the area surrounding an image when
+ * it's letterboxed, (2) creates a placeholder area displayed
+ * over the whole container when an image source is not provided,
+ * (3) creates a progressive loading experience as the colored background
+ * is displayed while an image is loading.
+ *
+ * Its default value is `$themePalette.grey.v_200`.
+ */
+ backgroundColor: {
+ type: String,
+ required: false,
+ default: null,
+ },
},
computed: {
ratio() {
@@ -146,10 +199,15 @@
return this.isDecorative ? '' : this.altText;
},
baseStyles() {
+ const backgroundColor = this.backgroundColor
+ ? this.backgroundColor
+ : this.$themePalette.grey.v_200;
+
return {
rootContainer: {
display: 'block',
- backgroundColor: this.$themePalette.grey.v_200,
+ position: 'relative',
+ backgroundColor,
height: this.validateAndFormatUnits(this.height),
width: this.validateAndFormatUnits(this.width),
maxHeight: this.validateAndFormatUnits(this.maxHeight),
@@ -162,6 +220,8 @@
},
img: {
display: 'block',
+ position: 'relative',
+ zIndex: '1',
},
};
},