From 466d98a228698832e1124da51b95d5e55d7b9a0a Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Mon, 15 Jun 2020 16:54:26 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Add=20link-button=20ros?= =?UTF-8?q?e=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Link-button rose component mimics button rose component, with the exception of being an anchor element instead of a button. --- .../rose/addon/components/rose/link-button.js | 14 +++ .../components/rose/link-button.stories.mdx | 103 ++++++++++++++++++ .../addon/styles/rose/components/_index.scss | 1 + .../styles/rose/components/_link-button.scss | 40 +++++++ .../templates/components/rose/link-button.hbs | 35 ++++++ .../rose/app/components/rose/link-button.js | 1 + .../rose/tests/dummy/app/templates/index.hbs | 21 ++-- .../tests/dummy/app/templates/playground.hbs | 9 ++ .../components/rose/link-button-test.js | 58 ++++++++++ 9 files changed, 274 insertions(+), 8 deletions(-) create mode 100644 addons/rose/addon/components/rose/link-button.js create mode 100644 addons/rose/addon/components/rose/link-button.stories.mdx create mode 100644 addons/rose/addon/styles/rose/components/_link-button.scss create mode 100644 addons/rose/addon/templates/components/rose/link-button.hbs create mode 100644 addons/rose/app/components/rose/link-button.js create mode 100644 addons/rose/tests/integration/components/rose/link-button-test.js diff --git a/addons/rose/addon/components/rose/link-button.js b/addons/rose/addon/components/rose/link-button.js new file mode 100644 index 000000000..32e084f7e --- /dev/null +++ b/addons/rose/addon/components/rose/link-button.js @@ -0,0 +1,14 @@ +import Component from '@ember/component'; +import layout from '../../templates/components/rose/link-button'; + +/** + * An achor element based on `rose-button` component styles + * + * @example + * Save + * Disabled + */ +export default Component.extend({ + layout, + tagName: '', +}); diff --git a/addons/rose/addon/components/rose/link-button.stories.mdx b/addons/rose/addon/components/rose/link-button.stories.mdx new file mode 100644 index 000000000..b29afbcd0 --- /dev/null +++ b/addons/rose/addon/components/rose/link-button.stories.mdx @@ -0,0 +1,103 @@ +import { Meta, Story, Preview } from '@storybook/addon-docs/blocks'; +import { hbs } from 'ember-cli-htmlbars'; +import { action } from '@storybook/addon-actions'; +import { text, boolean, select } from '@storybook/addon-knobs'; + + + +# LinkButton + +An achor element component styled to mimic `Rose::Button` component. +Styles supported: primary, secondary, warning, and ghost. + +```html + + Content + +``` + + + {{ + template: hbs` + + {{text}} + + `, + context: { + text: text('text', 'Content'), + disabled: boolean('disabled', false), + style: select( + 'style', + { + primary: 'primary', + secondary: 'secondary', + warning: 'warning', + ghost: 'ghost', + 'inline-link-action': 'inline-link-action', + }, + 'primary' + ), + iconLeft: select( + 'iconLeft', + { + 'check-circle-outline': 'check-circle-outline', + 'copy-action': 'copy-action', + 'unfold-more': 'unfold-more', + }, + 'copy-action' + ), + iconRight: select( + 'iconRight', + { + 'check-circle-outline': 'check-circle-outline', + 'chevron-right': 'chevron-right', + 'copy-action': 'copy-action', + 'search': 'search', + }, + 'chevron-right' + ), + }, + }} + + +Similar to `Rose::Button`, icon only link button is supported. + +```html + +``` + + + {{ + template: hbs` + + `, + context: { + style: select( + 'style', + { + primary: 'primary', + secondary: 'secondary', + warning: 'warning', + ghost: 'ghost', + 'inline-link-action': 'inline-link-action', + }, + 'primary' + ), + iconOnly: select( + 'iconOnly', + { + 'check-circle-outline': 'check-circle-outline', + 'help-circle-outline': 'help-circle-outline', + 'plus-circle-fill': 'plus-circle-fill', + 'user-square-outline': 'user-square-outline', + }, + 'help-circle-outline' + ), + }, + }} + diff --git a/addons/rose/addon/styles/rose/components/_index.scss b/addons/rose/addon/styles/rose/components/_index.scss index 948a7b735..66b1f3043 100644 --- a/addons/rose/addon/styles/rose/components/_index.scss +++ b/addons/rose/addon/styles/rose/components/_index.scss @@ -11,3 +11,4 @@ @import 'nav'; @import 'table'; @import 'message'; +@import 'link-button'; diff --git a/addons/rose/addon/styles/rose/components/_link-button.scss b/addons/rose/addon/styles/rose/components/_link-button.scss new file mode 100644 index 000000000..fe9a6aa54 --- /dev/null +++ b/addons/rose/addon/styles/rose/components/_link-button.scss @@ -0,0 +1,40 @@ +// Link button uses rose-button styling +.rose-link-button { + text-decoration: none; + + // Modify link disabled state to match button disabled state + &.disabled { + cursor: not-allowed; + opacity: var(--opacity-1); + box-shadow: none; + + &:hover { + opacity: var(--opacity-1); + box-shadow: none; + } + + &.rose-button-primary:hover { + color: var(--white); + background-color: var(--info); + border-color: var(--info-starker-2); + } + + &.rose-button-secondary:hover { + color: var(--ui-gray-starker-3); + border-color: var(--ui-gray-subtler-2); + background-color: var(--ui-gray-subtler-5); + } + + &.rose-button-warning:hover { + color: var(--failure); + border-color: var(--failure); + background-color: var(--subtle); + text-shadow: none; + } + + &.rose-button-ghost:hover { + color: var(--info); + border-color: var(--subtle); + } + } +} diff --git a/addons/rose/addon/templates/components/rose/link-button.hbs b/addons/rose/addon/templates/components/rose/link-button.hbs new file mode 100644 index 000000000..e3bcb61e5 --- /dev/null +++ b/addons/rose/addon/templates/components/rose/link-button.hbs @@ -0,0 +1,35 @@ + + + + {{#if @iconLeft}} + + {{/if}} + + + {{yield}} + + + {{#if @iconOnly}} + + {{/if}} + + {{#if @iconRight}} + + {{/if}} + + diff --git a/addons/rose/app/components/rose/link-button.js b/addons/rose/app/components/rose/link-button.js new file mode 100644 index 000000000..6dc4bbe0a --- /dev/null +++ b/addons/rose/app/components/rose/link-button.js @@ -0,0 +1 @@ +export { default } from 'rose/components/rose/link-button'; \ No newline at end of file diff --git a/addons/rose/tests/dummy/app/templates/index.hbs b/addons/rose/tests/dummy/app/templates/index.hbs index dde1dea20..c12b92974 100644 --- a/addons/rose/tests/dummy/app/templates/index.hbs +++ b/addons/rose/tests/dummy/app/templates/index.hbs @@ -1,8 +1,13 @@ - - - - Namespaces allow you to create distinct areas with their own separate policies, mounts, tokens, and identity entities. - - Add a namespace - - +Primary +Secondary +Warning +Ghost +
+Primary +Secondary +Warning +Ghost +
+Left Icon +Right Icon + diff --git a/addons/rose/tests/dummy/app/templates/playground.hbs b/addons/rose/tests/dummy/app/templates/playground.hbs index 3d4559c6b..5f02a47ef 100644 --- a/addons/rose/tests/dummy/app/templates/playground.hbs +++ b/addons/rose/tests/dummy/app/templates/playground.hbs @@ -284,5 +284,14 @@ Add a namespace + + + + + Namespaces allow you to create distinct areas with their own separate policies, mounts, tokens, and identity entities. + + Add a namespace + + diff --git a/addons/rose/tests/integration/components/rose/link-button-test.js b/addons/rose/tests/integration/components/rose/link-button-test.js new file mode 100644 index 000000000..6ef4f71ba --- /dev/null +++ b/addons/rose/tests/integration/components/rose/link-button-test.js @@ -0,0 +1,58 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render, find } from '@ember/test-helpers'; +import hbs from 'htmlbars-inline-precompile'; + +module('Integration | Component | rose/link-button', function(hooks) { + setupRenderingTest(hooks); + + test('it renders', async function(assert) { + await render(hbs``); + assert.ok(find('a')); + assert.notOk(find('.disabled')); + assert.notOk(find('.rose-button')); + assert.ok(find('.rose-link-button')); + }); + + test('it renders with attributes', async function(assert) { + await render(hbs``); + assert.ok(find('#link-button')); + }); + + test('it renders with content', async function(assert) { + await render(hbs`Link button content`); + assert.ok(find('.rose-link-button').textContent.trim(), 'Link button content'); + }); + + test('it renders disabled when @disabled={{true}}', async function(assert) { + await render(hbs``); + assert.ok(find('.disabled')); + }); + + test('it renders with rose button styles', async function(assert) { + this.set('style', 'primary'); + await render(hbs``); + assert.ok(find(`.rose-button-primary`)); + + this.set('style', 'sample'); + assert.ok(find(`.rose-button-sample`)); + }); + + test('it supports left icon with @iconLeft', async function(assert) { + await render(hbs``); + assert.ok(find('.rose-icon')); + assert.ok(find('.has-icon-left')); + }); + + test('it supports left icon with @iconRight', async function(assert) { + await render(hbs``); + assert.ok(find('.rose-icon')); + assert.ok(find('.has-icon-right')); + }); + + test('it supports only icon with @iconOnly', async function(assert) { + await render(hbs``); + assert.ok(find('.rose-icon')); + assert.ok(find('.has-icon-only')); + }); +});