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,39 +1,63 @@
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 = {
'green', args: {
'turquoise', text: 'Urgent',
'sky', color: 'red',
'blue', },
'purple', argTypes: { onClick: { action: 'clicked' } },
'pink', decorators: [ComponentDecorator],
'red', play: async ({ canvasElement, args }) => {
'orange', const tag = canvasElement.querySelector('h3');
'yellow',
'gray',
];
export const AllTags: Story = { if (!tag) throw new Error('Tag not found');
render: (args) => (
<> await userEvent.click(tag);
{TESTED_COLORS.map((color) => ( await expect(args.onClick).toHaveBeenCalled();
<Tag {...args} color={color} /> },
))} };
</>
), export const Catalog: Story = {
args: { text: 'Urgent' },
argTypes: {
color: { control: false },
},
parameters: {
catalog: {
dimensions: [
{
name: 'colors',
values: [
'green',
'turquoise',
'sky',
'blue',
'purple',
'pink',
'red',
'orange',
'yellow',
'gray',
] satisfies TagColor[],
props: (color: TagColor) => ({ color }),
},
],
},
},
decorators: [CatalogDecorator],
}; };