From 7fbfab669c937f2f774a1fc1862997e3cc2a2950 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 15 Mar 2022 12:54:56 +0000 Subject: [PATCH] ui: DisclosureCard component (#12541) --- .../app/components/disclosure-card/README.mdx | 125 ++++++++++++++++++ .../app/components/disclosure-card/index.hbs | 90 +++++++++++++ .../app/components/panel/index.css.js | 31 +++++ .../consul-ui/app/helpers/dom-position.js | 10 ++ ui/packages/consul-ui/app/helpers/require.js | 9 +- .../styles/base/icons/base-keyframes.css.js | 91 +++++++++++++ .../icons/icons/chevron-down/index.css.js | 16 +++ .../base/icons/icons/chevron-up/index.css.js | 16 +++ .../icons/icons/chevrons-down/index.css.js | 17 +++ 9 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 ui/packages/consul-ui/app/components/disclosure-card/README.mdx create mode 100644 ui/packages/consul-ui/app/components/disclosure-card/index.hbs create mode 100644 ui/packages/consul-ui/app/components/panel/index.css.js create mode 100644 ui/packages/consul-ui/app/styles/base/icons/base-keyframes.css.js create mode 100644 ui/packages/consul-ui/app/styles/base/icons/icons/chevron-down/index.css.js create mode 100644 ui/packages/consul-ui/app/styles/base/icons/icons/chevron-up/index.css.js create mode 100644 ui/packages/consul-ui/app/styles/base/icons/icons/chevrons-down/index.css.js diff --git a/ui/packages/consul-ui/app/components/disclosure-card/README.mdx b/ui/packages/consul-ui/app/components/disclosure-card/README.mdx new file mode 100644 index 000000000..098456452 --- /dev/null +++ b/ui/packages/consul-ui/app/components/disclosure-card/README.mdx @@ -0,0 +1,125 @@ + +# DisclosureCard + + +```hbs preview-template + +
+ +
+ Use the component +
+ + + +
+

api-service-1

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{if disclosure.expanded "View less" "View more"}} + + +
+ +
+``` + +## Attributes + + + + +## Arguments + + + + +## Slots + + + + +## CSS Parts + + + + +## CSS Properties + + + + +## Contextual Components + + + diff --git a/ui/packages/consul-ui/app/components/disclosure-card/index.hbs b/ui/packages/consul-ui/app/components/disclosure-card/index.hbs new file mode 100644 index 000000000..9ce8bb5ed --- /dev/null +++ b/ui/packages/consul-ui/app/components/disclosure-card/index.hbs @@ -0,0 +1,90 @@ + + + + + +
+
+ + +
+
+ + +
+
+ + {{yield disclosure}} + +
+
+
diff --git a/ui/packages/consul-ui/app/components/panel/index.css.js b/ui/packages/consul-ui/app/components/panel/index.css.js new file mode 100644 index 000000000..68179f056 --- /dev/null +++ b/ui/packages/consul-ui/app/components/panel/index.css.js @@ -0,0 +1,31 @@ +export default (css) => css` + .panel { + --padding-x: 14px; + --padding-y: 14px; + } + .panel { + position: relative; + } + .panel-separator { + margin: 0; + } + + .panel { + --tone-border: var(--tone-gray-300); + border: var(--decor-border-100); + border-radius: var(--decor-radius-200); + box-shadow: var(--decor-elevation-600); + } + .panel-separator { + border: 0; + border-top: var(--decor-border-100); + } + .panel { + color: rgb(var(--tone-gray-900)); + background-color: rgb(var(--tone-gray-000)); + } + .panel, + .panel-separator { + border-color: rgb(var(--tone-border)); + } +`; diff --git a/ui/packages/consul-ui/app/helpers/dom-position.js b/ui/packages/consul-ui/app/helpers/dom-position.js index 6b1300d0b..d28c95700 100644 --- a/ui/packages/consul-ui/app/helpers/dom-position.js +++ b/ui/packages/consul-ui/app/helpers/dom-position.js @@ -24,6 +24,16 @@ export default class DomPosition extends Helper { } } return target(rect); + } else { + // if we are using this as part of an on-resize + // provide and easy way to map coords to CSS props + const $el = e.target; + const rect = $el.getBoundingClientRect(); + target.forEach( + ([prop, value]) => { + $el.style[value] = `${rect[prop]}px`; + } + ); } }; } diff --git a/ui/packages/consul-ui/app/helpers/require.js b/ui/packages/consul-ui/app/helpers/require.js index 2955f058d..1a8d9950d 100644 --- a/ui/packages/consul-ui/app/helpers/require.js +++ b/ui/packages/consul-ui/app/helpers/require.js @@ -4,16 +4,23 @@ import { css } from '@lit/reactive-element'; import resolve from 'consul-ui/utils/path/resolve'; + +import panel from 'consul-ui/components/panel/index.css'; import distributionMeter from 'consul-ui/components/distribution-meter/index.css'; import distributionMeterMeter from 'consul-ui/components/distribution-meter/meter/index.css'; import distributionMeterMeterElement from 'consul-ui/components/distribution-meter/meter/element'; import visuallyHidden from 'consul-ui/styles/base/decoration/visually-hidden.css'; +import baseKeyframes from 'consul-ui/styles/base/icons/base-keyframes.css'; +import chevronDown from 'consul-ui/styles/base/icons/icons/chevron-down/index.css'; const fs = { + ['/components/panel/index.css']: panel, ['/components/distribution-meter/index.css']: distributionMeter, ['/components/distribution-meter/meter/index.css']: distributionMeterMeter, ['/components/distribution-meter/meter/element']: distributionMeterMeterElement, - ['/styles/base/decoration/visually-hidden.css']: visuallyHidden + ['/styles/base/decoration/visually-hidden.css']: visuallyHidden, + ['/styles/base/icons/base-keyframes.css']: baseKeyframes, + ['/styles/base/icons/icons/chevron-down/index.css']: chevronDown }; const container = new Map(); diff --git a/ui/packages/consul-ui/app/styles/base/icons/base-keyframes.css.js b/ui/packages/consul-ui/app/styles/base/icons/base-keyframes.css.js new file mode 100644 index 000000000..0a142062e --- /dev/null +++ b/ui/packages/consul-ui/app/styles/base/icons/base-keyframes.css.js @@ -0,0 +1,91 @@ +export default css => css` +*::before, *::after { + display: inline-block; + animation-play-state: paused; + animation-fill-mode: forwards; + animation-iteration-count: var(--icon-resolution, 1); + vertical-align: text-top; +} +*::before { + animation-name: var(--icon-name-start, var(--icon-name)), + var(--icon-size-start, var(--icon-size, icon-000)); + background-color: var(--icon-color-start, var(--icon-color)); +} +*::after { + animation-name: var(--icon-name-end, var(--icon-name)), + var(--icon-size-end, var(--icon-size, icon-000)); + background-color: var(--icon-color-end, var(--icon-color)); +} + +[style*='--icon-color-start']::before { + color: var(--icon-color-start); +} +[style*='--icon-color-end']::after { + color: var(--icon-color-end); +} +[style*='--icon-name-start']::before, +[style*='--icon-name-end']::after { + content: ''; +} + +@keyframes icon-000 { + 100% { + width: 1.2em; + height: 1.2em; + } +} +@keyframes icon-100 { + 100% { + width: 0.625rem; /* 10px */ + height: 0.625rem; /* 10px */ + } +} +@keyframes icon-200 { + 100% { + width: 0.75rem; /* 12px */ + height: 0.75rem; /* 12px */ + } +} +@keyframes icon-300 { + 100% { + width: 1rem; /* 16px */ + height: 1rem; /* 16px */ + } +} +@keyframes icon-400 { + 100% { + width: 1.125rem; /* 18px */ + height: 1.125rem; /* 18px */ + } +} +@keyframes icon-500 { + 100% { + width: 1.250rem; /* 20px */ + height: 1.250rem; /* 20px */ + } +} +@keyframes icon-600 { + 100% { + width: 1.375rem; /* 22px */ + height: 1.375rem; /* 22px */ + } +} +@keyframes icon-700 { + 100% { + width: 1.500rem; /* 24px */ + height: 1.500rem; /* 24px */ + } +} +@keyframes icon-800 { + 100% { + width: 1.625rem; /* 26px */ + height: 1.625rem; /* 26px */ + } +} +@keyframes icon-900 { + 100% { + width: 1.750rem; /* 28px */ + height: 1.750rem; /* 28px */ + } +} +`; diff --git a/ui/packages/consul-ui/app/styles/base/icons/icons/chevron-down/index.css.js b/ui/packages/consul-ui/app/styles/base/icons/icons/chevron-down/index.css.js new file mode 100644 index 000000000..3f3c16e19 --- /dev/null +++ b/ui/packages/consul-ui/app/styles/base/icons/icons/chevron-down/index.css.js @@ -0,0 +1,16 @@ +export default css => css ` +@keyframes icon-chevron-down { + 50% { + + background-color: var(--icon-color, var(--color-chevron-down-500, currentColor)); + -webkit-mask-image: var(--icon-chevron-down-24); + mask-image: var(--icon-chevron-down-24); + } + + 100% { + + background-color: var(--icon-color, var(--color-chevron-down-500, currentColor)); + -webkit-mask-image: var(--icon-chevron-down-16); + mask-image: var(--icon-chevron-down-16); + } +}`; diff --git a/ui/packages/consul-ui/app/styles/base/icons/icons/chevron-up/index.css.js b/ui/packages/consul-ui/app/styles/base/icons/icons/chevron-up/index.css.js new file mode 100644 index 000000000..8d854af7d --- /dev/null +++ b/ui/packages/consul-ui/app/styles/base/icons/icons/chevron-up/index.css.js @@ -0,0 +1,16 @@ +export default css => css ` +@keyframes icon-chevron-up { + 50% { + + background-color: var(--icon-color, var(--color-chevron-up-500, currentColor)); + -webkit-mask-image: var(--icon-chevron-up-24); + mask-image: var(--icon-chevron-up-24); + } + + 100% { + + background-color: var(--icon-color, var(--color-chevron-up-500, currentColor)); + -webkit-mask-image: var(--icon-chevron-up-16); + mask-image: var(--icon-chevron-up-16); + } +}`; diff --git a/ui/packages/consul-ui/app/styles/base/icons/icons/chevrons-down/index.css.js b/ui/packages/consul-ui/app/styles/base/icons/icons/chevrons-down/index.css.js new file mode 100644 index 000000000..256442d86 --- /dev/null +++ b/ui/packages/consul-ui/app/styles/base/icons/icons/chevrons-down/index.css.js @@ -0,0 +1,17 @@ +export default css => css ` +@keyframes icon-chevrons-down { + 50% { + + background-color: var(--icon-color, var(--color-chevrons-down-500, currentColor)); + -webkit-mask-image: var(--icon-chevrons-down-24); + mask-image: var(--icon-chevrons-down-24); + } + + 100% { + + background-color: var(--icon-color, var(--color-chevrons-down-500, currentColor)); + -webkit-mask-image: var(--icon-chevrons-down-16); + mask-image: var(--icon-chevrons-down-16); + } +} +`;