Skip to content

Commit

Permalink
feat(icon): variant property (#118)
Browse files Browse the repository at this point in the history
* feat(icon): variant property

* fix: updated constants

* feat: added test case
  • Loading branch information
shibulijack-fd authored Feb 18, 2020
1 parent e950af4 commit 7905cac
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ yarn add @freshworks/icon
{{#docs-demo as |demo|}}
{{#demo.example name='nucleus-icon-eg.hbs'}}
{{nucleus-icon name="nucleus-circle-check" size="small"}}
{{nucleus-icon name="nucleus-circle-cross" size="medium"}}
{{nucleus-icon name="nucleus-circle-help" size="large"}}
{{nucleus-icon name="nucleus-circle-cross" size="medium" variant="danger"}}
{{nucleus-icon name="nucleus-circle-help" size="large" variant="success"}}
{{/demo.example}}
{{demo.snippet 'nucleus-icon-eg.hbs'}}
{{/docs-demo}}
Expand Down
16 changes: 0 additions & 16 deletions packages/banner/addon/styles/components/_nucleus-banner-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@
position: relative;
top: 2px;
margin-right: 4px;

&.warning {
color: $text-warning;
}

&.danger {
color: $text-danger;
}

&.info {
color: $text-info;
}

&.success {
color: $text-success;
}
}

&__link {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{#if item.componentName}}
{{component item.componentName props=item.componentProps}}
{{else}}
<div class="nucleus-banner-item__icon {{item.type}}">
{{nucleus-icon name=bannerIcon size="medium"}}
<div class="nucleus-banner-item__icon">
{{nucleus-icon name=bannerIcon size="medium" variant=item.type}}
</div>
<div class="nucleus-banner-item__content">
{{item.title}}
Expand Down
23 changes: 19 additions & 4 deletions packages/icon/addon/components/nucleus-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { computed } from '@ember/object';
import Component from '@ember/component';
import layout from "../templates/components/nucleus-icon";

const DEFAULT_SIZE = 'medium';
const DEFAULT_VARIANT = 'primary';

/**
__Usage:__
[Refer component page](/docs/components/nucleus-icon)
Expand Down Expand Up @@ -40,7 +43,18 @@ class NucleusIcon extends Component {
* @public
*/
@defaultProp
size = 'medium';
size = DEFAULT_SIZE;

/**
* Variant
*
* @field variant
* @type string
* @default null
* @public
*/
@defaultProp
variant = DEFAULT_VARIANT;

/**
* Custom class
Expand All @@ -59,11 +73,12 @@ class NucleusIcon extends Component {
* @computed _disabled
* @private
*/
@computed('size', 'customClass')
@computed('size', 'variant', 'customClass')
get _classNames() {
let customClass = this.get('customClass');
let size = this.get('size') ? this.get('size') : 'medium';
let classNames = `nucleus-icon nucleus-icon--${size}`;
let size = this.get('size');
let variant = this.get('variant');
let classNames = `nucleus-icon nucleus-icon--${size} nucleus-icon--${variant}`;
return customClass ? `${classNames} ${customClass}` : classNames;
}
}
Expand Down
27 changes: 27 additions & 0 deletions packages/icon/addon/styles/addon.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Globals
@import "nucleus/variables";

.nucleus-icon {
width: 12px;
height: 12px;
Expand All @@ -21,4 +24,28 @@
width: 16px;
height: 16px;
}

&--primary {
fill: $text-default;
}

&--secondary {
fill: $text-secondary;
}

&--danger {
fill: $text-danger;
}

&--warning {
fill: $text-warning;
}

&--success {
fill: $text-success;
}

&--info {
fill: $text-info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module('Integration | Component | nucleus-icon', function(hooks) {
assert.dom('svg').hasClass('nucleus-icon--mini', 'icon has correct size class');
});

test('it has correct variant', async function(assert) {
await render(hbs`{{nucleus-icon name="nucleus-cross" variant="danger"}}`);

assert.dom('svg').hasClass('nucleus-icon--danger', 'icon has correct variant class');
});

test('it passes a11y tests', async function(assert) {
await render(hbs`{{nucleus-icon name="nucleus-cross"}}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
background-color: $bg-warning;
border: 1px solid $border-warning-color;

.nucleus-inline-banner__icon {
background-color: $bg-warning;
color: $text-warning;
}

.nucleus-inline-banner__content {
color: $text-default;
border-left-color: $border-warning-color;
Expand All @@ -46,11 +41,6 @@
background-color: $bg-danger;
border: 1px solid $border-danger-color;

.nucleus-inline-banner__icon {
background-color: $bg-danger;
color: $text-danger;
}

.nucleus-inline-banner__content {
color: $text-default;
border-left-color: $border-danger-color;
Expand All @@ -61,11 +51,6 @@
background-color: $bg-info;
border: 1px solid $border-info-color;

.nucleus-inline-banner__icon {
background-color: $bg-info;
color: $text-info;
}

.nucleus-inline-banner__content {
color: $text-default;
border-left-color: $border-info-color;
Expand All @@ -76,11 +61,6 @@
background-color: $bg-success;
border: 1px solid $border-success-color;

.nucleus-inline-banner__icon {
background-color: $bg-success;
color: $text-success;
}

.nucleus-inline-banner__content {
color: $text-default;
border-left-color: $border-success-color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}}
{{else}}
<div class="nucleus-inline-banner__icon">
{{nucleus-icon name=_icon size="medium"}}
{{nucleus-icon name=_icon size="medium" variant=type}}
</div>
<div class="nucleus-inline-banner__content">
<div data-test-id="nucleus-inline-banner-title">{{title}}</div>
Expand Down

0 comments on commit 7905cac

Please sign in to comment.