diff --git a/CHANGELOG.md b/CHANGELOG.md index 0088147f0..13c443bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Implement `Tag` component + ## [1.0.5] - 2023-11-20 ### Changed diff --git a/src/components/avatars/avatarIcon/avatarIcon.stories.ts b/src/components/avatars/avatarIcon/avatarIcon.stories.tsx similarity index 100% rename from src/components/avatars/avatarIcon/avatarIcon.stories.ts rename to src/components/avatars/avatarIcon/avatarIcon.stories.tsx diff --git a/src/components/index.ts b/src/components/index.ts index 488c2d15c..293059744 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -6,3 +6,4 @@ export * from './icon'; export * from './illustrations'; export * from './progress'; export * from './spinner'; +export * from './tag'; diff --git a/src/components/tag/index.ts b/src/components/tag/index.ts new file mode 100644 index 000000000..87d2dfdd1 --- /dev/null +++ b/src/components/tag/index.ts @@ -0,0 +1 @@ +export { Tag, type ITagProps } from './tag'; diff --git a/src/components/tag/tag.stories.tsx b/src/components/tag/tag.stories.tsx new file mode 100644 index 000000000..a749a1e9d --- /dev/null +++ b/src/components/tag/tag.stories.tsx @@ -0,0 +1,27 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import { Tag } from './tag'; + +const meta: Meta = { + title: 'components/Tag', + component: Tag, + tags: ['autodocs'], + parameters: { + design: { + type: 'figma', + url: 'https://www.figma.com/file/jfKRr1V9evJUp1uBeyP3Zz/v1.0.0?type=design&node-id=21-200&mode=design&t=9F9GGTyrap4TVsvP-4', + }, + }, +}; + +type Story = StoryObj; + +/** + * Default usage example of the Tag component. + */ +export const Default: Story = { + args: { + label: 'Label', + }, +}; + +export default meta; diff --git a/src/components/tag/tag.test.tsx b/src/components/tag/tag.test.tsx new file mode 100644 index 000000000..614a266a1 --- /dev/null +++ b/src/components/tag/tag.test.tsx @@ -0,0 +1,19 @@ +import { render, screen } from '@testing-library/react'; +import { Tag, type ITagProps } from './tag'; + +describe(' component', () => { + const createTestComponent = (props?: Partial) => { + const completeProps = { + label: 'my-label', + ...props, + }; + + return ; + }; + + it('renders the specified label', () => { + const label = 'label-test'; + render(createTestComponent({ label })); + expect(screen.getByText(label)).toBeInTheDocument(); + }); +}); diff --git a/src/components/tag/tag.tsx b/src/components/tag/tag.tsx new file mode 100644 index 000000000..f9ed08d43 --- /dev/null +++ b/src/components/tag/tag.tsx @@ -0,0 +1,38 @@ +import classNames from 'classnames'; + +export type TagVariant = 'neutral' | 'info' | 'warning' | 'critical' | 'success' | 'primary'; + +export interface ITagProps { + /** + * Defines the variant of the tag. + * @default neutral + */ + variant?: TagVariant; + /** + * Label of the tag. + */ + label: string; + /** + * Classes for the component. + */ + className?: string; +} + +const variantToClassName: Record = { + neutral: 'bg-neutral-100 text-neutral-600', + info: 'bg-info-200 text-info-800', + warning: 'bg-warning-200 text-warning-800', + critical: 'bg-critical-200 text-critical-800', + success: 'bg-success-200 text-success-800', + primary: 'bg-primary-100 text-primary-800', +}; + +export const Tag: React.FC = (props) => { + const { label, variant = 'neutral', className } = props; + + return ( +
+

{label}

+
+ ); +};