Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Tag): implement short tag size #7619

Merged
merged 10 commits into from
Jan 26, 2021
Merged
12 changes: 11 additions & 1 deletion packages/components/src/components/tag/_tag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
min-width: rem(32px);
// restricts size of contained elements
max-width: 100%;
min-height: 1.5rem;
min-height: rem(24px);
margin: $carbon--spacing-02;
padding: $carbon--spacing-02 $carbon--spacing-03;
word-break: break-word;
Expand Down Expand Up @@ -218,6 +218,16 @@
fill: $disabled-02;
}

// small tags
.#{$prefix}--tag--sm {
min-height: rem(18px);
padding: 0 $carbon--spacing-03;
}

.#{$prefix}--tag--sm.#{$prefix}--tag--filter {
padding-right: rem(2px);
}

// Skeleton state
.#{$prefix}--tag.#{$prefix}--skeleton {
@include skeleton;
Expand Down
16 changes: 16 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5181,6 +5181,14 @@ Map {
],
"type": "oneOfType",
},
"size": Object {
"args": Array [
Array [
"sm",
],
],
"type": "oneOf",
},
"title": Object {
"type": "string",
},
Expand Down Expand Up @@ -6587,6 +6595,14 @@ Map {
"className": Object {
"type": "string",
},
"size": Object {
"args": Array [
Array [
"sm",
],
],
"type": "oneOf",
},
},
},
"TextAreaSkeleton" => Object {
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/Tag/Tag-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const iconMap = {
Tag16,
};

const sizes = {
'Default size': undefined,
'Small size (sm)': 'sm',
};

const props = {
regular: () => ({
type: select(
Expand All @@ -40,6 +45,7 @@ const props = {
)
),
disabled: boolean('Disabled (disabled)', false),
size: select('Field size (size)', sizes, undefined) || undefined,
title: text('Title (title)', 'Clear Filter'),
}),
filter() {
Expand Down Expand Up @@ -123,6 +129,7 @@ CustomIcon.parameters = {
export const Skeleton = () => (
<div>
<TagSkeleton />
<TagSkeleton size="sm" />
</div>
);

Expand Down
12 changes: 10 additions & 2 deletions packages/react/src/components/Tag/Tag.Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { settings } from 'carbon-components';

const { prefix } = settings;

function TagSkeleton({ className, ...rest }) {
function TagSkeleton({ className, size, ...rest }) {
return (
<span
className={cx(`${prefix}--tag`, `${prefix}--skeleton`, className)}
className={cx(`${prefix}--tag`, `${prefix}--skeleton`, className, {
[`${prefix}--tag--${size}`]: size,
})}
{...rest}
/>
);
Expand All @@ -26,6 +28,12 @@ TagSkeleton.propTypes = {
* Specify an optional className to add.
*/
className: PropTypes.string,

/**
* Specify the size of the Tag. Currently supports either `sm` or
* default sizes.
*/
size: PropTypes.oneOf(['sm']),
};

export default TagSkeleton;
8 changes: 8 additions & 0 deletions packages/react/src/components/Tag/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ const Tag = ({
title,
disabled,
onClose,
size,
...other
}) => {
const tagId = id || `tag-${getInstanceId()}`;
const tagClasses = classNames(`${prefix}--tag`, className, {
[`${prefix}--tag--disabled`]: disabled,
[`${prefix}--tag--filter`]: filter,
[`${prefix}--tag--${size}`]: size,
[`${prefix}--tag--${type}`]: type,
});
const handleClose = (event) => {
Expand Down Expand Up @@ -131,6 +133,12 @@ Tag.propTypes = {
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

/**
* Specify the size of the Tag. Currently supports either `sm` or
* default sizes.
*/
size: PropTypes.oneOf(['sm']),

/**
* Text to show on clear filters
*/
Expand Down