-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: APP-2612 - Implement Tag component (#46)
- Loading branch information
Showing
7 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Tag, type ITagProps } from './tag'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { Tag } from './tag'; | ||
|
||
const meta: Meta<typeof Tag> = { | ||
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<typeof Tag>; | ||
|
||
/** | ||
* Default usage example of the Tag component. | ||
*/ | ||
export const Default: Story = { | ||
args: { | ||
label: 'Label', | ||
}, | ||
}; | ||
|
||
export default meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Tag, type ITagProps } from './tag'; | ||
|
||
describe('<Tag /> component', () => { | ||
const createTestComponent = (props?: Partial<ITagProps>) => { | ||
const completeProps = { | ||
label: 'my-label', | ||
...props, | ||
}; | ||
|
||
return <Tag {...completeProps} />; | ||
}; | ||
|
||
it('renders the specified label', () => { | ||
const label = 'label-test'; | ||
render(createTestComponent({ label })); | ||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TagVariant, string> = { | ||
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<ITagProps> = (props) => { | ||
const { label, variant = 'neutral', className } = props; | ||
|
||
return ( | ||
<div className={classNames('flex h-5 items-center rounded px-1', variantToClassName[variant], className)}> | ||
<p className="text-sm font-semibold leading-tight md:text-base">{label}</p> | ||
</div> | ||
); | ||
}; |