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)!: remove deprecated props and update API #1862

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/components/Tag/Tag.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

font: var(--eds-theme-typography-tag);
}

/**
Expand Down Expand Up @@ -72,12 +70,6 @@
--tag-outline-color: var(--eds-theme-color-border-utility-warning-default);
}

:where(.tag--yield) {
--tag-primary-color: var(--eds-theme-color-text-grade-revise);
--tag-secondary-color: var(--eds-theme-color-background-grade-revise-subtle);
--tag-outline-color: var(--eds-theme-color-border-grade-revise-default);
}

:where(.tag--brand) {
--tag-primary-color: var(--eds-theme-color-text-brand-default);
--tag-secondary-color: var(--eds-theme-color-background-brand-primary-default);
Expand Down
15 changes: 6 additions & 9 deletions src/components/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { StoryObj, Meta } from '@storybook/react';
import React from 'react';
import { Tag, VARIANTS } from './Tag';
import Icon from '../Icon';
import styles from './Tag.stories.module.css';

const supportedVariants = VARIANTS.filter((variant) => variant !== 'yield');

export default {
title: 'Components/Tag',
component: Tag,
Expand Down Expand Up @@ -37,7 +34,7 @@ export const Default: Story = {};
export const Variants: Story = {
render: (args) => (
<div className={styles.tagList}>
{supportedVariants.map((variant) => {
{VARIANTS.map((variant) => {
return (
<Tag
data-testid="test"
Expand All @@ -58,7 +55,7 @@ export const Variants: Story = {
export const OutlineVariants: Story = {
render: (args) => (
<div className={styles.tagList}>
{supportedVariants.map((variant) => {
{VARIANTS.map((variant) => {
return (
<Tag
key={variant}
Expand All @@ -79,11 +76,11 @@ export const OutlineVariants: Story = {
export const WithIcon: Story = {
...Default,
args: {
icon: <Icon name="favorite" purpose="decorative" />,
icon: 'favorite',
},
render: (args) => (
<div className={styles.tagList}>
{supportedVariants.map((variant) => {
{VARIANTS.map((variant) => {
return (
<Tag
key={variant}
Expand All @@ -105,11 +102,11 @@ export const WithLongTextAndIcon: Story = {
...Default,
args: {
text: 'This tag has a really long text message',
icon: <Icon name="star" purpose="decorative" />,
icon: 'star',
},
render: (args) => (
<div className={styles.tagList}>
{supportedVariants.map((variant) => {
{VARIANTS.map((variant) => {
return <Tag key={variant} {...args} hasOutline variant={variant} />;
})}
</div>
Expand Down
24 changes: 7 additions & 17 deletions src/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import clsx from 'clsx';
import React from 'react';
import type { IconName } from '../Icon';
import Icon from '../Icon';
import Text from '../Text';

import styles from './Tag.module.css';

export const VARIANTS = [
'neutral',
'error',
'success',
'warning',
/** @deprecated */
'yield',
'brand',
] as const;

