Fix bug tag colors

This commit is contained in:
Charles Bochet
2023-08-29 18:23:24 +02:00
parent b755b6009d
commit ccac7ec07b

View File

@ -1,16 +1,23 @@
import styled from '@emotion/styled';
export type TagColor =
| 'green'
| 'turquoise'
| 'sky'
| 'blue'
| 'purple'
| 'pink'
| 'red'
| 'orange'
| 'yellow'
| 'gray';
const tagColors = [
'green',
'turquoise',
'sky',
'blue',
'purple',
'pink',
'red',
'orange',
'yellow',
'gray',
];
export type TagColor = (typeof tagColors)[number];
export function castToTagColor(color: string): TagColor {
return tagColors.find((tagColor) => tagColor === color) ?? 'gray';
}
const StyledTag = styled.h3<{
color: TagColor;
@ -33,14 +40,14 @@ const StyledTag = styled.h3<{
`;
export type TagProps = {
color: TagColor;
color: string;
text: string;
onClick?: () => void;
};
export function Tag({ color, text, onClick }: TagProps) {
return (
<StyledTag color={color} onClick={onClick}>
<StyledTag color={castToTagColor(color)} onClick={onClick}>
{text}
</StyledTag>
);