@@ -2,6 +2,10 @@ import React from 'react';
2
2
import Link from 'next/link' ;
3
3
import TextTruncate from 'react-text-truncate' ;
4
4
import Image from 'next/image' ;
5
+ import { Card as ShadcnCard } from '@/components/ui/card' ;
6
+ import { Separator } from '@/components/ui/separator' ;
7
+ import { cn } from '@/lib/utils' ;
8
+
5
9
export interface CardProps {
6
10
title : string ;
7
11
body : string ;
@@ -20,23 +24,25 @@ const CardBody = ({
20
24
link,
21
25
image,
22
26
extended,
23
- headerSize,
24
- bodyTextSize,
27
+ headerSize = 'medium' ,
28
+ bodyTextSize = 'medium' ,
25
29
} : CardProps ) => {
26
- const headerSizeClasses : Record < string , string > = {
30
+ const headerSizeClasses = {
27
31
small : 'text-[0.9rem]' ,
28
32
medium : 'text-[1.3rem]' ,
29
33
large : 'text-[2rem]' ,
30
34
} ;
31
- const bodyTextSizeClasses : Record < string , string > = {
35
+
36
+ const bodyTextSizeClasses = {
32
37
small : 'text-[0.85rem]' ,
33
38
medium : 'text-[1rem]' ,
34
39
large : 'text-[1.5rem]' ,
35
40
} ;
41
+
36
42
return (
37
- < div className = 'group relative h-full w-full rounded-lg border border-gray-200 bg-white p-6 px-12 shadow-3xl dark:shadow-2xl dark:shadow-slate-900 transition-colors ease-in-out hover:bg-slate-100 dark:bg-slate-800 hover:dark:bg-slate-900/30' >
38
- < div className = 'flex justify-center ' >
39
- { image && (
43
+ < ShadcnCard className = 'group relative h-full w-full rounded-lg border border-gray-200 bg-white p-6 px-12 shadow-3xl dark:shadow-2xl dark:shadow-slate-900 transition-colors ease-in-out hover:bg-slate-100 dark:bg-slate-800 hover:dark:bg-slate-900/30' >
44
+ { image && (
45
+ < div className = 'flex justify-center ' >
40
46
< Image
41
47
src = { image }
42
48
alt = { title }
@@ -45,9 +51,10 @@ const CardBody = ({
45
51
className = 'h-32 p-2 object-contain'
46
52
data-test = 'card-image'
47
53
/>
48
- ) }
49
- </ div >
50
- < div className = 'flex flex-row items-start mb-6' >
54
+ </ div >
55
+ ) }
56
+
57
+ < div className = 'flex flex-row items-start ' >
51
58
{ icon && (
52
59
< span className = 'mr-6 flex h-14 w-14 flex-shrink-0 items-center justify-center rounded-lg border bg-blue-200 px-3 text-gray-900 dark:text-white' >
53
60
< Image
@@ -61,20 +68,32 @@ const CardBody = ({
61
68
</ span >
62
69
) }
63
70
< p
64
- className = { `mb-1 mt-1 items-center font-bold text-gray-900 dark:text-white ${ headerSizeClasses [ headerSize || 'medium' ] } ` }
71
+ className = { cn (
72
+ 'mb-1 mt-1 items-center font-bold text-gray-900 dark:text-white' ,
73
+ headerSizeClasses [ headerSize ] ,
74
+ ) }
65
75
data-test = 'card-title'
66
76
>
67
77
{ title }
68
78
</ p >
69
79
</ div >
70
- < hr className = 'mb-4 mt-3.5 h-px border-0 bg-gray-400' />
80
+
81
+ < Separator className = 'bg-gray-400' />
82
+
71
83
< p
72
- className = { `mb-8 text-black mt-5 dark:text-white ${ bodyTextSizeClasses [ bodyTextSize || 'medium' ] } ` }
84
+ className = { cn (
85
+ 'mb-8 text-black mt-5 dark:text-white ' ,
86
+ bodyTextSizeClasses [ bodyTextSize ] ,
87
+ ) }
73
88
data-test = 'card-body'
74
89
>
75
- { extended && < span dangerouslySetInnerHTML = { { __html : body } } /> }
76
- { ! extended && < TextTruncate element = 'span' line = { 3 } text = { body } /> }
90
+ { extended ? (
91
+ < span dangerouslySetInnerHTML = { { __html : body } } />
92
+ ) : (
93
+ < TextTruncate element = 'span' line = { 3 } text = { body } />
94
+ ) }
77
95
</ p >
96
+
78
97
{ link && (
79
98
< p
80
99
className = 'absolute bottom-3 right-5 font-medium opacity-0 transition-opacity delay-150 ease-in-out group-hover:opacity-100 text-black dark:text-white'
@@ -83,52 +102,17 @@ const CardBody = ({
83
102
Read More
84
103
</ p >
85
104
) }
86
- </ div >
105
+ </ ShadcnCard >
87
106
) ;
88
107
} ;
89
108
90
- const Card : React . FC < CardProps > = ( {
91
- title,
92
- body,
93
- icon,
94
- link,
95
- image,
96
- extended,
97
- headerSize,
98
- bodyTextSize,
99
- } ) => {
100
- return (
101
- < >
102
- { link ? (
103
- < Link href = { link } data-test = 'card-link' >
104
- < CardBody
105
- { ...{
106
- title,
107
- body,
108
- icon,
109
- link,
110
- image,
111
- extended,
112
- headerSize,
113
- bodyTextSize,
114
- } }
115
- />
116
- </ Link >
117
- ) : (
118
- < CardBody
119
- { ...{
120
- title,
121
- body,
122
- icon,
123
- link,
124
- image,
125
- extended,
126
- headerSize,
127
- bodyTextSize,
128
- } }
129
- />
130
- ) }
131
- </ >
109
+ const Card : React . FC < CardProps > = ( { link, ...props } ) => {
110
+ return link ? (
111
+ < Link href = { link } data-test = 'card-link' >
112
+ < CardBody link = { link } { ...props } />
113
+ </ Link >
114
+ ) : (
115
+ < CardBody { ...props } />
132
116
) ;
133
117
} ;
134
118
0 commit comments