Skip to content

Commit 3e0a5dd

Browse files
committed
feat(component): add component LeetCodeDifficulty
1 parent cb08439 commit 3e0a5dd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
import kebabCase from 'lodash.kebabcase'
3+
4+
export interface Props {
5+
difficulty: string
6+
}
7+
8+
const { difficulty } = Astro.props
9+
const difficultyStyleMap: Record<string, string> = {
10+
Easy: 'difficulty-easy',
11+
Medium: 'difficulty-medium',
12+
Hard: 'difficulty-hard',
13+
}
14+
15+
const getDifficultyCssClass: (difficulty: string) => string = (
16+
difficulty: string
17+
) => {
18+
return Object.keys(difficultyStyleMap).includes(difficulty)
19+
? difficultyStyleMap[difficulty] || ''
20+
: ''
21+
}
22+
---
23+
24+
<a
25+
href={`/difficulties/${kebabCase(difficulty)}`}
26+
class:list={['px-2 py-1', getDifficultyCssClass(difficulty)]}
27+
>
28+
{difficulty}
29+
</a>
30+
31+
<style lang="scss">
32+
$difficulties: 'easy', 'medium', 'hard';
33+
34+
@each $difficulty in $difficulties {
35+
.difficulty-#{$difficulty} {
36+
@apply bg-difficulty-#{$difficulty};
37+
@apply border-2;
38+
@apply border-difficulty-#{$difficulty};
39+
@apply text-difficulty-#{$difficulty};
40+
@apply hover:bg-transparent;
41+
@apply hover:border-difficulty-#{$difficulty}-hover;
42+
@apply hover:text-difficulty-#{$difficulty}-hover;
43+
}
44+
}
45+
</style>

0 commit comments

Comments
 (0)