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