From 636811900848b112ee7f6839fc122ab1e66a16e2 Mon Sep 17 00:00:00 2001 From: emyarod Date: Tue, 26 Jan 2021 14:11:53 -0800 Subject: [PATCH] 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> --- packages/components/src/components/tag/_tag.scss | 12 +++++++++++- .../__snapshots__/PublicAPI-test.js.snap | 16 ++++++++++++++++ packages/react/src/components/Tag/Tag-story.js | 7 +++++++ .../react/src/components/Tag/Tag.Skeleton.js | 12 ++++++++++-- packages/react/src/components/Tag/Tag.js | 8 ++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/packages/components/src/components/tag/_tag.scss b/packages/components/src/components/tag/_tag.scss index 08e2ceff7eef..7e5393b3893e 100644 --- a/packages/components/src/components/tag/_tag.scss +++ b/packages/components/src/components/tag/_tag.scss @@ -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; @@ -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; diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 872455c87fe6..18d12911597d 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -5181,6 +5181,14 @@ Map { ], "type": "oneOfType", }, + "size": Object { + "args": Array [ + Array [ + "sm", + ], + ], + "type": "oneOf", + }, "title": Object { "type": "string", }, @@ -6587,6 +6595,14 @@ Map { "className": Object { "type": "string", }, + "size": Object { + "args": Array [ + Array [ + "sm", + ], + ], + "type": "oneOf", + }, }, }, "TextAreaSkeleton" => Object { diff --git a/packages/react/src/components/Tag/Tag-story.js b/packages/react/src/components/Tag/Tag-story.js index 3bcbbb7e15e8..5c405db816b2 100644 --- a/packages/react/src/components/Tag/Tag-story.js +++ b/packages/react/src/components/Tag/Tag-story.js @@ -25,6 +25,11 @@ const iconMap = { Tag16, }; +const sizes = { + 'Default size': undefined, + 'Small size (sm)': 'sm', +}; + const props = { regular: () => ({ type: select( @@ -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() { @@ -123,6 +129,7 @@ CustomIcon.parameters = { export const Skeleton = () => (
+
); diff --git a/packages/react/src/components/Tag/Tag.Skeleton.js b/packages/react/src/components/Tag/Tag.Skeleton.js index aca9b8fed401..f1fed69d89dd 100644 --- a/packages/react/src/components/Tag/Tag.Skeleton.js +++ b/packages/react/src/components/Tag/Tag.Skeleton.js @@ -12,10 +12,12 @@ import { settings } from 'carbon-components'; const { prefix } = settings; -function TagSkeleton({ className, ...rest }) { +function TagSkeleton({ className, size, ...rest }) { return ( ); @@ -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; diff --git a/packages/react/src/components/Tag/Tag.js b/packages/react/src/components/Tag/Tag.js index 8f6c6af069d7..979ca30ea550 100644 --- a/packages/react/src/components/Tag/Tag.js +++ b/packages/react/src/components/Tag/Tag.js @@ -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) => { @@ -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 */