Skip to content

Commit eff2d4b

Browse files
webcrawlspepelsbey
andauthored
feat: add 'copy css' button to tools/border-image-generator (#174)
* feat: add 'click to copy CSS' button to tools/border-image-generator * fix: replace `mousedown` listener with `onclick` * `mousedown` triggers for both right and middle-clicks, which does not align with the UX of a button. `onclick` is a more 'canonical' option. * fix: correct `click` listener typo * Fix code style --------- Co-authored-by: Vadim Makeev <vmakeev@mozilla.com>
1 parent 984cb14 commit eff2d4b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

tools/border-image-generator/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@
148148
</div>
149149

150150
<div id="output" class="category">
151-
<div class="title">CSS Code</div>
151+
<div class="title">
152+
CSS Code <button type="button" id="copy-css">Click to Copy</button>
153+
</div>
152154
<div class="css-property">
153155
<span class="name"> border-image-slice: </span>
154156
<span id="out-border-slice" class="value"> </span>

tools/border-image-generator/script.js

+20
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,25 @@ var BorderImage = (function BorderImage() {
12671267
}
12681268
};
12691269

1270+
var initCodeOutput = function initCodeOutput() {
1271+
var copyButton = getElemById("copy-css");
1272+
1273+
var copy = function copy() {
1274+
let output = "";
1275+
1276+
for (const property of document.querySelectorAll(".css-property")) {
1277+
const name = property.querySelector(".name").innerText;
1278+
const value = property.querySelector(".value").innerText;
1279+
1280+
output += name + " " + value + "\n";
1281+
}
1282+
1283+
navigator.clipboard.writeText(output);
1284+
};
1285+
1286+
copyButton.addEventListener("click", copy);
1287+
};
1288+
12701289
var init = function init() {
12711290
var gallery = (subject = getElemById("subject"));
12721291
preview = getElemById("preview");
@@ -1281,6 +1300,7 @@ var BorderImage = (function BorderImage() {
12811300
initBorderSliceControls();
12821301
initBorderWidthControls();
12831302
initBorderOutsetControls();
1303+
initCodeOutput();
12841304

12851305
var elem = document.querySelectorAll(".guideline");
12861306
var size = elem.length;

tools/border-image-generator/styles.css

+19
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,25 @@ body[data-move="Y"] {
972972
color: #aaa;
973973
}
974974

975+
#output .title #copy-css {
976+
float: right;
977+
978+
background-color: unset;
979+
color: inherit;
980+
border: 1px solid #ccc;
981+
border-radius: 3px;
982+
box-shadow: 0 0 3px 0 #bababa;
983+
}
984+
985+
#controls .category:hover #copy-css:not(:hover) {
986+
color: #aaa;
987+
}
988+
989+
#output .title #copy-css:hover {
990+
cursor: pointer;
991+
color: #777;
992+
}
993+
975994
#output .css-property {
976995
width: 100%;
977996
margin: 0;

0 commit comments

Comments
 (0)