Expand All @@ -19,8 +20,6 @@ type Props = {
/**
* The color variant of the tag. It will update the content colors, background color, and border (when `hasOutline` is set to `true`).
*
* **NOTE**: `yield` variant is deprecated and will be removed in a future release.
*
* **Default is `"neutral"`**.
*/
variant?: Variant;
Expand All @@ -29,9 +28,9 @@ type Props = {
*/
className?: string;
/**
* The tag icon
* Icon name from the defined set of EDS icons
*/
icon?: React.ReactNode;
icon?: IconName;
/**
* The text contents of the tag, nested inside the component, in addition to the icon.
*/
Expand All @@ -55,7 +54,6 @@ export const Tag = ({
icon,
text,
hasOutline = false,
...other
}: Props) => {
const componentClassName = clsx(
styles['tag'],
Expand All @@ -64,17 +62,9 @@ export const Tag = ({
className,
);

// TODO: Text component is receiving the tag styles directly, instead of using a wrapper. De-couple
// and remove deprecated usages
return (
<Text
as="span"
className={componentClassName}
size="sm"
weight="bold"
{...other}
>
{icon}
<Text as="span" className={componentClassName} preset="tag">
{icon && <Icon name={icon} purpose="decorative" />}
{text && <span className={styles['tag__body']}>{text}</span>}
</Text>
);
Expand Down
47 changes: 21 additions & 26 deletions src/components/Tag/__snapshots__/Tag.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`<Tag /> Default story renders snapshot 1`] = `
<span
class="text text--sm text--bold-weight tag tag--neutral"
class="text text--tag tag tag--neutral"
>
<span
class="tag__body"
Expand All @@ -17,7 +17,7 @@ exports[`<Tag /> OutlineVariants story renders snapshot 1`] = `
class="tagList"
>
<span
class="text text--sm text--bold-weight tag tag--neutral tag--outline"
class="text text--tag tag tag--neutral tag--outline"
>
<span
class="tag__body"
Expand All @@ -26,7 +26,7 @@ exports[`<Tag /> OutlineVariants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--error tag--outline"
class="text text--tag tag tag--error tag--outline"
>
<span
class="tag__body"
Expand All @@ -35,7 +35,7 @@ exports[`<Tag /> OutlineVariants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--success tag--outline"
class="text text--tag tag tag--success tag--outline"
>
<span
class="tag__body"
Expand All @@ -44,7 +44,7 @@ exports[`<Tag /> OutlineVariants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--warning tag--outline"
class="text text--tag tag tag--warning tag--outline"
>
<span
class="tag__body"
Expand All @@ -53,7 +53,7 @@ exports[`<Tag /> OutlineVariants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--brand tag--outline"
class="text text--tag tag tag--brand tag--outline"
>
<span
class="tag__body"
Expand All @@ -69,8 +69,7 @@ exports[`<Tag /> Variants story renders snapshot 1`] = `
class="tagList"
>
<span
class="text text--sm text--bold-weight tag tag--neutral"
data-testid="test"
class="text text--tag tag tag--neutral"
>
<span
class="tag__body"
Expand All @@ -79,8 +78,7 @@ exports[`<Tag /> Variants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--error"
data-testid="test"
class="text text--tag tag tag--error"
>
<span
class="tag__body"
Expand All @@ -89,8 +87,7 @@ exports[`<Tag /> Variants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--success"
data-testid="test"
class="text text--tag tag tag--success"
>
<span
class="tag__body"
Expand All @@ -99,8 +96,7 @@ exports[`<Tag /> Variants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--warning"
data-testid="test"
class="text text--tag tag tag--warning"
>
<span
class="tag__body"
Expand All @@ -109,8 +105,7 @@ exports[`<Tag /> Variants story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--brand"
data-testid="test"
class="text text--tag tag tag--brand"
>
<span
class="tag__body"
Expand All @@ -126,7 +121,7 @@ exports[`<Tag /> WithIcon story renders snapshot 1`] = `
class="tagList"
>
<span
class="text text--sm text--bold-weight tag tag--neutral tag--outline"
class="text text--tag tag tag--neutral tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -146,7 +141,7 @@ exports[`<Tag /> WithIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--error tag--outline"
class="text text--tag tag tag--error tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -166,7 +161,7 @@ exports[`<Tag /> WithIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--success tag--outline"
class="text text--tag tag tag--success tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -186,7 +181,7 @@ exports[`<Tag /> WithIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--warning tag--outline"
class="text text--tag tag tag--warning tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -206,7 +201,7 @@ exports[`<Tag /> WithIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--brand tag--outline"
class="text text--tag tag tag--brand tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -233,7 +228,7 @@ exports[`<Tag /> WithLongTextAndIcon story renders snapshot 1`] = `
class="tagList"
>
<span
class="text text--sm text--bold-weight tag tag--neutral tag--outline"
class="text text--tag tag tag--neutral tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -253,7 +248,7 @@ exports[`<Tag /> WithLongTextAndIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--error tag--outline"
class="text text--tag tag tag--error tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -273,7 +268,7 @@ exports[`<Tag /> WithLongTextAndIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--success tag--outline"
class="text text--tag tag tag--success tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -293,7 +288,7 @@ exports[`<Tag /> WithLongTextAndIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--warning tag--outline"
class="text text--tag tag tag--warning tag--outline"
>
<svg
aria-hidden="true"
Expand All @@ -313,7 +308,7 @@ exports[`<Tag /> WithLongTextAndIcon story renders snapshot 1`] = `
</span>
</span>
<span
class="text text--sm text--bold-weight tag tag--brand tag--outline"
class="text text--tag tag tag--brand tag--outline"
>
<svg
aria-hidden="true"
Expand Down
Loading