From b00e3653f2620f16fa8eadf41de66d4b7d62d183 Mon Sep 17 00:00:00 2001 From: Dan Cormier Date: Tue, 22 Mar 2022 18:05:36 -0400 Subject: [PATCH] Add code copy buttons to Card page Addresses https://github.com/StackExchange/Stacks/issues/829 --- docs/.eleventy.js | 29 ++++++++++++++++++++ docs/assets/js/controllers/clipboard.ts | 32 ++++++++++++++++++++++ docs/assets/less/stacks-documentation.less | 3 +- docs/product/components/cards.html | 27 +++++++++++++++++- 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 docs/assets/js/controllers/clipboard.ts diff --git a/docs/.eleventy.js b/docs/.eleventy.js index e530813f2f..a75af71d70 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -134,6 +134,35 @@ module.exports = function(eleventyConfig) { return output; }); + // Copy button shortcode + eleventyConfig.addLiquidShortcode("copybutton", function(name) { + var checkmarkIcon = Icons["Checkmark"]; + var copyIcon = Icons["Copy"]; + var tooltipId = "tooltip-" + (name || Math.floor(Math.random() * 1000)); + + var output = ''; + output += ''; + output += '' + copyIcon + ''; + output += '' + output += '
el.classList.add("d-none")); + showElements.map(el => el.classList.remove("d-none")); + + setTimeout(function () { + hideElements.map(el => el.classList.remove("d-none")); + showElements.map(el => el.classList.add("d-none")); + }, 3000); + } + }); +})(); \ No newline at end of file diff --git a/docs/assets/less/stacks-documentation.less b/docs/assets/less/stacks-documentation.less index acff8723dd..638a9ad550 100644 --- a/docs/assets/less/stacks-documentation.less +++ b/docs/assets/less/stacks-documentation.less @@ -255,7 +255,8 @@ box-shadow: none; }); - > pre.s-code-block { + > pre.s-code-block, + > .stacks-clipboard-content pre.s-code-block { border-radius: @br-md @br-md 0 0; border: 1px solid var(--bc-medium); max-height: 24rem; diff --git a/docs/product/components/cards.html b/docs/product/components/cards.html index f58ffdd769..d16b65ef13 100644 --- a/docs/product/components/cards.html +++ b/docs/product/components/cards.html @@ -9,6 +9,9 @@

The base card styling applies a border and padding to the card.

Cards can be any size and it’s ok to increase the body text size for larger cards.

+
+ {% copybutton %} + {% highlight html %}

@@ -16,6 +19,8 @@

{% endhighlight %} +
+

Base card title

@@ -41,12 +46,17 @@

Base card title

{% header "h2", "Box shadows" %}

Applying a .bs-* class adds a box shadow to a card. Useful when giving users the impression they can interact with the card.

+
+ {% copybutton %} + {% highlight html %}
{% endhighlight %} -
+ +
+

Small box shadow

@@ -70,6 +80,9 @@

Large box shadow

The .s-card class can be applied to an <a> tag for instances where a whole card should link somewhere. If possible, linked cards should visually indication that they’re interactive (ex. including an .s-btn or .s-link somewhere).

A :hover style for border color is automatically added to all linked cards. For linked cards with a box shadow (.bs-*), adding a .h:bs-* class will apply a hover style to the box shadow as well. Increasing the .bs- size by a factor of one is usually best.