Skip to content

Commit d13f5da

Browse files
Merge pull request #2344 from bryanjenningz/make-exericse-card-responsive
Make exercise card responsive and replace module name with "Your Answer"
2 parents 4c87423 + a30f711 commit d13f5da

File tree

7 files changed

+56
-38
lines changed

7 files changed

+56
-38
lines changed

__tests__/__snapshots__/storyshots.test.js.snap

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5222,27 +5222,31 @@ exports[`Storyshots Components/ExerciseCard Basic 1`] = `
52225222
className="card p-5 border-0 shadow"
52235223
>
52245224
<div
5225-
className="fw-bold mb-2"
5225+
className="d-flex flex-column flex-md-row mb-2"
52265226
>
5227-
Problem
5228-
</div>
5229-
<div
5230-
className="d-flex mb-2"
5231-
>
5232-
<pre
5233-
className="w-50 bg-light py-3 px-4 mb-0 me-3"
5227+
<div
5228+
className="mb-0 me-md-3 exerciseCard__section"
52345229
>
5235-
let a = 5
5230+
<div
5231+
className="fw-bold mb-2"
5232+
>
5233+
Problem
5234+
</div>
5235+
<pre
5236+
className="bg-light py-3 px-4"
5237+
>
5238+
let a = 5
52365239
a = a + 10
52375240
// what is a?
5238-
</pre>
5241+
</pre>
5242+
</div>
52395243
<div
5240-
className="w-50 ms-3"
5244+
className="ms-md-3 exerciseCard__section"
52415245
>
52425246
<div
5243-
className="mb-2"
5247+
className="fw-bold mt-2 mt-md-0 mb-2"
52445248
>
5245-
Variable mutation
5249+
Your Answer
52465250
</div>
52475251
<input
52485252
aria-label="User answer"
@@ -5251,12 +5255,12 @@ a = a + 10
52515255
value=""
52525256
/>
52535257
<div
5254-
className="exerciseCard__message my-2"
5258+
className="exerciseCard__message my-3"
52555259
>
52565260

52575261
</div>
52585262
<div
5259-
className="d-flex"
5263+
className="d-flex flex-column flex-md-row"
52605264
>
52615265
<button
52625266
className="newButton "
@@ -5265,7 +5269,7 @@ a = a + 10
52655269
SUBMIT
52665270
</button>
52675271
<button
5268-
className="bg-transparent ms-3 border-0 fw-normal"
5272+
className="bg-transparent mt-2 mt-md-0 ms-md-3 border-0 fw-normal"
52695273
onClick={[Function]}
52705274
>
52715275
<div

components/ExerciseCard/ExerciseCard.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ a = a + 10
1313

1414
const { getByRole, queryByText, getByLabelText } = render(
1515
<ExerciseCard
16-
challengeName="Variable mutation"
1716
problem={exampleProblem}
1817
answer={exampleAnswer}
1918
explanation={exampleExplanation}

components/ExerciseCard/ExerciseCard.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Text } from '../theme/Text'
44
import styles from './exerciseCard.module.scss'
55

66
export type ExerciseCardProps = {
7-
challengeName: string
87
problem: string
98
answer: string
109
explanation: string
@@ -18,24 +17,21 @@ enum Message {
1817

1918
type MessageKey = keyof typeof Message
2019

21-
const ExerciseCard = ({
22-
challengeName,
23-
problem,
24-
answer,
25-
explanation
26-
}: ExerciseCardProps) => {
20+
const ExerciseCard = ({ problem, answer, explanation }: ExerciseCardProps) => {
2721
const [studentAnswer, setStudentAnswer] = useState('')
2822
const [answerShown, setAnswerShown] = useState(false)
2923
const [messageKey, setMessageKey] = useState<MessageKey>('EMPTY')
3024
const message = Message[messageKey]
3125

3226
return (
3327
<section className="card p-5 border-0 shadow">
34-
<div className="fw-bold mb-2">Problem</div>
35-
<div className="d-flex mb-2">
36-
<pre className="w-50 bg-light py-3 px-4 mb-0 me-3">{problem}</pre>
37-
<div className="w-50 ms-3">
38-
<div className="mb-2">{challengeName}</div>
28+
<div className="d-flex flex-column flex-md-row mb-2">
29+
<div className={`mb-0 me-md-3 ${styles.exerciseCard__section}`}>
30+
<div className="fw-bold mb-2">Problem</div>
31+
<pre className="bg-light py-3 px-4">{problem}</pre>
32+
</div>
33+
<div className={`ms-md-3 ${styles.exerciseCard__section}`}>
34+
<div className="fw-bold mt-2 mt-md-0 mb-2">Your Answer</div>
3935
<input
4036
aria-label="User answer"
4137
className={`form-control mb-2 ${
@@ -47,11 +43,11 @@ const ExerciseCard = ({
4743
<div
4844
className={`${styles.exerciseCard__message} ${
4945
messageKey === 'ERROR' ? styles.exerciseCard__message__error : ''
50-
} my-2`}
46+
} my-3`}
5147
>
5248
{message}
5349
</div>
54-
<div className="d-flex">
50+
<div className="d-flex flex-column flex-md-row">
5551
<NewButton
5652
onClick={() => {
5753
if (studentAnswer.trim() === answer.trim()) {
@@ -65,7 +61,7 @@ const ExerciseCard = ({
6561
SUBMIT
6662
</NewButton>
6763
<button
68-
className="bg-transparent ms-3 border-0 fw-normal"
64+
className="bg-transparent mt-2 mt-md-0 ms-md-3 border-0 fw-normal"
6965
onClick={() => setAnswerShown(!answerShown)}
7066
>
7167
<Text size="xs" bold>
@@ -79,9 +75,15 @@ const ExerciseCard = ({
7975
<>
8076
<hr />
8177
<div className="fw-bold mb-2">Answer</div>
82-
<div className="d-flex mb-2">
83-
<pre className="w-50 bg-light py-3 px-4 mb-0 me-3">{answer}</pre>
84-
<div className="w-50 ms-3">{explanation}</div>
78+
<div className="d-flex flex-column flex-md-row mb-2">
79+
<pre
80+
className={`bg-light py-3 px-4 mb-2 mb-md-0 me-md-3 ${styles.exerciseCard__section}`}
81+
>
82+
{answer}
83+
</pre>
84+
<div className={`ms-md-3 ${styles.exerciseCard__section}`}>
85+
{explanation}
86+
</div>
8587
</div>
8688
</>
8789
)}

components/ExerciseCard/exerciseCard.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
$error-red: #a0213e;
22

3+
.exerciseCard__section {
4+
width: 100%;
5+
6+
@media (min-width: 768px) {
7+
width: 50%;
8+
}
9+
}
10+
311
.exerciseCard__message {
412
min-height: 20px;
513
font-size: 12px;

pages/exercises/[lessonSlug].tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const Exercise = ({
107107
showSkipButton
108108
}: ExerciseProps) => {
109109
return (
110-
<div className="w-75 mx-auto">
110+
<div className={`mx-auto ${styles.exercise__container}`}>
111111
<button
112112
className="btn ps-0 d-flex align-items-center"
113113
onClick={() => setExerciseIndex(-1)}
@@ -117,7 +117,6 @@ const Exercise = ({
117117

118118
<h1 className="mb-4 fs-2">{lessonTitle}</h1>
119119
<ExerciseCard
120-
challengeName={exercise.challengeName}
121120
problem={exercise.problem}
122121
answer={exercise.answer}
123122
explanation={exercise.explanation}

scss/exercises.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@
99
width: 100%;
1010
}
1111
}
12+
13+
.exercise__container {
14+
width: 100%;
15+
@media (min-width: 768px) {
16+
width: 75%;
17+
}
18+
}

stories/components/ExerciseCard.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const exampleExplanation = `You can reassign variables that are initialized with
1717
export const Basic = () => {
1818
return (
1919
<ExerciseCard
20-
challengeName="Variable mutation"
2120
problem={exampleProblem}
2221
answer={exampleAnswer}
2322
explanation={exampleExplanation}

0 commit comments

Comments
 (0)