Skip to content

Commit e2cbd28

Browse files
authored
feat: add support for tag icons (#1618)
1 parent c0f3985 commit e2cbd28

File tree

2 files changed

+77
-20
lines changed

2 files changed

+77
-20
lines changed

src/components/CvTag/CvTag.stories.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,39 @@ import {
55
sbCompPrefix,
66
storyParametersObject,
77
} from '../../global/storybook-utils';
8+
import {
9+
DataDefinition20,
10+
Bee20,
11+
Carbon20,
12+
Watson20,
13+
IbmCloud20,
14+
EdtLoop20,
15+
IbmSecurity20,
16+
} from '@carbon/icons-vue';
17+
18+
const icons = {
19+
DataDefinition20,
20+
Bee20,
21+
Carbon20,
22+
Watson20,
23+
IbmCloud20,
24+
EdtLoop20,
25+
IbmSecurity20,
26+
undefined,
27+
};
828

929
export default {
1030
title: `${sbCompPrefix}/CvTag`,
1131
component: CvTag,
1232
argTypes: {
1333
kind: { control: 'select', options: tagKinds },
34+
renderIcon: { control: { type: 'select', options: Object.keys(icons) } },
1435
},
1536
};
1637

1738
const template = `<cv-tag @remove="onRemove" v-bind="args" />`;
18-
const Template = (args, { argTypes }) => {
39+
const Template = (argsIn, { argTypes }) => {
40+
let args = { ...argsIn, renderIcon: icons[argsIn.renderIcon] };
1941
return {
2042
props: Object.keys(argTypes),
2143
components: { CvTag },
@@ -31,9 +53,14 @@ const Template = (args, { argTypes }) => {
3153

3254
export const Default = Template.bind({});
3355
Default.args = {
34-
label: 'This is a tag',
56+
label: 'Hugo Award winner',
3557
filter: false,
3658
};
59+
Default.parameters = {
60+
controls: {
61+
exclude: ['remove'],
62+
},
63+
};
3764
Default.parameters = storyParametersObject(
3865
Default.parameters,
3966
template,
@@ -42,8 +69,14 @@ Default.parameters = storyParametersObject(
4269

4370
export const Filter = Template.bind({});
4471
Filter.args = {
45-
label: 'This is a tag',
72+
label: 'Filter House',
4673
filter: true,
74+
kind: 'high-contrast',
75+
};
76+
Filter.parameters = {
77+
controls: {
78+
exclude: ['remove'],
79+
},
4780
};
4881
Filter.parameters = storyParametersObject(
4982
Filter.parameters,
@@ -56,8 +89,29 @@ Skeleton.args = {
5689
skeleton: true,
5790
label: '',
5891
};
92+
Skeleton.parameters = {
93+
controls: {
94+
include: ['small'],
95+
},
96+
};
5997
Skeleton.parameters = storyParametersObject(
6098
Skeleton.parameters,
6199
template,
62100
Skeleton.args
63101
);
102+
103+
export const TagIcon = Template.bind({});
104+
TagIcon.args = {
105+
renderIcon: 'DataDefinition20',
106+
label: 'Steampunk',
107+
};
108+
TagIcon.parameters = {
109+
controls: {
110+
include: ['renderIcon'],
111+
},
112+
};
113+
TagIcon.parameters = storyParametersObject(
114+
TagIcon.parameters,
115+
template,
116+
TagIcon.args
117+
);

src/components/CvTag/CvTag.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<template>
22
<div v-if="skeleton" :class="tagClasses"></div>
33
<div v-else :class="tagClasses" role="listitem" :title="title">
4+
<cv-svg
5+
v-if="!skeleton && renderIcon"
6+
:svg="renderIcon"
7+
:class="`${carbonPrefix}--tag__custom-icon`"
8+
/>
49
<span :class="`${carbonPrefix}--tag__label`">
510
{{ label }}
611
</span>
@@ -21,23 +26,19 @@ import { computed } from 'vue';
2126
import { carbonPrefix } from '../../global/settings';
2227
import { tagKinds } from './consts';
2328
import Close16 from '@carbon/icons-vue/es/close/16';
29+
import CvSvg from '../CvSvg/_CvSvg.vue';
2430
2531
export default {
2632
name: 'CvTag',
27-
components: { Close16 },
33+
components: { CvSvg, Close16 },
2834
props: {
35+
/** aria label to use for the x icon for the filter tag */
2936
clearAriaLabel: { type: String, default: 'Clear filter' },
30-
/**
31-
* disabled by property or if skeleton
32-
*/
37+
/** disabled by property or if skeleton */
3338
disabled: Boolean,
34-
/**
35-
* label to be used in the CvTag component
36-
*/
39+
/** label to be used in the CvTag component */
3740
label: { type: String, required: true },
38-
/**
39-
* kind of the CvTag
40-
*/
41+
/** kind of the CvTag */
4142
kind: {
4243
type: String,
4344
default: undefined,
@@ -46,20 +47,22 @@ export default {
4647
},
4748
},
4849
/**
49-
* If filter is true, the CvTag will include a remove button on the right side, which on a click, will emit the 'remove' event.
50+
* If filter is true, the CvTag will include a remove button on the right side, which on a click, will emit the
51+
* 'remove' event.
5052
*/
5153
filter: {
5254
type: Boolean,
5355
default: false,
5456
},
55-
/**
56-
* skeleton used when loading
57-
*/
57+
/** skeleton used when loading */
5858
skeleton: Boolean,
59-
/**
60-
* tag size small
61-
*/
59+
/** tag size small */
6260
small: Boolean,
61+
/** Optional prop to render a custom icon. \@carbon/icons-vue icon, href, svg or symbol */
62+
renderIcon: {
63+
type: [String, Object],
64+
default: undefined,
65+
},
6366
},
6467
emits: [
6568
/**

0 commit comments

Comments
 (0)