Skip to content

Commit 9e5de7d

Browse files
committed
Fixed the card image and header layout, added a new headersize
1 parent 2c94143 commit 9e5de7d

File tree

3 files changed

+57
-43
lines changed

3 files changed

+57
-43
lines changed

components/Card.tsx

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Image from 'next/image';
55
import { Card as ShadcnCard } from '@/components/ui/card';
66
import { Separator } from '@/components/ui/separator';
77
import { cn } from '@/lib/utils';
8+
import { LucideArrowDownRight } from 'lucide-react';
89

910
export interface CardProps {
1011
title: string;
@@ -13,7 +14,7 @@ export interface CardProps {
1314
link?: string;
1415
image?: string;
1516
extended?: boolean;
16-
headerSize?: 'small' | 'medium' | 'large';
17+
headerSize?: 'small' | 'base' | 'medium' | 'large';
1718
bodyTextSize?: 'small' | 'medium' | 'large';
1819
}
1920

@@ -29,7 +30,8 @@ const CardBody = ({
2930
}: CardProps) => {
3031
const headerSizeClasses = {
3132
small: 'text-[0.9rem]',
32-
medium: 'text-[1.3rem]',
33+
base: 'text-[1rem]',
34+
medium: 'text-[1.2rem]',
3335
large: 'text-[2rem]',
3436
};
3537

@@ -54,28 +56,32 @@ const CardBody = ({
5456
</div>
5557
)}
5658

57-
<div className='flex flex-row items-start '>
58-
{icon && (
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'>
60-
<Image
61-
src={icon}
62-
alt={title}
63-
width={56}
64-
height={56}
65-
className='h-full w-full'
66-
data-test='card-icon'
67-
/>
68-
</span>
69-
)}
70-
<p
71-
className={cn(
72-
'mb-1 mt-1 items-center font-bold text-gray-900 dark:text-white',
73-
headerSizeClasses[headerSize],
59+
<div className='flex flex-row items-start'>
60+
<div className='flex flex-col h-full w-fit items-center justify-center'>
61+
{icon && (
62+
<span className='mr-6 flex size-[52px] flex-shrink-0 items-center justify-center rounded-lg border bg-blue-200 px-3 text-gray-900 dark:text-white'>
63+
<Image
64+
src={icon}
65+
alt={title}
66+
width={56}
67+
height={56}
68+
className='h-full w-full'
69+
data-test='card-icon'
70+
/>
71+
</span>
7472
)}
75-
data-test='card-title'
76-
>
77-
{title}
78-
</p>
73+
</div>
74+
<div className='flex flex-col h-full w-fit items-center justify-center'>
75+
<p
76+
className={cn(
77+
'flex items-center my-1 font-bold text-gray-900 dark:text-white',
78+
headerSizeClasses[headerSize],
79+
)}
80+
data-test='card-title'
81+
>
82+
{title}
83+
</p>
84+
</div>
7985
</div>
8086

8187
<Separator className='bg-gray-400' />
@@ -96,10 +102,11 @@ const CardBody = ({
96102

97103
{link && (
98104
<p
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'
105+
className='absolute flex bottom-3 right-5 font-medium opacity-0 transition-opacity delay-100 ease-in-out group-hover:opacity-100 text-black dark:text-white'
100106
data-test='card-read-more'
101107
>
102-
Read More
108+
Read More{' '}
109+
<LucideArrowDownRight className='ml-2 group-hover:-rotate-90 duration-500' />
103110
</p>
104111
)}
105112
</ShadcnCard>
@@ -108,8 +115,10 @@ const CardBody = ({
108115

109116
const Card: React.FC<CardProps> = ({ link, ...props }) => {
110117
return link ? (
111-
<Link href={link} data-test='card-link'>
112-
<CardBody link={link} {...props} />
118+
<Link href={link} passHref legacyBehavior>
119+
<a data-test='card-link'>
120+
<CardBody link={link} {...props} />
121+
</a>
113122
</Link>
114123
) : (
115124
<CardBody {...props} />

cypress/components/Card.cy.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ describe('Card Component', () => {
1717
it('should render Roadmap Card correctly', () => {
1818
cy.mount(<Card {...RoadmapProps} />);
1919
cy.get('[data-test="card-image"]').should('not.exist');
20-
cy.get('[data-test="card-icon"]').should(
21-
'have.attr',
22-
'src',
23-
RoadmapProps.icon,
24-
);
20+
cy.get('[data-test="card-icon"]')
21+
.should('have.attr', 'src')
22+
.and('include', RoadmapProps.icon);
2523
cy.get('[data-test="card-title"]').should('have.text', RoadmapProps.title);
2624
cy.get('[data-test="card-body"]').should('have.text', RoadmapProps.body);
27-
cy.get('[data-test="card-read-more"]').should('have.text', 'Read More');
25+
cy.get('[data-test="card-read-more"]').should('contain.text', 'Read More');
2826
cy.get('[data-test="card-link"]').should(
2927
'have.attr',
3028
'href',
@@ -42,10 +40,19 @@ describe('Card Component', () => {
4240
bodyTextSize: undefined,
4341
};
4442
cy.mount(<Card {...missingSizes} />);
45-
cy.get('[data-test="card-title"]').should('have.class', 'text-[1.3rem]');
43+
cy.get('[data-test="card-title"]').should('have.class', 'text-[1.2rem]');
4644
cy.get('[data-test="card-body"]').should('have.class', 'text-[1rem]');
4745
});
4846

47+
it('should render Roadmap card with base header size', () => {
48+
const baseHeaderProps: CardProps = {
49+
...RoadmapProps,
50+
headerSize: 'base',
51+
};
52+
cy.mount(<Card {...baseHeaderProps} />);
53+
cy.get('[data-test="card-title"]').should('have.class', 'text-[1rem]');
54+
});
55+
4956
// Render the Roadmap card with extended body text
5057
it('should render Roadmap card with extended body text', () => {
5158
const extendedBody = { ...RoadmapProps, extended: true };
@@ -57,11 +64,9 @@ describe('Card Component', () => {
5764
it('should render Roadmap card with image', () => {
5865
const imageProps = { ...RoadmapProps, image: '/icons/roadmap.svg' };
5966
cy.mount(<Card {...imageProps} />);
60-
cy.get('[data-test="card-image"]').should(
61-
'have.attr',
62-
'src',
63-
imageProps.image,
64-
);
67+
cy.get('[data-test="card-image"]')
68+
.should('have.attr', 'src')
69+
.and('include', imageProps.image);
6570
});
6671

6772
// Render the Roadmap Card with some missing props
@@ -76,7 +81,7 @@ describe('Card Component', () => {
7681
it('should show "Read More" text when link is provided', () => {
7782
cy.mount(<Card {...RoadmapProps} />);
7883
cy.get('[data-test="card-read-more"]').should('exist');
79-
cy.get('[data-test="card-read-more"]').should('have.text', 'Read More');
84+
cy.get('[data-test="card-read-more"]').should('contain.text', 'Read More');
8085
});
8186

8287
// Test different text size combinations

pages/implementers/index.page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export default function ContentExample({
2929
<SectionContext.Provider value='docs'>
3030
<StyledMarkdown markdown={blocks[0]} />
3131
<section className='my-10'>
32-
<div className='grid grid-cols-1 md:grid-cols-2 gap-4 w-12/12 md:w-11/12 lg:w-10/12 xl:w-10/12 m-auto'>
32+
<div className='grid grid-cols-1 md:grid-cols-2 gap-4 w-12/12 md:w-11/12 lg:w-10/12 mx-auto'>
3333
<Card
3434
key='common-interfaces'
3535
icon='/icons/list.svg'
3636
title='Understand common interfaces'
3737
body='Build interoperable JSON Schema tools using shared interfaces.'
38-
headerSize='small'
38+
headerSize='base'
3939
bodyTextSize='small'
4040
link='./implementers/interfaces'
4141
/>
@@ -44,7 +44,7 @@ export default function ContentExample({
4444
icon='/img/logos/bowtie.svg'
4545
title='Validate with Bowtie'
4646
body='Validate your JSON Schema tools with the Bowtie meta-validator.'
47-
headerSize='medium'
47+
headerSize='base'
4848
bodyTextSize='small'
4949
link='https://docs.bowtie.report/en/stable/'
5050
/>

0 commit comments

Comments
 (0)