Skip to content

Commit 655a434

Browse files
refactor(QuizzesList): migrate to Tailwind
1 parent e25ce68 commit 655a434

File tree

3 files changed

+51
-43
lines changed

3 files changed

+51
-43
lines changed

src/components/Quiz/QuizItem.tsx

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { useTranslation } from "next-i18next"
2-
import { Box, Flex, ListItem, Stack, Text } from "@chakra-ui/react"
32

43
import type { QuizzesSection } from "@/lib/types"
54

6-
import { Button } from "../Buttons"
5+
import { cn } from "@/lib/utils/cn"
6+
77
import { GreenTickIcon } from "../icons/quiz"
88
import Tag from "../Tag"
99
import Translation from "../Translation"
10+
import { Button } from "../ui/buttons/Button"
11+
import { Flex, Stack } from "../ui/flex"
12+
import { ListItem } from "../ui/list"
1013

1114
export type QuizzesListItemProps = Omit<QuizzesSection, "id"> & {
1215
isCompleted: boolean
@@ -26,37 +29,24 @@ const QuizItem = ({
2629

2730
return (
2831
<ListItem
29-
color={isCompleted ? "body.medium" : "text"}
30-
fontWeight="bold"
31-
px={{ base: 0, lg: 4 }}
32-
py={4}
33-
borderBottom="1px solid"
34-
borderColor="disabled"
35-
mb={0}
36-
sx={{ counterIncrement: "list-counter" }}
32+
className={cn(
33+
isCompleted ? "text-body-medium" : "text-body",
34+
"mb-0 border-b border-disabled py-4 font-bold [counter-increment:_list-counter] lg:px-4"
35+
)}
3736
>
38-
<Flex
39-
justifyContent="space-between"
40-
alignItems={{ base: "flex-start", lg: "center" }}
41-
direction={{ base: "column", lg: "row" }}
42-
>
43-
<Stack mb={{ base: 5, lg: 0 }}>
44-
<Flex gap={2} alignItems="center">
45-
<Text
46-
color={isCompleted ? "body.medium" : "text"}
47-
_before={{
48-
content: 'counter(list-counter) ". "',
49-
}}
50-
>
37+
<Flex className="justify-between max-lg:flex-col lg:items-center">
38+
<Stack className="max-lg:mb-5">
39+
<Flex className="items-center gap-2">
40+
<span className="before:content-[counter(list-counter)_'._']">
5141
<Translation id={titleId} />
52-
</Text>
42+
</span>
5343

5444
{/* Show green tick if quizz was completed only */}
5545
{isCompleted && <GreenTickIcon />}
5646
</Flex>
5747

5848
{/* Labels */}
59-
<Flex gap={3}>
49+
<Flex className="gap-3">
6050
{/* number of questions - label */}
6151
<Tag
6252
label={t(`${numberOfQuestions} ${t("questions")}`)}
@@ -69,15 +59,15 @@ const QuizItem = ({
6959
</Stack>
7060

7161
{/* Start Button */}
72-
<Box w={{ base: "full", lg: "auto" }}>
62+
<div className="max-lg:w-full">
7363
<Button
7464
variant="outline"
75-
w={{ base: "full", lg: "auto" }}
65+
className="max-lg:w-full"
7666
onClick={handleStart}
7767
>
7868
<Translation id="learn-quizzes:start" />
7969
</Button>
80-
</Box>
70+
</div>
8171
</Flex>
8272
</ListItem>
8373
)

src/components/Quiz/QuizzesList.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from "react"
2-
import { Heading, OrderedList, Stack, Text } from "@chakra-ui/react"
32

43
import type { QuizKey, QuizzesSection, UserStats } from "@/lib/types"
54

65
import { trackCustomEvent } from "@/lib/utils/matomo"
76

87
import allQuizzesData from "@/data/quizzes"
98

9+
import { Stack } from "../ui/flex"
10+
import { OrderedList } from "../ui/list"
11+
1012
import QuizItem from "./QuizItem"
1113

1214
type QuizzesListProps = {
@@ -26,17 +28,13 @@ const QuizzesList = ({
2628
quizHandler,
2729
modalHandler,
2830
}: QuizzesListProps) => (
29-
<Stack spacing="8" px={{ base: "8", lg: 0 }} pt="12">
30-
<Stack spacing="8">
31-
<Heading size="xl">{headingId}</Heading>
32-
<Text>{descriptionId}</Text>
31+
<Stack className="gap-8 pt-12 max-lg:px-8">
32+
<Stack className="gap-8">
33+
<h2>{headingId}</h2>
34+
<p>{descriptionId}</p>
3335
</Stack>
3436

35-
<OrderedList
36-
m={0}
37-
listStyleType="none"
38-
sx={{ counterReset: "list-counter" }}
39-
>
37+
<OrderedList className="m-0 list-none [counter-reset:_list-counter]">
4038
{content.map((listItem) => {
4139
const handleStart = () => {
4240
quizHandler(listItem.id)

src/components/Quiz/stories/QuizzesList.stories.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ const meta = {
2626
},
2727
},
2828
},
29-
} satisfies Meta<typeof QuizzesListComponent>
30-
31-
export default meta
32-
33-
export const QuizzesList: StoryObj<typeof meta> = {
3429
args: {
3530
content: ethereumBasicsQuizzes,
3631
headingId: "basics",
@@ -43,7 +38,32 @@ export const QuizzesList: StoryObj<typeof meta> = {
4338
quizHandler: fn(),
4439
modalHandler: fn(),
4540
},
41+
} satisfies Meta<typeof QuizzesListComponent>
4642

43+
export default meta
44+
45+
export const Default: StoryObj<typeof meta> = {
46+
render: ({ headingId, descriptionId, ...args }) => (
47+
<QuizzesListComponent
48+
{...args}
49+
headingId={getTranslation(headingId, "learn-quizzes")}
50+
descriptionId={getTranslation(descriptionId, "learn-quizzes")}
51+
/>
52+
),
53+
}
54+
55+
export const OneCompletedQuiz: StoryObj<typeof meta> = {
56+
args: {
57+
...meta.args,
58+
userStats: {
59+
average: [100],
60+
score: 4,
61+
completed: {
62+
...meta.args.userStats.completed,
63+
"what-is-ethereum": [true, 5],
64+
},
65+
},
66+
},
4767
render: ({ headingId, descriptionId, ...args }) => (
4868
<QuizzesListComponent
4969
{...args}

0 commit comments

Comments
 (0)