diff --git a/src/color-swatch/README.md b/src/color-swatch/README.md
index ebcaf84d..d95c4182 100644
--- a/src/color-swatch/README.md
+++ b/src/color-swatch/README.md
@@ -128,6 +128,64 @@ future_swatch_container.append(swatch);
```
+### The `label` attribute
+
+You can provide the color label via the `label` attribute.
+
+
+
@@ -27,6 +28,7 @@ const Self = class ColorSwatch extends ColorElement {
this._el = {
wrapper: this.shadowRoot.querySelector("#wrapper"),
+ label: this.shadowRoot.querySelector("[part=label]"),
colorWrapper: this.shadowRoot.querySelector("[part=color]"),
};
@@ -61,6 +63,11 @@ const Self = class ColorSwatch extends ColorElement {
return this._el.gamutIndicator.gamut;
}
+ get textContent () {
+ // Children that are not assigned to another slot
+ return [...this.childNodes].filter(n => !n.slot).map(n => n.textContent).join("").trim();
+ }
+
propChangedCallback ({name, prop, detail: change}) {
let input = this._el.input;
@@ -101,6 +108,15 @@ const Self = class ColorSwatch extends ColorElement {
}
}
+ if (name === "label") {
+ if (this.label.length && this.label !== this.textContent) {
+ this._el.label.textContent = this.label;
+ }
+ else {
+ this._el.label.textContent = "";
+ }
+ }
+
if (name === "color") {
let isValid = this.color !== null || !this.value;
@@ -155,13 +171,21 @@ const Self = class ColorSwatch extends ColorElement {
return this._el.input.value;
}
- // Children that are not assigned to another slot
- return [...this.childNodes].filter(n => !n.slot).map(n => n.textContent).join("").trim();
+ return this.textContent;
},
reflect: {
from: true,
},
},
+ label: {
+ type: String,
+ default () {
+ return this.textContent;
+ },
+ convert (value) {
+ return value.trim();
+ },
+ },
color: {
get type () {
return ColorSwatch.Color;