From 80cc867647817954615ee2f5813d9d02eae2ee81 Mon Sep 17 00:00:00 2001 From: guidari Date: Fri, 8 Mar 2024 15:31:03 -0300 Subject: [PATCH 01/14] feat: added ellipses to tag --- .../react/src/components/Tag/Tag.stories.js | 4 +- packages/react/src/components/Tag/Tag.tsx | 61 ++++++++++++++++--- packages/styles/scss/components/tag/_tag.scss | 18 +++++- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/packages/react/src/components/Tag/Tag.stories.js b/packages/react/src/components/Tag/Tag.stories.js index b162934e0dd2..9356c5f5472c 100644 --- a/packages/react/src/components/Tag/Tag.stories.js +++ b/packages/react/src/components/Tag/Tag.stories.js @@ -19,7 +19,7 @@ export const ReadOnly = () => { return ( <> - {'Tag content'} + {'Tag content big Tag content big Tag content big '} {'Tag content'} @@ -61,7 +61,7 @@ export const ReadOnly = () => { export const Playground = (args) => { return ( - {'Tag content'} + {'Tag contentcontent content content content'} ); }; diff --git a/packages/react/src/components/Tag/Tag.tsx b/packages/react/src/components/Tag/Tag.tsx index 959c67210077..775f9efb0a07 100644 --- a/packages/react/src/components/Tag/Tag.tsx +++ b/packages/react/src/components/Tag/Tag.tsx @@ -6,7 +6,7 @@ */ import PropTypes, { ReactNodeLike } from 'prop-types'; -import React from 'react'; +import React, { useLayoutEffect, useState } from 'react'; import classNames from 'classnames'; import { Close } from '@carbon/icons-react'; import setupGetInstanceId from '../../tools/setupGetInstanceId'; @@ -14,6 +14,7 @@ import { usePrefix } from '../../internal/usePrefix'; import { PolymorphicProps } from '../../types/common'; import { Text } from '../Text'; import deprecate from '../../prop-types/deprecate'; +import { Tooltip } from '../Tooltip'; const getInstanceId = setupGetInstanceId(); export const TYPES = { @@ -118,6 +119,17 @@ const Tag = ({ }: TagProps) => { const prefix = usePrefix(); const tagId = id || `tag-${getInstanceId()}`; + const [isEllipsisApplied, setIsEllipsisApplied] = useState(false); + + const isEllipsisActive = (element: any) => { + setIsEllipsisApplied(element.offsetWidth < element.scrollWidth); + return element.offsetWidth < element.scrollWidth; + }; + + useLayoutEffect(() => { + const element = document.querySelector(`[title="${children}"]`); + isEllipsisActive(element); + }, [prefix, children]); const conditions = [ `${prefix}--tag--selectable`, @@ -166,11 +178,26 @@ const Tag = ({ ) : ( '' )} - - {children !== null && children !== undefined ? children : typeText} - + {isEllipsisApplied ? ( + + + {children !== null && children !== undefined + ? children + : typeText} + + + ) : ( + + {children !== null && children !== undefined ? children : typeText} + + )} {normalizedSlug} + + ); + } + return ( ({ ) : ( '' )} - - {isEllipsisApplied ? ( - - - {children !== null && children !== undefined ? children : typeText} - - - ) : ( - - {children !== null && children !== undefined ? children : typeText} + + {tagText ? tagText : typeText} + + {text !== undefined ? ( + + {children} - )} + ) : null} {normalizedSlug} ); @@ -315,6 +346,11 @@ Tag.propTypes = { */ slug: PropTypes.node, + /** + * Provide text to be rendered inside of a the tag. + */ + text: PropTypes.string, + /** * Text to show on clear filters */ diff --git a/packages/styles/scss/components/tag/_tag.scss b/packages/styles/scss/components/tag/_tag.scss index 9381a0459a44..ad9e1f4aa97f 100644 --- a/packages/styles/scss/components/tag/_tag.scss +++ b/packages/styles/scss/components/tag/_tag.scss @@ -72,6 +72,10 @@ padding-inline-start: $spacing-03; } + &:not(.#{$prefix}--tag--selectable) { + border: 0; + } + &:not(:first-child) { margin-inline-start: 0; } @@ -85,8 +89,10 @@ } .#{$prefix}--tag--interactive:focus { - box-shadow: inset 0 0 0 1px $focus; - outline: none; + // box-shadow: inset 0 0 0 1px $focus; + // outline: none; + outline: 2px solid $focus; + outline-offset: 1px; } .#{$prefix}--tag--interactive:hover { From cc5ce74fec35b9a2c7a94aaecd03c9eb1a379c9b Mon Sep 17 00:00:00 2001 From: guidari Date: Thu, 14 Mar 2024 13:30:40 -0300 Subject: [PATCH 03/14] feat: added text prop to intereactive tags storybook --- .../components/Tag/InteractiveTag.stories.js | 135 +++++++++--------- packages/react/src/components/Tag/Tag.tsx | 25 ++-- 2 files changed, 77 insertions(+), 83 deletions(-) diff --git a/packages/react/src/components/Tag/InteractiveTag.stories.js b/packages/react/src/components/Tag/InteractiveTag.stories.js index 35e7e6e75b15..83621864df6d 100644 --- a/packages/react/src/components/Tag/InteractiveTag.stories.js +++ b/packages/react/src/components/Tag/InteractiveTag.stories.js @@ -33,16 +33,16 @@ export const Selectable = (args) => { <> {' '} + /> ); }; @@ -100,7 +100,7 @@ export const Operational = (args) => { type="red" className="some-class" renderIcon={Asleep} - text="Tag content content content content" + text="Tag content with a long text description" {...args} /> { type="purple" className="some-class" renderIcon={Asleep} - {...args}> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + /> - {'Tag content'} - + text="Tag content" + {...args} + />

Interactive examples

@@ -180,19 +180,22 @@ export const Operational = (args) => { label="View more" align="bottom" className={`${prefix}--icon-tooltip`}> - - {'Tag content'} - + - {'Tag content'} - + {...args} + />
@@ -211,10 +214,10 @@ export const Operational = (args) => { setOpen(!open); }} renderIcon={Asleep} + text="Tag content" className="some-class" - {...args}> - {'Tag content'} - + {...args} + />
{ className="some-class" title="Clear Filter" renderIcon={Asleep} - text="Tag content content content content" + text="Tag content with a long text description" {...args} /> { className="some-class" title="Clear Filter" text="Tag content" - {...args} renderIcon={Asleep} + {...args} /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> - {'Tag content'} - + /> ); }; diff --git a/packages/react/src/components/Tag/Tag.tsx b/packages/react/src/components/Tag/Tag.tsx index e211fc75aa19..f000da1890d1 100644 --- a/packages/react/src/components/Tag/Tag.tsx +++ b/packages/react/src/components/Tag/Tag.tsx @@ -126,7 +126,6 @@ const Tag = ({ const prefix = usePrefix(); const tagId = id || `tag-${getInstanceId()}`; const [isEllipsisApplied, setIsEllipsisApplied] = useState(false); - const [toggleTooltip, setToggleTooltip] = useState(true); const isEllipsisActive = (element: any) => { setIsEllipsisApplied(element.offsetWidth < element.scrollWidth); @@ -226,7 +225,10 @@ const Tag = ({ if (isEllipsisApplied) { return ( - <> + ({ ) : ( '' )} - - - {tagText ? tagText : typeText} - - - + + {tagText ? tagText : typeText} + {text !== undefined ? children : null} {normalizedSlug} - - - + ); } From ea500670acfec2dfe28c83251947927ec46c56c6 Mon Sep 17 00:00:00 2001 From: guidari Date: Thu, 14 Mar 2024 13:48:58 -0300 Subject: [PATCH 04/14] fix: removed children prop from interactive tags --- .../src/components/Tag/OperationalTag.tsx | 24 +++++++++---------- .../src/components/Tag/SelectableTag.tsx | 5 ---- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/react/src/components/Tag/OperationalTag.tsx b/packages/react/src/components/Tag/OperationalTag.tsx index 7feb9189dc18..4fe10e11b054 100644 --- a/packages/react/src/components/Tag/OperationalTag.tsx +++ b/packages/react/src/components/Tag/OperationalTag.tsx @@ -29,11 +29,6 @@ const TYPES = { }; export interface OperationalTagBaseProps { - /** - * Provide content to be rendered inside of a `OperationalTag` - */ - children?: React.ReactNode; - /** * Provide a custom className that is applied to the containing */ @@ -67,6 +62,11 @@ export interface OperationalTagBaseProps { */ slug?: ReactNodeLike; + /** + * Provide text to be rendered inside of a the tag. + */ + text?: string; + /** * Specify the type of the `Tag` */ @@ -79,13 +79,13 @@ export type OperationalTagProps = PolymorphicProps< >; const OperationalTag = ({ - children, className, disabled, id, renderIcon, slug, size, + text, type = 'gray', ...other }: OperationalTagProps) => { @@ -109,9 +109,9 @@ const OperationalTag = ({ disabled={disabled} className={tagClasses} id={tagId} + text={text} {...other}>
- {children} {normalizedSlug}
@@ -119,11 +119,6 @@ const OperationalTag = ({ }; OperationalTag.propTypes = { - /** - * Provide content to be rendered inside of a `OperationalTag` - */ - children: PropTypes.node, - /** * Provide a custom className that is applied to the containing */ @@ -156,6 +151,11 @@ OperationalTag.propTypes = { */ slug: PropTypes.node, + /** + * Provide text to be rendered inside of a the tag. + */ + text: PropTypes.string, + /** * Specify the type of the `Tag` */ diff --git a/packages/react/src/components/Tag/SelectableTag.tsx b/packages/react/src/components/Tag/SelectableTag.tsx index e813ff16ddb8..b466b50ef72d 100644 --- a/packages/react/src/components/Tag/SelectableTag.tsx +++ b/packages/react/src/components/Tag/SelectableTag.tsx @@ -16,11 +16,6 @@ import Tag, { SIZES } from './Tag'; const getInstanceId = setupGetInstanceId(); export interface SelectableTagBaseProps { - /** - * Provide content to be rendered inside of a `SelectableTag` - */ - children?: React.ReactNode; - /** * Provide a custom className that is applied to the containing */ From 3dfb0685cc9cb593415fc2a4a908a8de085910d2 Mon Sep 17 00:00:00 2001 From: guidari Date: Thu, 14 Mar 2024 13:56:48 -0300 Subject: [PATCH 05/14] test: snapshots updated --- .../src/__tests__/__snapshots__/PublicAPI-test.js.snap | 6 ++++++ .../react/__tests__/__snapshots__/PublicAPI-test.js.snap | 3 +++ packages/styles/scss/__tests__/theme-test.js | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap index f56fe39aeca3..be0e3c8e2f87 100644 --- a/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/elements/src/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -77,6 +77,12 @@ Array [ "chatBubbleAgent", "chatBubbleAgentBorder", "chatBubbleUser", + "chatButton", + "chatButtonActive", + "chatButtonHover", + "chatButtonSelected", + "chatButtonTextHover", + "chatButtonTextSelected", "chatHeaderBackground", "chatPromptBackground", "chatPromptBorderEnd", diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index f8fa1425bc58..0073245a2fbe 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -8210,6 +8210,9 @@ Map { "slug": Object { "type": "node", }, + "text": Object { + "type": "string", + }, "title": [Function], "type": Object { "args": Array [ diff --git a/packages/styles/scss/__tests__/theme-test.js b/packages/styles/scss/__tests__/theme-test.js index fc41dece5e1b..62c0d848f8d3 100644 --- a/packages/styles/scss/__tests__/theme-test.js +++ b/packages/styles/scss/__tests__/theme-test.js @@ -163,6 +163,12 @@ describe('@carbon/styles/scss/theme', () => { "chat-avatar-user", "chat-shell-background", "chat-header-background", + "chat-button", + "chat-button-hover", + "chat-button-text-hover", + "chat-button-active", + "chat-button-selected", + "chat-button-text-selected", "highlight", "overlay", "toggle-off", From eff52edadf0da5e7123e25e9c7b55631a4ab7bf3 Mon Sep 17 00:00:00 2001 From: guidari Date: Fri, 15 Mar 2024 12:40:19 -0300 Subject: [PATCH 06/14] fix: fixed button propagation --- packages/react/src/components/Tag/DismissibleTag.tsx | 3 +++ packages/react/src/components/Tag/Tag.tsx | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react/src/components/Tag/DismissibleTag.tsx b/packages/react/src/components/Tag/DismissibleTag.tsx index d6abd0c5f0fb..6a1fbb054308 100644 --- a/packages/react/src/components/Tag/DismissibleTag.tsx +++ b/packages/react/src/components/Tag/DismissibleTag.tsx @@ -124,6 +124,9 @@ const DismissibleTag = ({
{normalizedSlug} -
+ {normalizedSlug} + ); }; diff --git a/packages/react/src/components/Tag/OperationalTag.tsx b/packages/react/src/components/Tag/OperationalTag.tsx index 4fe10e11b054..ec5f99a9e0b5 100644 --- a/packages/react/src/components/Tag/OperationalTag.tsx +++ b/packages/react/src/components/Tag/OperationalTag.tsx @@ -111,9 +111,7 @@ const OperationalTag = ({ id={tagId} text={text} {...other}> -
- {normalizedSlug} -
+ {normalizedSlug} ); }; diff --git a/packages/react/src/components/Tag/SelectableTag.tsx b/packages/react/src/components/Tag/SelectableTag.tsx index b466b50ef72d..55a80d24979b 100644 --- a/packages/react/src/components/Tag/SelectableTag.tsx +++ b/packages/react/src/components/Tag/SelectableTag.tsx @@ -105,9 +105,7 @@ const SelectableTag = ({ text={text} onClick={() => setSelectedTag(!selectedTag)} {...otherProps}> -
- {normalizedSlug} -
+ {normalizedSlug} ); }; diff --git a/packages/react/src/components/Tag/Tag.stories.js b/packages/react/src/components/Tag/Tag.stories.js index f3c26d34dc46..f8ad717f4aac 100644 --- a/packages/react/src/components/Tag/Tag.stories.js +++ b/packages/react/src/components/Tag/Tag.stories.js @@ -61,7 +61,7 @@ export const ReadOnly = () => { export const Playground = (args) => { return ( - {'Tag contentcontent content content content'} + {'Tag content'} ); }; diff --git a/packages/styles/scss/components/tag/_tag.scss b/packages/styles/scss/components/tag/_tag.scss index ad9e1f4aa97f..e6e88d77a01f 100644 --- a/packages/styles/scss/components/tag/_tag.scss +++ b/packages/styles/scss/components/tag/_tag.scss @@ -111,11 +111,6 @@ } } - .#{$prefix}--interactive--tag-children { - display: inline-flex; - place-items: center; - } - .#{$prefix}--tag--selectable { border: 1px solid $border-inverse; background-color: $layer;