-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathChallenge.tsx
More file actions
140 lines (131 loc) · 4.16 KB
/
Copy pathChallenge.tsx
File metadata and controls
140 lines (131 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
import {useState} from 'react';
import cn from 'classnames';
import {Button} from 'components/Button';
import {ChallengeContents} from './Challenges';
import {IconHint} from '../../Icon/IconHint';
import {IconSolution} from '../../Icon/IconSolution';
import {IconArrowSmall} from '../../Icon/IconArrowSmall';
import {H4} from '../Heading';
interface ChallengeProps {
isRecipes?: boolean;
totalChallenges: number;
currentChallenge: ChallengeContents;
hasNextChallenge: boolean;
handleClickNextChallenge: () => void;
}
export function Challenge({
isRecipes,
totalChallenges,
currentChallenge,
hasNextChallenge,
handleClickNextChallenge,
}: ChallengeProps) {
const [showHint, setShowHint] = useState(false);
const [showSolution, setShowSolution] = useState(false);
const toggleHint = () => {
if (showSolution && !showHint) {
setShowSolution(false);
}
setShowHint((hint) => !hint);
};
const toggleSolution = () => {
if (showHint && !showSolution) {
setShowHint(false);
}
setShowSolution((solution) => !solution);
};
return (
<div className="p-5 sm:py-8 sm:px-8">
<div>
<H4
className="text-xl text-primary dark:text-primary-dark mb-2 mt-0 font-medium"
id={currentChallenge.id}>
<div className="font-bold block md:inline">
{isRecipes ? 'Exemplo' : 'Desafio'} {currentChallenge.order} de{' '}
{totalChallenges}
<span className="text-primary dark:text-primary-dark">: </span>
</div>
{currentChallenge.name}
</H4>
{currentChallenge.content}
</div>
<div className="flex justify-between items-center mt-4">
{currentChallenge.hint ? (
<div>
<Button className="me-2" onClick={toggleHint} active={showHint}>
<IconHint />{' '}
{showHint ? 'Ocultar dica' : 'Exibir dica'}
</Button>
<Button
className="me-2"
onClick={toggleSolution}
active={showSolution}>
<IconSolution />{' '}
{showSolution ? 'Ocultar Solução' : 'Exibir Solução'}
</Button>
</div>
) : (
!isRecipes && (
<Button
className="me-2"
onClick={toggleSolution}
active={showSolution}>
<IconSolution />{' '}
{showSolution ? 'Ocultar Solução' : 'Exibir Solução'}
</Button>
)
)}
{hasNextChallenge && (
<Button
className={cn(
isRecipes
? 'bg-purple-50 border-purple-50 hover:bg-purple-50 focus:bg-purple-50 active:bg-purple-50'
: 'bg-link dark:bg-link-dark'
)}
onClick={handleClickNextChallenge}
active>
Next {isRecipes ? 'Example' : 'Challenge'}
<IconArrowSmall displayDirection="end" className="block ms-1.5" />
</Button>
)}
</div>
{showHint && currentChallenge.hint}
{showSolution && (
<div className="mt-6">
<h3 className="text-2xl font-bold text-primary dark:text-primary-dark">
Solução
</h3>
{currentChallenge.solution}
<div className="flex justify-between items-center mt-4">
<Button onClick={() => setShowSolution(false)}>
Fechar solução
</Button>
{hasNextChallenge && (
<Button
className={cn(
isRecipes ? 'bg-purple-50' : 'bg-link dark:bg-link-dark'
)}
onClick={handleClickNextChallenge}
active>
Próximo desafio
<IconArrowSmall
displayDirection="end"
className="block ms-1.5"
/>
</Button>
)}
</div>
</div>
)}
</div>
);
}