Skip to content

Commit 1d59140

Browse files
authored
Merge pull request #204 from ethereum/quiz-styling
Fix Quiz styling
2 parents fdca95f + f1f4d50 commit 1d59140

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/components/Quiz/QuizWidget/QuizContent.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback } from "react"
2-
import { Text, VStack } from "@chakra-ui/react"
2+
import { Text, type TextProps, VStack } from "@chakra-ui/react"
33

44
import { ChildOnlyProp } from "@/lib/types"
55

@@ -12,13 +12,20 @@ export const QuizContent = ({ children }: QuizContentProps) => {
1212

1313
const getTitleContent = useCallback((): string => {
1414
if (!answerStatus) return title
15-
16-
return answerStatus === 'correct' ? "Correct!" : "Incorrect"
15+
16+
return answerStatus === "correct" ? "Correct!" : "Incorrect"
1717
}, [answerStatus, title])
18-
18+
19+
const getTitleTextColor = (): TextProps["color"] => {
20+
if (!answerStatus) return "primary.hover"
21+
return answerStatus === "correct" ? "success.base" : "fail.base"
22+
}
23+
1924
return (
2025
<VStack spacing="4">
21-
<Text>{getTitleContent()}</Text>
26+
<Text fontWeight="bold" textAlign="center" color={getTitleTextColor()}>
27+
{getTitleContent()}
28+
</Text>
2229
{children}
2330
</VStack>
2431
)

src/components/Quiz/QuizWidget/QuizRadioGroup.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,18 @@ const CustomRadio = ({
118118
...radioProps
119119
}: CustomRadioProps) => {
120120
const INPUT_ID = `quiz-question-answer-${index}`
121-
const { getInputProps, getRadioProps, getLabelProps } = useRadio({
121+
const { state, getInputProps, getRadioProps, getLabelProps } = useRadio({
122122
...radioProps,
123123
id: INPUT_ID,
124124
})
125125

126+
const buttonBg = useMemo<string>(() => {
127+
if (!state.isChecked) return "body.inverted"
128+
if (!isAnswerVisible) return "primary.base"
129+
if (!isSelectedCorrect) return "error.base"
130+
return "success.base"
131+
}, [state.isChecked, isAnswerVisible, isSelectedCorrect])
132+
126133
const primaryBaseColor = useToken("colors", "primary.base")
127134

128135
const getAnswerColor = (): ChakraProps["bg"] =>
@@ -149,6 +156,7 @@ const CustomRadio = ({
149156
w="full"
150157
p="2"
151158
color="text"
159+
bg={buttonBg}
152160
borderRadius="base"
153161
_hover={{
154162
outline: isAnswerVisible ? "none" : `1px solid ${primaryBaseColor}`,

0 commit comments

Comments
 (0)