From 772913e702ca84b064ae7878465baac9b0a91373 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Tue, 3 Aug 2021 14:37:36 -0600 Subject: [PATCH] Adding a click to copy function, needs indication that it was successful --- index.php | 12 +++++++----- js/app.js | 13 ++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 7fad8f0..1b42aa2 100644 --- a/index.php +++ b/index.php @@ -53,10 +53,12 @@
-
+

Batch Color Converter

- +

Click a particular cell in the table with HSL, RGB, or hex to copy that value.

+ +
@@ -78,9 +80,9 @@
- {{ color.hex }} - {{ color.rgb }} - {{ color.hsl }} +
{{ color.hex }}
+
{{ color.rgb }}
+
{{ color.hsl }}
diff --git a/js/app.js b/js/app.js index 8f92059..7ab3e44 100644 --- a/js/app.js +++ b/js/app.js @@ -1,3 +1,5 @@ +const clipboard = navigator.clipboard; + let app = new Vue({ el: '#app', @@ -10,6 +12,8 @@ let app = new Vue({ ], inputBox: "ccc\n#4f46e5\n#db2777aa\n", + copyInput: "", + hexRegex: /^\#?[a-f0-9]{3,9}/i, rgbRegex: /^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)/i, rgbaRegex: /^rgba\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*(0(\.[0-9])?|1(\.0)?)\s*\)/i, @@ -108,6 +112,7 @@ let app = new Vue({ blue = Number.parseInt(blue); converted.hex = "#" + this.rgbaToHexa(red, green, blue, alpha); + converted.rgb = "rgba(" + red + ", " + green + ", " + blue + ", " + alpha + ")"; let hsl = this.rgbToHsl(red, green, blue); @@ -367,6 +372,12 @@ console.error('hexa to HSLa not implemented yet'); } return alpha.toFixed(1); - } + }, + + updateClipboard: function (text) { + clipboard.writeText(text).then(() => { + console.log('text copied!'); + }); + }, }, });