Skip to content

Commit 6368119

Browse files
feat(Tag): implement short tag size (#7619)
* feat(Tag): support short tag * docs(Tag): add size knob * feat(Tag): add short tag skeleton * chore: update snapshots * fix(tag): restore line-height * refactor(tag): remove unused styles * refactor(Tag): rename small size * chore: update snapshots Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent c83fccf commit 6368119

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

packages/components/src/components/tag/_tag.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
min-width: rem(32px);
3434
// restricts size of contained elements
3535
max-width: 100%;
36-
min-height: 1.5rem;
36+
min-height: rem(24px);
3737
margin: $carbon--spacing-02;
3838
padding: $carbon--spacing-02 $carbon--spacing-03;
3939
word-break: break-word;
@@ -218,6 +218,16 @@
218218
fill: $disabled-02;
219219
}
220220

221+
// small tags
222+
.#{$prefix}--tag--sm {
223+
min-height: rem(18px);
224+
padding: 0 $carbon--spacing-03;
225+
}
226+
227+
.#{$prefix}--tag--sm.#{$prefix}--tag--filter {
228+
padding-right: rem(2px);
229+
}
230+
221231
// Skeleton state
222232
.#{$prefix}--tag.#{$prefix}--skeleton {
223233
@include skeleton;

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5181,6 +5181,14 @@ Map {
51815181
],
51825182
"type": "oneOfType",
51835183
},
5184+
"size": Object {
5185+
"args": Array [
5186+
Array [
5187+
"sm",
5188+
],
5189+
],
5190+
"type": "oneOf",
5191+
},
51845192
"title": Object {
51855193
"type": "string",
51865194
},
@@ -6587,6 +6595,14 @@ Map {
65876595
"className": Object {
65886596
"type": "string",
65896597
},
6598+
"size": Object {
6599+
"args": Array [
6600+
Array [
6601+
"sm",
6602+
],
6603+
],
6604+
"type": "oneOf",
6605+
},
65906606
},
65916607
},
65926608
"TextAreaSkeleton" => Object {

packages/react/src/components/Tag/Tag-story.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const iconMap = {
2525
Tag16,
2626
};
2727

28+
const sizes = {
29+
'Default size': undefined,
30+
'Small size (sm)': 'sm',
31+
};
32+
2833
const props = {
2934
regular: () => ({
3035
type: select(
@@ -40,6 +45,7 @@ const props = {
4045
)
4146
),
4247
disabled: boolean('Disabled (disabled)', false),
48+
size: select('Field size (size)', sizes, undefined) || undefined,
4349
title: text('Title (title)', 'Clear Filter'),
4450
}),
4551
filter() {
@@ -123,6 +129,7 @@ CustomIcon.parameters = {
123129
export const Skeleton = () => (
124130
<div>
125131
<TagSkeleton />
132+
<TagSkeleton size="sm" />
126133
</div>
127134
);
128135

packages/react/src/components/Tag/Tag.Skeleton.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { settings } from 'carbon-components';
1212

1313
const { prefix } = settings;
1414

15-
function TagSkeleton({ className, ...rest }) {
15+
function TagSkeleton({ className, size, ...rest }) {
1616
return (
1717
<span
18-
className={cx(`${prefix}--tag`, `${prefix}--skeleton`, className)}
18+
className={cx(`${prefix}--tag`, `${prefix}--skeleton`, className, {
19+
[`${prefix}--tag--${size}`]: size,
20+
})}
1921
{...rest}
2022
/>
2123
);
@@ -26,6 +28,12 @@ TagSkeleton.propTypes = {
2628
* Specify an optional className to add.
2729
*/
2830
className: PropTypes.string,
31+
32+
/**
33+
* Specify the size of the Tag. Currently supports either `sm` or
34+
* default sizes.
35+
*/
36+
size: PropTypes.oneOf(['sm']),
2937
};
3038

3139
export default TagSkeleton;

packages/react/src/components/Tag/Tag.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ const Tag = ({
3838
title,
3939
disabled,
4040
onClose,
41+
size,
4142
...other
4243
}) => {
4344
const tagId = id || `tag-${getInstanceId()}`;
4445
const tagClasses = classNames(`${prefix}--tag`, className, {
4546
[`${prefix}--tag--disabled`]: disabled,
4647
[`${prefix}--tag--filter`]: filter,
48+
[`${prefix}--tag--${size}`]: size,
4749
[`${prefix}--tag--${type}`]: type,
4850
});
4951
const handleClose = (event) => {
@@ -131,6 +133,12 @@ Tag.propTypes = {
131133
*/
132134
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
133135

136+
/**
137+
* Specify the size of the Tag. Currently supports either `sm` or
138+
* default sizes.
139+
*/
140+
size: PropTypes.oneOf(['sm']),
141+
134142
/**
135143
* Text to show on clear filters
136144
*/

0 commit comments

Comments
 (0)