[questions][ui] move QuestionTypeBadge icon to start

pull/549/head
Jeff Sieu 2 years ago
parent a6fd4c4c09
commit c2599d6a8c

@ -1,4 +1,12 @@
import type { ComponentProps } from 'react';
import {
BookOpenIcon,
ChatBubbleLeftRightIcon,
CodeBracketIcon,
WrenchIcon,
} from '@heroicons/react/20/solid';
import type { QuestionsQuestionType } from '@prisma/client'; import type { QuestionsQuestionType } from '@prisma/client';
import type { BadgeVariant } from '@tih/ui';
import { Badge } from '@tih/ui'; import { Badge } from '@tih/ui';
import { QUESTION_TYPES } from '~/utils/questions/constants'; import { QUESTION_TYPES } from '~/utils/questions/constants';
@ -7,11 +15,29 @@ export type QuestionTypeBadgeProps = {
type: QuestionsQuestionType; type: QuestionsQuestionType;
}; };
type BadgeProps = ComponentProps<typeof Badge>;
const variantMap: Record<QuestionsQuestionType, BadgeVariant> = {
BEHAVIORAL: 'danger',
CODING: 'info',
SYSTEM_DESIGN: 'warning',
THEORY: 'success',
};
const iconMap: Record<QuestionsQuestionType, Required<BadgeProps>['endAddOn']> =
{
BEHAVIORAL: ChatBubbleLeftRightIcon,
CODING: CodeBracketIcon,
SYSTEM_DESIGN: WrenchIcon,
THEORY: BookOpenIcon,
};
export default function QuestionTypeBadge({ type }: QuestionTypeBadgeProps) { export default function QuestionTypeBadge({ type }: QuestionTypeBadgeProps) {
return ( return (
<Badge <Badge
label={QUESTION_TYPES.find(({ value }) => value === type)!.label} label={QUESTION_TYPES.find(({ value }) => value === type)!.label}
variant="info" startAddOn={iconMap[type]}
variant={variantMap[type]}
/> />
); );
} }

Loading…
Cancel
Save