Skip to content

Commit d585a99

Browse files
authored
Migrate NavigationButton, DocsHelp, and Card components to ShadCN (#1727)
* imlement shadcn in NavigationButtons * create test file for navigation button * adapt DocHelp to shadcn * adapting card component to shadcn * add 2 tests for the card test file * format adjustments * fixing test format * adding proptype for the shadcn elemnts * adjusting the card test for better structer * adjusting the colors and hover effects for dark mode * adjust configuration
1 parent 35f8a3e commit d585a99

File tree

9 files changed

+599
-293
lines changed

9 files changed

+599
-293
lines changed

components/Card.tsx

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import React from 'react';
22
import Link from 'next/link';
33
import TextTruncate from 'react-text-truncate';
44
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+
59
export interface CardProps {
610
title: string;
711
body: string;
@@ -20,23 +24,25 @@ const CardBody = ({
2024
link,
2125
image,
2226
extended,
23-
headerSize,
24-
bodyTextSize,
27+
headerSize = 'medium',
28+
bodyTextSize = 'medium',
2529
}: CardProps) => {
26-
const headerSizeClasses: Record<string, string> = {
30+
const headerSizeClasses = {
2731
small: 'text-[0.9rem]',
2832
medium: 'text-[1.3rem]',
2933
large: 'text-[2rem]',
3034
};
31-
const bodyTextSizeClasses: Record<string, string> = {
35+
36+
const bodyTextSizeClasses = {
3237
small: 'text-[0.85rem]',
3338
medium: 'text-[1rem]',
3439
large: 'text-[1.5rem]',
3540
};
41+
3642
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 '>
4046
<Image
4147
src={image}
4248
alt={title}
@@ -45,9 +51,10 @@ const CardBody = ({
4551
className='h-32 p-2 object-contain'
4652
data-test='card-image'
4753
/>
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 '>
5158
{icon && (
5259
<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'>
5360
<Image
@@ -61,20 +68,32 @@ const CardBody = ({
6168
</span>
6269
)}
6370
<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+
)}
6575
data-test='card-title'
6676
>
6777
{title}
6878
</p>
6979
</div>
70-
<hr className='mb-4 mt-3.5 h-px border-0 bg-gray-400' />
80+
81+
<Separator className='bg-gray-400' />
82+
7183
<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+
)}
7388
data-test='card-body'
7489
>
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+
)}
7795
</p>
96+
7897
{link && (
7998
<p
8099
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 = ({
83102
Read More
84103
</p>
85104
)}
86-
</div>
105+
</ShadcnCard>
87106
);
88107
};
89108

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} />
132116
);
133117
};
134118

0 commit comments

Comments
 (0)