diff --git a/src/components/Tag/Tag.scss b/src/components/Tag/Tag.scss index c322cd592..7bc1082f0 100644 --- a/src/components/Tag/Tag.scss +++ b/src/components/Tag/Tag.scss @@ -1,38 +1,70 @@ .Tag { - display: flex; + display: inline-flex; align-items: center; - padding: var(--space-50) var(--space-75); - border-radius: var(--border-radius); + padding: var(--space-25) var(--space-50); + gap: var(--space-50); + border-radius: var(--space-50); + border: 1px solid var(--color-border-subtle); + cursor: default; + background-color: var(--bg-color, white); // Fallback to --color-background if bgColor isn't provided + + &[disabled] { + color: var(--color-text-disabled); + } &--isSelected { - box-shadow: 0 0 0 2px var(--color-brand-50); + box-shadow: 0 0 0 var(--space-25) var(--color-brand-50); } - &--clickable { + &--clickable:not([disabled]) { cursor: pointer; + + &:hover:not([disabled]){ + background-color: var(--color-background-neutral-subtlest-hover); + } + + &:focus:not([disabled]) { + outline: none; + box-shadow: 0 0 0 var(--space-25) var(--color-info-20); + } } &__text{ + composes: OneUI-label-text from global; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + &[disabled] { + color: var(--color-text-disabled); + } } &__deleteButton { display: flex; + justify-content: center; align-items: center; - min-width: 15px; - min-height: 15px; + min-width: var(--space-200); + height: var(--space-200); - border: 0; + border: none; + border-radius: var(--space-25); cursor: pointer; background-color: var(--transparent); padding: 0; - margin-left: var(--space-50); + + &:focus:not([disabled]) { + outline: none; + box-shadow: 0 0 0 var(--space-25) var(--color-info-20); + } + &[disabled] { + fill: var(--color-text-disabled); + cursor: default; + } + } } diff --git a/src/components/Tag/Tag.tsx b/src/components/Tag/Tag.tsx index 015f02329..b499dc9f9 100644 --- a/src/components/Tag/Tag.tsx +++ b/src/components/Tag/Tag.tsx @@ -1,8 +1,7 @@ import * as React from 'react'; -import { MdClose } from 'react-icons/md'; +import Close from '@material-design-icons/svg/round/close.svg'; import { bem } from '../../utils'; -import { Text } from '../Text'; -import { ENTER_KEY, Size } from '../../constants'; +import { ENTER_KEY } from '../../constants'; import styles from './Tag.scss'; export interface Props extends React.HTMLAttributes { @@ -12,8 +11,6 @@ export interface Props extends React.HTMLAttributes { bgColor?: string; /** Max-width of a component */ maxWidth?: string; - /** Size of the text */ - size?: Size; /** Callback, that is fired when a user clicks on a delete icon */ onDelete?: (e: React.KeyboardEvent | React.MouseEvent) => void; /** Callback, that is fired when a user clicks on an element */ @@ -24,6 +21,8 @@ export interface Props extends React.HTMLAttributes { contentStyle?: React.CSSProperties; /** Close label name for ARIA labelling, it is used when needs to clear data from component */ closeLabel?: string; + /** Should tag be disabled or not */ + disabled?: boolean; } const { block, elem } = bem('Tag', styles); @@ -32,15 +31,15 @@ export const Tag = React.forwardRef( ( { children, - bgColor = 'var(--color-background)', - maxWidth = 'fit-content', - size = 'large', + bgColor, + maxWidth = '224px', onDelete = undefined, onClick = undefined, isSelected = false, contentClassName, contentStyle, closeLabel, + disabled, ...rest }, ref @@ -65,15 +64,15 @@ export const Tag = React.forwardRef( const handleDeleteButtonKeyPress = (e: React.KeyboardEvent) => { e.stopPropagation(); - e.preventDefault(); if (e.key === ENTER_KEY) { + e.preventDefault(); onDelete?.(e); } }; return ( -
( onKeyPress: handleTagKeyPress, })} style={{ - backgroundColor: bgColor, + '--bg-color': bgColor, maxWidth, }} + disabled={disabled} > - {children} - + {onDelete && ( )} -
+ ); } ); diff --git a/src/components/Tag/__tests__/Tag.spec.tsx b/src/components/Tag/__tests__/Tag.spec.tsx index 05d40118f..76bce2322 100644 --- a/src/components/Tag/__tests__/Tag.spec.tsx +++ b/src/components/Tag/__tests__/Tag.spec.tsx @@ -13,7 +13,6 @@ describe(' component', () => { const text = 'Tag text'; const bgColor = '#ccc'; const maxWidth = '30px'; - const textSize = 'large'; const closeLabel = 'close label'; it('should render correctly with minimum amount of props', () => { @@ -29,7 +28,6 @@ describe(' component', () => { isSelected bgColor={bgColor} maxWidth={maxWidth} - size={textSize} onClick={onTagClick} onDelete={onDeleteClick} contentClassName="my-class" @@ -43,10 +41,7 @@ describe(' component', () => { expect(view.container).toMatchSnapshot(); expect(button).toBeInTheDocument(); - expect(button).toHaveAttribute( - 'style', - 'background-color: rgb(204, 204, 204); max-width: 30px;' - ); + expect(button).toHaveAttribute('style', '--bg-color: #ccc; max-width: 30px;'); }); it('should invoke callback when onClick event is called', async () => { diff --git a/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap b/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap index 6e325a9fa..4eb5f2eae 100644 --- a/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +++ b/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap @@ -2,57 +2,45 @@ exports[` component should render correctly with full list of props 1`] = `
-
-

Tag text -

+ -
+
`; exports[` component should render correctly with minimum amount of props 1`] = `
-
-

Tag text -

-
+ +
`; diff --git a/src/components/Teaser/__tests__/__snapshots__/Teaser.spec.tsx.snap b/src/components/Teaser/__tests__/__snapshots__/Teaser.spec.tsx.snap index fade2a4a5..a79a2097e 100644 --- a/src/components/Teaser/__tests__/__snapshots__/Teaser.spec.tsx.snap +++ b/src/components/Teaser/__tests__/__snapshots__/Teaser.spec.tsx.snap @@ -325,28 +325,28 @@ exports[`Teaser should render with all props defined 1`] = `
-
-

First Tag -

-
-
+ + -

Second Tag -

-
+ +
diff --git a/stories/atoms/Tag.stories.tsx b/stories/atoms/Tag.stories.tsx index fda764736..2ca08053b 100644 --- a/stories/atoms/Tag.stories.tsx +++ b/stories/atoms/Tag.stories.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import type { Meta, StoryObj } from '@storybook/react'; -import { FiCheck } from 'react-icons/fi'; import { Tag } from '@textkernel/oneui'; const meta: Meta = { @@ -10,9 +9,6 @@ const meta: Meta = { bgColor: { options: ['#3eff2b', '#ffa139', 'var(--color-background)'], }, - size: { - options: ['small', 'medium', 'large'], - }, }, }; @@ -23,10 +19,14 @@ type Story = StoryObj; export const _Tag: Story = { name: 'Tag', args: { - bgColor: '#3eff2b', isSelected: false, - maxWidth: 'fit-content', children: 'This is an extremely long long text!', + onClick: () => { + console.log('onClick: The tag has been clicked'); + }, + onDelete: () => { + console.log('onDelete: The delete button has been clicked'); + }, }, render: (args) => (
- - Some text - - ), + children: <>Read Only, + contentClassName: 'test-class', + contentStyle: { + display: 'flex', + alignItems: 'center', + gap: 'var(--space-75)', + }, + onDelete: undefined, + onClick: undefined, + }, + render: (args) => ( +
+ +
+ ), +}; + +export const ColoredTag: Story = { + name: 'Colored Tag', + args: { + bgColor: '#0097D1', + children: <>Colored Tag, contentClassName: 'test-class', contentStyle: { display: 'flex', diff --git a/stories/molecules/Teaser.stories.tsx b/stories/molecules/Teaser.stories.tsx index 240b1e2dc..e479cff23 100644 --- a/stories/molecules/Teaser.stories.tsx +++ b/stories/molecules/Teaser.stories.tsx @@ -34,12 +34,8 @@ export const WithAllFields: Story = { matchingIndicatorPercentage: 50, bottom: (
- - First - - - Second - + First + Second
), disabled: true, @@ -73,12 +69,10 @@ export const WithoutCheckbox: Story = { date: 'about 1 month ago', bottom: (
- console.log('Deleted')}> + console.log('Deleted')}> First - - Second - + Second
), }, @@ -149,12 +143,10 @@ export const VariantThree: Story = { date: 'Today', bottom: (
- console.log('Deleted')}> + console.log('Deleted')}> First - - Second - + Second
), },