Skip to content

Commit 2872606

Browse files
authoredSep 13, 2024··
[v3] remove image prop from <Card> component, image will be showed based on truthiness children prop now (#3243)
* a * b * add changeset * Update packages/nextra/src/client/components/cards.tsx
1 parent b90cf47 commit 2872606

File tree

2 files changed

+37
-77
lines changed

2 files changed

+37
-77
lines changed
 

‎.changeset/little-camels-scream.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'nextra-theme-blog': major
3+
'nextra-theme-docs': major
4+
'nextra': major
5+
---
6+
7+
remove `image` prop from `<Card>` component, image will be showed based on truthiness `children` prop now
8+
9+
set `icon` as optional prop

‎packages/nextra/src/client/components/cards.tsx

+28-77
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,49 @@
11
import cn from 'clsx'
22
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'
274

285
function Card({
296
children,
307
title,
318
icon,
32-
image,
339
arrow,
3410
href,
3511
...props
3612
}: {
3713
title: string
38-
icon: ReactNode
14+
icon?: ReactElement
3915
arrow?: boolean
4016
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+
}) {
8019
return (
8120
<NextLink
8221
href={href}
8322
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'
8631
)}
8732
{...props}
8833
>
34+
{children}
8935
<span
9036
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'
9343
)}
9444
>
9545
{icon}
9646
{title}
97-
{animatedArrow}
9847
</span>
9948
</NextLink>
10049
)
@@ -109,14 +58,16 @@ function _Cards({
10958
}: { num?: number } & ComponentProps<'div'>) {
11059
return (
11160
<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+
)}
11366
{...props}
114-
style={
115-
{
116-
...style,
117-
'--rows': num
118-
} as CSSProperties
119-
}
67+
style={{
68+
...style,
69+
['--rows' as string]: num
70+
}}
12071
>
12172
{children}
12273
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.