1
1
import cn from 'clsx'
2
2
import NextLink from 'next/link'
3
- import type { ComponentProps , CSSProperties , ReactNode } from 'react'
4
-
5
- const classes = {
6
- cards : cn (
7
- 'nextra-cards _mt-4 _gap-4 _grid' ,
8
- '_not-prose' // for nextra-theme-blog
9
- ) ,
10
- card : cn (
11
- 'nextra-card _group _flex _flex-col _justify-start _overflow-hidden _rounded-lg _border _border-gray-200' ,
12
- '_text-current _no-underline dark:_shadow-none' ,
13
- 'hover:_shadow-gray-100 dark:hover:_shadow-none _shadow-gray-100' ,
14
- 'active:_shadow-sm active:_shadow-gray-200' ,
15
- '_transition-all _duration-200 hover:_border-gray-300'
16
- ) ,
17
- title : cn (
18
- '_flex _font-semibold _items-start _gap-2 _p-4 _text-gray-700 hover:_text-gray-900'
19
- )
20
- }
21
-
22
- const arrowEl = (
23
- < span className = "_transition-transform _duration-75 group-hover:_translate-x-[2px]" >
24
- →
25
- </ span >
26
- )
3
+ import type { ComponentProps , ReactElement , ReactNode } from 'react'
27
4
28
5
function Card ( {
29
6
children,
30
7
title,
31
8
icon,
32
- image,
33
9
arrow,
34
10
href,
35
11
...props
36
12
} : {
37
13
title : string
38
- icon : ReactNode
14
+ icon ?: ReactElement
39
15
arrow ?: boolean
40
16
href : string
41
- } & (
42
- | {
43
- children ?: never
44
- image ?: false
45
- }
46
- | {
47
- children : ReactNode
48
- image : true
49
- }
50
- ) ) {
51
- const animatedArrow = arrow ? arrowEl : null
52
-
53
- if ( image ) {
54
- return (
55
- < NextLink
56
- href = { href }
57
- className = { cn (
58
- classes . card ,
59
- '_bg-gray-100 _shadow dark:_border-neutral-700 dark:_bg-neutral-800 dark:_text-gray-50 hover:_shadow-lg dark:hover:_border-neutral-500 dark:hover:_bg-neutral-700'
60
- ) }
61
- { ...props }
62
- >
63
- { children }
64
- < span
65
- className = { cn (
66
- classes . title ,
67
- 'dark:_text-gray-300 dark:hover:_text-gray-100'
68
- ) }
69
- >
70
- { icon }
71
- < span className = "_flex _gap-1" >
72
- { title }
73
- { animatedArrow }
74
- </ span >
75
- </ span >
76
- </ NextLink >
77
- )
78
- }
79
-
17
+ children ?: ReactNode
18
+ } ) {
80
19
return (
81
20
< NextLink
82
21
href = { href }
83
22
className = { cn (
84
- classes . card ,
85
- '_bg-transparent _shadow-sm dark:_border-neutral-800 hover:_bg-slate-50 hover:_shadow-md dark:hover:_border-neutral-700 dark:hover:_bg-neutral-900'
23
+ 'nextra-card _group _flex _flex-col _justify-start _overflow-hidden _rounded-lg _border _border-gray-200' ,
24
+ '_text-current _no-underline dark:_shadow-none' ,
25
+ 'hover:_shadow-gray-100 dark:hover:_shadow-none _shadow-gray-100' ,
26
+ 'active:_shadow-sm active:_shadow-gray-200' ,
27
+ '_transition-all _duration-200 hover:_border-gray-300' ,
28
+ children
29
+ ? '_bg-gray-100 _shadow dark:_border-neutral-700 dark:_bg-neutral-800 dark:_text-gray-50 hover:_shadow-lg dark:hover:_border-neutral-500 dark:hover:_bg-neutral-700'
30
+ : '_bg-transparent _shadow-sm dark:_border-neutral-800 hover:_bg-slate-50 hover:_shadow-md dark:hover:_border-neutral-700 dark:hover:_bg-neutral-900'
86
31
) }
87
32
{ ...props }
88
33
>
34
+ { children }
89
35
< span
90
36
className = { cn (
91
- classes . title ,
92
- 'dark:_text-neutral-200 dark:hover:_text-neutral-50 _flex _items-center'
37
+ '_flex _font-semibold _items-center _gap-2 _p-4 _text-gray-700 hover:_text-gray-900' ,
38
+ arrow &&
39
+ 'after:_content-["→"] after:_transition-transform after:_duration-75 after:group-hover:_translate-x-0.5' ,
40
+ children
41
+ ? 'dark:_text-gray-300 dark:hover:_text-gray-100'
42
+ : 'dark:_text-neutral-200 dark:hover:_text-neutral-50'
93
43
) }
94
44
>
95
45
{ icon }
96
46
{ title }
97
- { animatedArrow }
98
47
</ span >
99
48
</ NextLink >
100
49
)
@@ -109,14 +58,16 @@ function _Cards({
109
58
} : { num ?: number } & ComponentProps < 'div' > ) {
110
59
return (
111
60
< div
112
- className = { cn ( classes . cards , className ) }
61
+ className = { cn (
62
+ 'nextra-cards _mt-4 _gap-4 _grid' ,
63
+ '_not-prose' , // for nextra-theme-blog
64
+ className
65
+ ) }
113
66
{ ...props }
114
- style = {
115
- {
116
- ...style ,
117
- '--rows' : num
118
- } as CSSProperties
119
- }
67
+ style = { {
68
+ ...style ,
69
+ [ '--rows' as string ] : num
70
+ } }
120
71
>
121
72
{ children }
122
73
</ div >
0 commit comments