Skip to content

Commit

Permalink
feat(Tag): add support for background gradient (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
THoj13 committed Sep 2, 2021
1 parent 6193b31 commit 952cbcf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions elements/Tag/Tag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ name|type|required|default|description
backgroundColor|color|true|#232328|color of the tag's background
title|string|true|-|text to display in tag
titleColor|color|false|#ffffff|color of text
gradientColor|color|false|-|color of gradient

### Styles

Expand Down
3 changes: 3 additions & 0 deletions elements/Tag/Tag.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Basic = args =>
Tag: {
type: Tag,
backgroundColor: args.backgroundColor,
gradientColor: args.gradientColor,
title: args.title,
titleColor: args.titleColor
}
Expand All @@ -31,10 +32,12 @@ export const Basic = args =>
};
Basic.args = {
backgroundColor: '#f6a50a',
gradientColor: undefined,
title: 'Tag',
titleColor: '#ffffff'
};
Basic.argTypes = {
backgroundColor: { control: 'color' },
gradientColor: { control: 'color' },
titleColor: { control: 'color' }
};
8 changes: 8 additions & 0 deletions elements/Tag/Tag.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TestUtils from '../../test/lightning-test-utils';
import { getValidColor } from '../../Styles';
import Tag from '.';

const createComponent = TestUtils.makeCreateComponent(Tag);
Expand Down Expand Up @@ -45,4 +46,11 @@ describe('Tag', () => {
expect(tag.w).toBe(68);
});
});

it('changes background color gradient', () => {
const gradientColor = '#000000';
[tag, testRenderer] = createComponent({ gradientColor });
testRenderer.update();
expect(tag._Background.colorRight).toEqual(getValidColor(gradientColor));
});
});
11 changes: 10 additions & 1 deletion elements/Tag/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export default class Tag extends withStyles(Base, styles) {
}

static get properties() {
return ['backgroundColor', 'radius', 'title', 'titleColor'];
return [
'backgroundColor',
'gradientColor',
'radius',
'title',
'titleColor'
];
}

static get tags() {
Expand Down Expand Up @@ -75,6 +81,9 @@ export default class Tag extends withStyles(Base, styles) {
this.backgroundColor || getValidColor('#232328')
)
});
if (this.gradientColor) {
this._Background.colorRight = getValidColor(this.gradientColor);
}
}

_setBackgroundColor(color) {
Expand Down

0 comments on commit 952cbcf

Please sign in to comment.