Remove unused logic on board column menu tags (#1373)

This commit is contained in:
Charles Bochet 2023-08-29 17:51:46 +02:00 committed by GitHub
parent 96c41563cf
commit b755b6009d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 36 deletions

View File

@ -1,15 +1,24 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
export type TagColor =
| 'green'
| 'turquoise'
| 'sky'
| 'blue'
| 'purple'
| 'pink'
| 'red'
| 'orange'
| 'yellow'
| 'gray';
const StyledTag = styled.h3<{ const StyledTag = styled.h3<{
colorHexCode?: string; color: TagColor;
colorId?: string;
}>` }>`
align-items: center; align-items: center;
background: ${({ colorId, theme }) => background: ${({ color, theme }) => theme.tag.background[color]};
colorId ? theme.tag.background[colorId] : null};
border-radius: ${({ theme }) => theme.border.radius.sm}; border-radius: ${({ theme }) => theme.border.radius.sm};
color: ${({ colorHexCode, colorId, theme }) => color: ${({ color, theme }) => theme.tag.text[color]};
colorId ? theme.tag.text[colorId] : colorHexCode};
display: flex; display: flex;
flex-direction: row; flex-direction: row;
font-size: ${({ theme }) => theme.font.size.md}; font-size: ${({ theme }) => theme.font.size.md};
@ -24,17 +33,14 @@ const StyledTag = styled.h3<{
`; `;
export type TagProps = { export type TagProps = {
color?: string; color: TagColor;
text: string; text: string;
onClick?: () => void; onClick?: () => void;
}; };
export function Tag({ color, text, onClick }: TagProps) { export function Tag({ color, text, onClick }: TagProps) {
const colorHexCode = color?.charAt(0) === '#' ? color : undefined;
const colorId = color?.charAt(0) === '#' ? undefined : color;
return ( return (
<StyledTag colorHexCode={colorHexCode} colorId={colorId} onClick={onClick}> <StyledTag color={color} onClick={onClick}>
{text} {text}
</StyledTag> </StyledTag>
); );

View File

@ -1,21 +1,48 @@
import { expect } from '@storybook/jest';
import type { Meta, StoryObj } from '@storybook/react'; import type { Meta, StoryObj } from '@storybook/react';
import { userEvent } from '@storybook/testing-library';
import { CatalogDecorator } from '~/testing/decorators/CatalogDecorator';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { Tag } from '../Tag'; import { Tag, TagColor } from '../Tag';
const meta: Meta<typeof Tag> = { const meta: Meta<typeof Tag> = {
title: 'UI/Accessories/Tag', title: 'UI/Tag/Tag',
component: Tag, component: Tag,
decorators: [ComponentDecorator],
argTypes: { color: { control: false } },
args: { text: 'Urgent' },
}; };
export default meta; export default meta;
type Story = StoryObj<typeof Tag>; type Story = StoryObj<typeof Tag>;
const TESTED_COLORS = [ export const Default: Story = {
args: {
text: 'Urgent',
color: 'red',
},
argTypes: { onClick: { action: 'clicked' } },
decorators: [ComponentDecorator],
play: async ({ canvasElement, args }) => {
const tag = canvasElement.querySelector('h3');
if (!tag) throw new Error('Tag not found');
await userEvent.click(tag);
await expect(args.onClick).toHaveBeenCalled();
},
};
export const Catalog: Story = {
args: { text: 'Urgent' },
argTypes: {
color: { control: false },
},
parameters: {
catalog: {
dimensions: [
{
name: 'colors',
values: [
'green', 'green',
'turquoise', 'turquoise',
'sky', 'sky',
@ -26,14 +53,11 @@ const TESTED_COLORS = [
'orange', 'orange',
'yellow', 'yellow',
'gray', 'gray',
]; ] satisfies TagColor[],
props: (color: TagColor) => ({ color }),
export const AllTags: Story = { },
render: (args) => ( ],
<> },
{TESTED_COLORS.map((color) => ( },
<Tag {...args} color={color} /> decorators: [CatalogDecorator],
))}
</>
),
}; };