11---
2+ import type { HTMLAttributes } from ' astro/types'
23import kebabCase from ' lodash.kebabcase'
34
4- export interface Props {
5+ export interface Props extends HTMLAttributes <' a' | ' span' > {
6+ tag? : string
57 difficulty: string
68}
79
8- const { difficulty } = Astro .props
10+ const { difficulty, tag = ' a' , ... props } = Astro .props
11+
12+ const Tag = tag
13+
14+ const tagProps: Record <string , string > = {}
15+ if (tag === ' a' ) {
16+ tagProps .href = ` /difficulties/${kebabCase (difficulty )} `
17+ }
18+
919const difficultyStyleMap: Record <string , string > = {
1020 Easy: ' difficulty-easy' ,
1121 Medium: ' difficulty-medium' ,
@@ -21,12 +31,17 @@ const getDifficultyCssClass: (difficulty: string) => string = (
2131}
2232---
2333
24- <a
25- href ={ ` /difficulties/${kebabCase (difficulty )} ` }
26- class:list ={ [' px-2 py-1' , getDifficultyCssClass (difficulty )]}
34+ <Tag
35+ {... tagProps }
36+ class:list ={ [
37+ ' px-2 py-1' ,
38+ getDifficultyCssClass (difficulty ),
39+ tag === ' a' ? ' link' : ' ' ,
40+ props .class ,
41+ ]}
2742>
2843 { difficulty }
29- </a >
44+ </Tag >
3045
3146<style lang =" scss" >
3247 $difficulties: 'easy', 'medium', 'hard';
@@ -37,9 +52,11 @@ const getDifficultyCssClass: (difficulty: string) => string = (
3752 @apply border-2;
3853 @apply border-difficulty-#{$difficulty};
3954 @apply text-difficulty-#{$difficulty};
40- @apply hover:bg-site-bg;
41- @apply hover:border-difficulty-#{$difficulty}-hover;
42- @apply hover:text-difficulty-#{$difficulty}-hover;
55+ &.link {
56+ @apply hover:bg-site-bg;
57+ @apply hover:border-difficulty-#{$difficulty}-hover;
58+ @apply hover:text-difficulty-#{$difficulty}-hover;
59+ }
4360 }
4461 }
4562</style >
0 commit comments