diff --git a/src/components/pg/color/__examples__/basic/basic.html b/src/components/pg/color/__examples__/basic/basic.html
index 80bb9a7..c5100f7 100644
--- a/src/components/pg/color/__examples__/basic/basic.html
+++ b/src/components/pg/color/__examples__/basic/basic.html
@@ -1,4 +1,9 @@
-
Selected:
+
+
+ Selected:
+ No color selected
+
+
\ No newline at end of file
diff --git a/src/components/pg/color/__examples__/basic/basic.ts b/src/components/pg/color/__examples__/basic/basic.ts
index 6711e61..c9aeefe 100644
--- a/src/components/pg/color/__examples__/basic/basic.ts
+++ b/src/components/pg/color/__examples__/basic/basic.ts
@@ -1,4 +1,4 @@
-import { Component, Part, Prop } from '@pictogrammers/element';
+import { Component, Part } from '@pictogrammers/element';
import PgColor from '../../color';
import template from './basic.html';
@@ -10,11 +10,38 @@ import template from './basic.html';
export default class XPgColorBasic extends HTMLElement {
@Part() $color1: PgColor;
@Part() $colorSelected: HTMLSpanElement;
+ @Part() $copyButton: HTMLButtonElement;
+
+ private selectedHex = '';
connectedCallback() {
this.$color1.addEventListener('select', (e: CustomEvent) => {
const { rgb, hex } = e.detail;
+
+ this.selectedHex = hex;
this.$colorSelected.innerText = `${hex} or rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
+ this.$copyButton.disabled = false;
+ });
+
+ this.$copyButton.addEventListener('click', async () => {
+ try {
+ await navigator.clipboard.writeText(this.selectedHex);
+
+ const original = this.$copyButton.innerText;
+ this.$copyButton.innerText = 'Copied!';
+
+ setTimeout(() => {
+ this.$copyButton.innerText = original;
+ }, 1000);
+ } catch (error) {
+ console.error('Failed to copy color:', error);
+
+ this.$copyButton.innerText = 'Failed';
+
+ setTimeout(() => {
+ this.$copyButton.innerText = 'Copy';
+ }, 1000);
+ }
});
}
}
\ No newline at end of file