Skip to content

Commit 0052ce2

Browse files
committed
fix: update exercise.jsx
1 parent 98b7cd5 commit 0052ce2

File tree

2 files changed

+94
-58
lines changed

2 files changed

+94
-58
lines changed

component/markdown.jsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Span, Color, P, Div } from './elements.jsx'
2+
import { css } from '../lib/dom.js'
3+
import { navigate } from '../lib/router.js'
4+
5+
css(`
6+
li.mli {
7+
display:block;
8+
}
9+
li.mli.link {
10+
cursor:pointer;
11+
}
12+
13+
`)
14+
15+
export const MTitle = Object.fromEntries(
16+
['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].map((el) => [
17+
el,
18+
({ children, ...props }) =>
19+
h(
20+
el,
21+
props,
22+
<>
23+
<Span fg="red">{'#'.repeat(Number(el.slice(1)))}</Span>&nbsp;
24+
</>,
25+
children,
26+
),
27+
]),
28+
)
29+
30+
export const MItalicWord = ({ children, color }) => {
31+
return (
32+
<P>
33+
<Span fg="orange"> > </Span>
34+
<Color.CommentLighter>*</Color.CommentLighter>
35+
<Span fg={color} style={{ fontStyle: 'italic' }}>
36+
{children}
37+
</Span>
38+
<Color.CommentLighter>*</Color.CommentLighter>
39+
</P>
40+
)
41+
}
42+
43+
export const MLi = ({ children, link }) => {
44+
let ColorIze = link ? Color.CyanDarker : Color.CommentLighter
45+
return (
46+
<li
47+
class={`mli ${link ? 'link' : ''}`}
48+
onClick={(e) => {
49+
if (link) navigate(link)
50+
}}
51+
>
52+
<Span fg="orange"> - </Span>
53+
<Span
54+
style={{
55+
padding: '0.1rem',
56+
background: !link && 'rgba(75, 75, 75, 0.63)',
57+
textDecoration: link && 'underline',
58+
}}
59+
fg={link ? 'cyan-darker' : 'white'}
60+
>
61+
<ColorIze>{link ? '[' : '`'}</ColorIze>
62+
{children}
63+
<ColorIze>{link ? ']' : '`'}</ColorIze>
64+
</Span>
65+
</li>
66+
)
67+
}
68+
69+
export const Warning = ({ children }) => {
70+
return <Div style={{ border: '1px dashed red',padding:"0.8rem" }}>{children}</Div>
71+
}

page/exercise.jsx

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,63 @@
11
import { css } from '../lib/dom.js'
2-
import { Div, P, Span } from '../component/elements.jsx'
2+
import { Div, P } from '../component/elements.jsx'
3+
import { MTitle, MItalicWord, MLi, Warning } from '../component/markdown.jsx'
34
import exercise from '../data/fakeExercise.json'
45

56
css(`
67
.exercise h1 {
78
font-weight: bolder;
89
}
910
10-
.exercise>hr {
11-
width: 100%;
12-
height: 2px;
13-
background: grey;
14-
}
15-
1611
.exercise h3 {
1712
font-weight: bolder;
18-
text-decoration: underline;
19-
}
20-
21-
.exercise ul li {
22-
display: block;
2313
}
2414
2515
.exercise .instructions .description {
2616
padding: 0.3rem;
2717
}
2818
29-
.exercise .instructions ul li:before {
30-
content: '';
31-
display: inline-block;
32-
width: 12px;
33-
height: 12px;
34-
margin-right: 10px;
35-
border-radius: 0.5rem;
36-
background: white;
37-
}
38-
39-
.exercise .notions h3 span {
40-
color: yellow;
41-
}
42-
4319
.exercise .notions p {
4420
padding: 0.3rem;
45-
46-
.exercise .notions ul li {
47-
cursor:pointer;
48-
transition: all .25s ease-in-out;
49-
}
50-
51-
.exercise .notions ul li:hover {
52-
color: skyblue;
53-
font-weight:bolder;
54-
}
55-
56-
.exercise .notions ul li:before {
57-
content: '';
58-
display: inline-block;
59-
width: 12px;
60-
height: 12px;
61-
border-radius: 0 10rem 10rem 0;
62-
background: white;
6321
}
6422
`)
6523
export const Exercise = () => {
6624
return (
6725
<Div class="exercise">
68-
<h1>🖊 {exercise.name}</h1>
69-
<hr />
70-
26+
<MTitle.h2>{exercise.name}</MTitle.h2>
7127
{'\n'}
7228
<Div class="instructions">
73-
<h3>Instructions</h3>
29+
<MTitle.h3>Instructions</MTitle.h3>
30+
{'\n'}
7431
{exercise.description && (
7532
<P class="description">{exercise.description}</P>
7633
)}
34+
{'\n'}
7735
{exercise.instructions && (
7836
<ul>
7937
{exercise.instructions.map((key) => (
80-
<li key={key}>{key}</li>
38+
<MLi key={key}>{key}</MLi>
8139
))}
8240
</ul>
8341
)}
8442
</Div>
8543
{'\n'}
44+
8645
<Div class="notions">
87-
<h3>
88-
<span></span> Warning
89-
</h3>
90-
<P>To do this Exercise you should know the following concepts : </P>
91-
<ul>
92-
{exercise.notions.map((key) => (
93-
<li key={key}>{key}</li>
94-
))}
95-
</ul>
46+
<MTitle.h3>Warning</MTitle.h3>
47+
{'\n'}
48+
<Warning>
49+
<MItalicWord color="red">
50+
To do this Exercise you should know the following concepts :
51+
</MItalicWord>
52+
{'\n'}
53+
<ul>
54+
{exercise.notions.map((key) => (
55+
<MLi key={key} link="/notions">
56+
{key}
57+
</MLi>
58+
))}
59+
</ul>
60+
</Warning>
9661
</Div>
9762
{'\n'}
9863
</Div>

0 commit comments

Comments
 (0)