From de5814699aaa872f56837129472bf17addab141a Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 26 May 2020 15:58:27 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20add=20right-align=20?= =?UTF-8?q?and=20icon=20options=20to=20dropdowns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../addon/components/rose/header.stories.mdx | 48 ++++++++++++------- .../rose/components/header/_catchall.scss | 2 - .../rose/components/header/_dropdown.scss | 31 +++++++++++- .../styles/rose/components/header/_index.scss | 1 + .../rose/components/header/_utilities.scss | 9 ++++ .../templates/components/rose/header.hbs | 6 ++- .../components/rose/header/dropdown.hbs | 18 ++++++- .../components/rose/header/utilities.hbs | 12 ++--- .../rose/tests/dummy/app/templates/index.hbs | 18 +++---- .../components/rose/header/dropdown-test.js | 15 ++++++ 10 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 addons/rose/addon/styles/rose/components/header/_utilities.scss diff --git a/addons/rose/addon/components/rose/header.stories.mdx b/addons/rose/addon/components/rose/header.stories.mdx index d546e5c5e..bffd410b7 100644 --- a/addons/rose/addon/components/rose/header.stories.mdx +++ b/addons/rose/addon/components/rose/header.stories.mdx @@ -1,7 +1,7 @@ import { Meta, Story, Preview } from '@storybook/addon-docs/blocks'; import { hbs } from 'ember-cli-htmlbars'; import { action } from '@storybook/addon-actions'; -import { text, boolean } from '@storybook/addon-knobs'; +import { text, boolean, select } from '@storybook/addon-knobs'; @@ -24,12 +24,14 @@ A header component that allows three distinct sections to be configured: brand, - - Click me - - link - button - + + Menu item + Menu item + Button menu item @@ -39,7 +41,7 @@ A header component that allows three distinct sections to be configured: brand, {{ template: hbs` - + Menu item @@ -50,21 +52,31 @@ A header component that allows three distinct sections to be configured: brand, Section - - - - link - button - + + Menu item + Menu item + Button menu item `, context: { - 'nav-dropdown-label': text('nav-dropdown-label', 'org-name'), - 'nav-dropdown-link-label': text('nav-dropdown-link-label', 'Menu Item'), - 'nav-dropdown-button-label': text('nav-dropdown-button-label', 'Menu Item'), - 'nav-link-label': text('nav-link-label', 'Section'), + brandName: text('brandName', 'Brand Name'), + dropdownIcon: select( + 'dropdownIcon', + { + 'user-square-fill': 'user-square-fill', + 'check-circle-outline': 'check-circle-outline', + 'copy-action': 'copy-action', + 'unfold-more': 'unfold-more', + 'unfold-less': 'unfold-less', + }, + 'user-square-fill' + ), }, }} diff --git a/addons/rose/addon/styles/rose/components/header/_catchall.scss b/addons/rose/addon/styles/rose/components/header/_catchall.scss index 0d01e8090..dddb4761a 100644 --- a/addons/rose/addon/styles/rose/components/header/_catchall.scss +++ b/addons/rose/addon/styles/rose/components/header/_catchall.scss @@ -12,7 +12,6 @@ .rose-header-nav, .rose-header-utilities { .rose-header-dropdown { - .rose-header-dropdown-content { position: absolute; background-color: var(--white); @@ -24,7 +23,6 @@ &.rose-header-dropdown-content-right { right: sizing.rems(s); } - } } } diff --git a/addons/rose/addon/styles/rose/components/header/_dropdown.scss b/addons/rose/addon/styles/rose/components/header/_dropdown.scss index 3584c3126..bf6ab366d 100644 --- a/addons/rose/addon/styles/rose/components/header/_dropdown.scss +++ b/addons/rose/addon/styles/rose/components/header/_dropdown.scss @@ -12,10 +12,30 @@ $dropdown-chevron: ( .rose-header-dropdown-trigger { cursor: default; + overflow: hidden; + display: flex; + align-items: center; color: var(--white); background: url(map.get($dropdown-chevron, default)) no-repeat right center; + background-size: sizing.rems(m); margin-right: sizing.rems(s); - padding-right: sizing.rems(l); + padding-right: sizing.rems(l) - sizing.rems(xxs); + $lineHeight: 48 / 16; + line-height: $lineHeight; + + &.icon-only { + padding-right: sizing.rems(m); + + .rose-header-dropdown-trigger-text { + // TODO: factor out into visually-hidden mixin utility + position: absolute; + left: -1000px; + top: -1000px; + width: 1px; + height: 1px; + opacity: 0; + } + } // Hide default twistie triangle // Webkit / Chromium @@ -27,6 +47,15 @@ $dropdown-chevron: ( &::marker { display: none; } + + .rose-icon { + display: inline-block; + height: var(--size); + + > svg { + vertical-align: top; + } + } } .rose-header-dropdown-content { diff --git a/addons/rose/addon/styles/rose/components/header/_index.scss b/addons/rose/addon/styles/rose/components/header/_index.scss index fd0595fe6..6ba8aba30 100644 --- a/addons/rose/addon/styles/rose/components/header/_index.scss +++ b/addons/rose/addon/styles/rose/components/header/_index.scss @@ -4,6 +4,7 @@ @import 'brand'; @import 'nav'; +@import 'utilities'; @import 'link'; @import 'dropdown'; diff --git a/addons/rose/addon/styles/rose/components/header/_utilities.scss b/addons/rose/addon/styles/rose/components/header/_utilities.scss new file mode 100644 index 000000000..ad28137ff --- /dev/null +++ b/addons/rose/addon/styles/rose/components/header/_utilities.scss @@ -0,0 +1,9 @@ +@use '../../variables/sizing'; + +.rose-header-utilities { + grid-area: utilities; + display: flex; + flex-wrap: wrap; + flex-direction: row-reverse; + align-items: center; +} diff --git a/addons/rose/addon/templates/components/rose/header.hbs b/addons/rose/addon/templates/components/rose/header.hbs index 0d3efc51a..2d355f398 100644 --- a/addons/rose/addon/templates/components/rose/header.hbs +++ b/addons/rose/addon/templates/components/rose/header.hbs @@ -1,5 +1,7 @@ -
+
{{yield (hash brand=(component 'rose/header/brand') utilities=(component 'rose/header/utilities') diff --git a/addons/rose/addon/templates/components/rose/header/dropdown.hbs b/addons/rose/addon/templates/components/rose/header/dropdown.hbs index f9376ddfe..86406b2d9 100644 --- a/addons/rose/addon/templates/components/rose/header/dropdown.hbs +++ b/addons/rose/addon/templates/components/rose/header/dropdown.hbs @@ -4,8 +4,22 @@ {{on-click-outside this.close}} > - - {{@text}} + + + {{#if @icon}} + + {{/if}} + + + {{@text}} + +
diff --git a/addons/rose/addon/templates/components/rose/header/utilities.hbs b/addons/rose/addon/templates/components/rose/header/utilities.hbs index eefb15e8d..6ee49e33f 100644 --- a/addons/rose/addon/templates/components/rose/header/utilities.hbs +++ b/addons/rose/addon/templates/components/rose/header/utilities.hbs @@ -1,7 +1,5 @@ - - - {{yield (hash - dropdown=(component 'rose/header/dropdown' position="true") - )}} - - +
+ {{yield (hash + dropdown=(component 'rose/header/dropdown' alignRight=true) + )}} +
diff --git a/addons/rose/tests/dummy/app/templates/index.hbs b/addons/rose/tests/dummy/app/templates/index.hbs index aaa68d9be..400f1d6f1 100644 --- a/addons/rose/tests/dummy/app/templates/index.hbs +++ b/addons/rose/tests/dummy/app/templates/index.hbs @@ -12,17 +12,19 @@ Section - {{!-- + - - - - link - button - + + Menu item + Menu item + Button menu item - --}} + diff --git a/addons/rose/tests/integration/components/rose/header/dropdown-test.js b/addons/rose/tests/integration/components/rose/header/dropdown-test.js index fcb355cf1..96806b98b 100644 --- a/addons/rose/tests/integration/components/rose/header/dropdown-test.js +++ b/addons/rose/tests/integration/components/rose/header/dropdown-test.js @@ -27,6 +27,21 @@ module('Integration | Component | rose/header/dropdown', function (hooks) { ); }); + test('it supports an icon', async function (assert) { + await render(hbs``); + assert.ok(find('svg')); + }); + + test('it supports icon-only display', async function (assert) { + await render(hbs``); + assert.ok(find('.icon-only')); + }); + + test('it supports right-aligned content', async function (assert) { + await render(hbs``); + assert.ok(find('.dropdown-right')); + }); + test('it renders with content', async function (assert) { await render(hbs`