Skip to content

Commit 4f081ac

Browse files
authored
Migrate Tag, Badge, and Remember Components to ShadCN and Add Tests (#1689)
* create test files for Badge and Tag * adapting tag,badge and remember * format adjutments * tests adjutments for better format * fixing according to github action requirments * adjusting test coverege problem * fixing prop type bug * installing prop types for the use of shadcn card element * Revert "installing prop types for the use of shadcn card element" This reverts commit 467628e. * adding card test file for full test coverage
1 parent 717d30c commit 4f081ac

File tree

11 files changed

+465
-88
lines changed

11 files changed

+465
-88
lines changed

components/Remember.tsx

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,106 @@
11
import React from 'react';
2+
import { Card, CardHeader, CardContent, CardTitle } from '@/components/ui/card';
3+
const linkProps = { className: 'underline', rel: 'noreferrer' };
24

3-
export const Remember = () => {
4-
return (
5-
<div className='flex mt-7 flex-col rounded-md shadow-md border border-gray-200 p-4 mt-2'>
6-
<h3
7-
className='flex text-h5mobile md:text-h5 font-semibold border-b pb-3'
5+
export const Remember = () => (
6+
<Card className='mt-7'>
7+
<CardHeader className='flex flex-row items-center space-x-3 pb-3 border-b'>
8+
<svg
9+
xmlns='http://www.w3.org/2000/svg'
10+
width='32'
11+
height='32'
12+
fill='currentColor'
13+
className='bi bi-info-circle-fill'
14+
viewBox='0 0 16 16'
15+
>
16+
<path d='M2 6a6 6 0 1 1 10.174 4.31c-.203.196-.359.4-.453.619l-.762 1.769A.5.5 0 0 1 10.5 13a.5.5 0 0 1 0 1 .5.5 0 0 1 0 1l-.224.447a1 1 0 0 1-.894.553H6.618a1 1 0 0 1-.894-.553L5.5 15a.5.5 0 0 1 0-1 .5.5 0 0 1 0-1 .5.5 0 0 1-.46-.302l-.761-1.77a1.964 1.964 0 0 0-.453-.618A5.984 5.984 0 0 1 2 6zm6-5a5 5 0 0 0-3.479 8.592c.263.254.514.564.676.941L5.83 12h4.342l.632-1.467c.162-.377.413-.687.676-.941A5 5 0 0 0 8 1z' />
17+
</svg>
18+
<CardTitle
19+
className='text-h5mobile md:text-h5'
820
data-test='remember-heading'
921
>
10-
<svg
11-
xmlns='http://www.w3.org/2000/svg'
12-
width='32'
13-
height='32'
14-
fill='currentColor'
15-
className='bi bi-info-circle-fill mr-3'
16-
viewBox='0 0 16 16'
17-
>
18-
<path d='M2 6a6 6 0 1 1 10.174 4.31c-.203.196-.359.4-.453.619l-.762 1.769A.5.5 0 0 1 10.5 13a.5.5 0 0 1 0 1 .5.5 0 0 1 0 1l-.224.447a1 1 0 0 1-.894.553H6.618a1 1 0 0 1-.894-.553L5.5 15a.5.5 0 0 1 0-1 .5.5 0 0 1 0-1 .5.5 0 0 1-.46-.302l-.761-1.77a1.964 1.964 0 0 0-.453-.618A5.984 5.984 0 0 1 2 6zm6-5a5 5 0 0 0-3.479 8.592c.263.254.514.564.676.941L5.83 12h4.342l.632-1.467c.162-.377.413-.687.676-.941A5 5 0 0 0 8 1z' />
19-
</svg>{' '}
2022
Remember
21-
</h3>
22-
<span
23-
className='inline-block mt-2 ml-2 font-medium antialiased font-semibold'
24-
data-test='contribute-docs-span'
25-
>
26-
Contribute to the JSON Schema Docs
27-
</span>
28-
<div className='mt-2 mb-2' data-test='contribute-docs-div'>
29-
Code isn't the only way to contribute to OSS; Docs are extremely import
30-
for the JSON Schema Ecosystem. At JSON Schema, We value Docs
31-
contributions as much as every other type of contribution!
23+
</CardTitle>
24+
</CardHeader>
25+
<CardContent className='space-y-6'>
26+
<div className='space-y-2'>
27+
<span
28+
className='antialiased font-semibold'
29+
data-test='contribute-docs-span'
30+
>
31+
Contribute to the JSON Schema Docs
32+
</span>
33+
<p data-test='contribute-docs-div'>
34+
Code isn't the only way to contribute to OSS; Docs are extremely
35+
import for the JSON Schema Ecosystem. At JSON Schema, We value Docs
36+
contributions as much as every other type of contribution!
37+
</p>
3238
</div>
33-
<span
34-
className='inline-block mt-3 ml-2 font-medium antialiased font-semibold'
35-
data-test='get-started-span'
36-
>
37-
To get started as a Docs contributor:
38-
</span>
39-
<div className='mt-2 mb-2'>
40-
<ol className='list-decimal mt-2 mb-4 ml-5'>
41-
<li className='mt-1 leading-7'>
39+
40+
<div className='space-y-2'>
41+
<span
42+
className='antialiased font-semibold'
43+
data-test='get-started-span'
44+
>
45+
To get started as a Docs contributor:
46+
</span>
47+
<ol className='list-decimal ml-5 space-y-2'>
48+
<li className='leading-7'>
4249
Familiarize yourself with our project's{' '}
4350
<a
44-
className='underline'
45-
rel='noreferrer'
51+
{...linkProps}
4652
href='https://github.com/json-schema-org/community/blob/main/CONTRIBUTING.md'
4753
>
4854
Contribution Guide
4955
</a>{' '}
5056
and our{' '}
5157
<a
52-
className='underline'
53-
rel='noreferrer'
58+
{...linkProps}
5459
href='https://github.com/json-schema-org/.github/blob/main/CODE_OF_CONDUCT.md'
5560
>
5661
Code of Conduct
5762
</a>
5863
.
5964
</li>
60-
<li className='mt-1 leading-7'>
65+
<li className='leading-7'>
6166
Head over to our{' '}
6267
<a
63-
className='underline'
64-
rel='noreferrer'
68+
{...linkProps}
6569
href='https://github.com/orgs/json-schema-org/projects/16'
6670
>
6771
JSON Schema Docs Board
6872
</a>
6973
.
7074
</li>
71-
<li className='mt-1 leading-7'>
75+
<li className='leading-7'>
7276
Pick an issue you would like to contribute to and leave a comment
7377
introducing yourself. This is also the perfect place to leave any
7478
questions you may have on how to get started.
7579
</li>
76-
<li className='mt-1 leading-7'>
80+
<li className='leading-7'>
7781
If there is no work done in that Docs issue yet, feel free to open a
7882
PR and get started!
7983
</li>
8084
</ol>
8185
</div>
82-
<span
83-
className='inline-block ml-2 font-medium antialiased font-semibold'
84-
data-test='contribute-docs-questions-span'
85-
>
86-
Docs contributor questions?
87-
</span>
88-
<div className='mt-2 mb-2' data-test='contribute-docs-questions-div'>
89-
Do you have a documentation contributor question? Please leave a comment
90-
in the issue or PR or join the <code>#contribute</code> or{' '}
91-
<code>#documentation</code> channels on{' '}
92-
<a
93-
className='underline'
94-
rel='noreferrer'
95-
href='https://json-schema.org/slack'
86+
87+
<div className='space-y-2'>
88+
<span
89+
className='antialiased font-semibold'
90+
data-test='contribute-docs-questions-span'
9691
>
97-
Slack
98-
</a>{' '}
99-
and leave a message.
92+
Docs contributor questions?
93+
</span>
94+
<p data-test='contribute-docs-questions-div'>
95+
Do you have a documentation contributor question? Please leave a
96+
comment in the issue or PR or join the <code>#contribute</code> or{' '}
97+
<code>#documentation</code> channels on{' '}
98+
<a {...linkProps} href='https://json-schema.org/slack'>
99+
Slack
100+
</a>{' '}
101+
and leave a message.
102+
</p>
100103
</div>
101-
</div>
102-
);
103-
};
104+
</CardContent>
105+
</Card>
106+
);

components/ui/badge.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable linebreak-style */
2+
import * as React from 'react';
3+
import { Slot } from '@radix-ui/react-slot';
4+
import { cva, type VariantProps } from 'class-variance-authority';
5+
6+
import { cn } from '@/lib/utils';
7+
8+
const badgeVariants = cva(
9+
'inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden',
10+
{
11+
variants: {
12+
variant: {
13+
default:
14+
'border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90',
15+
secondary:
16+
'border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90',
17+
destructive:
18+
'border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60',
19+
outline:
20+
'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground',
21+
},
22+
},
23+
defaultVariants: {
24+
variant: 'default',
25+
},
26+
},
27+
);
28+
29+
function Badge({
30+
className,
31+
variant,
32+
asChild = false,
33+
...props
34+
}: React.ComponentProps<'span'> &
35+
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
36+
const Comp = asChild ? Slot : 'span';
37+
38+
return (
39+
<Comp
40+
data-slot='badge'
41+
className={cn(badgeVariants({ variant }), className)}
42+
{...props}
43+
/>
44+
);
45+
}
46+
47+
export { Badge, badgeVariants };

components/ui/card.tsx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/* eslint-disable linebreak-style */
2+
/* eslint-disable react/prop-types */
3+
import * as React from 'react';
4+
import PropTypes from 'prop-types';
5+
6+
import { cn } from '@/lib/utils';
7+
8+
interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
9+
className?: string;
10+
}
11+
12+
function Card({ className, ...props }: CardProps) {
13+
return (
14+
<div
15+
data-slot='card'
16+
className={cn(
17+
'bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm',
18+
className,
19+
)}
20+
{...props}
21+
/>
22+
);
23+
}
24+
25+
Card.propTypes = {
26+
className: PropTypes.string,
27+
};
28+
29+
interface CardHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
30+
className?: string;
31+
}
32+
33+
function CardHeader({ className, ...props }: CardHeaderProps) {
34+
return (
35+
<div
36+
data-slot='card-header'
37+
className={cn(
38+
'@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6',
39+
className,
40+
)}
41+
{...props}
42+
/>
43+
);
44+
}
45+
46+
CardHeader.propTypes = {
47+
className: PropTypes.string,
48+
};
49+
50+
interface CardTitleProps extends React.HTMLAttributes<HTMLDivElement> {
51+
className?: string;
52+
}
53+
54+
function CardTitle({ className, ...props }: CardTitleProps) {
55+
return (
56+
<div
57+
data-slot='card-title'
58+
className={cn('leading-none font-semibold', className)}
59+
{...props}
60+
/>
61+
);
62+
}
63+
64+
CardTitle.propTypes = {
65+
className: PropTypes.string,
66+
};
67+
68+
interface CardDescriptionProps extends React.HTMLAttributes<HTMLDivElement> {
69+
className?: string;
70+
}
71+
72+
function CardDescription({ className, ...props }: CardDescriptionProps) {
73+
return (
74+
<div
75+
data-slot='card-description'
76+
className={cn('text-muted-foreground text-sm', className)}
77+
{...props}
78+
/>
79+
);
80+
}
81+
82+
CardDescription.propTypes = {
83+
className: PropTypes.string,
84+
};
85+
86+
interface CardActionProps extends React.HTMLAttributes<HTMLDivElement> {
87+
className?: string;
88+
}
89+
90+
function CardAction({ className, ...props }: CardActionProps) {
91+
return (
92+
<div
93+
data-slot='card-action'
94+
className={cn(
95+
'col-start-2 row-span-2 row-start-1 self-start justify-self-end',
96+
className,
97+
)}
98+
{...props}
99+
/>
100+
);
101+
}
102+
103+
CardAction.propTypes = {
104+
className: PropTypes.string,
105+
};
106+
107+
interface CardContentProps extends React.HTMLAttributes<HTMLDivElement> {
108+
className?: string;
109+
}
110+
111+
function CardContent({ className, ...props }: CardContentProps) {
112+
return (
113+
<div
114+
data-slot='card-content'
115+
className={cn('px-6', className)}
116+
{...props}
117+
/>
118+
);
119+
}
120+
121+
CardContent.propTypes = {
122+
className: PropTypes.string,
123+
};
124+
125+
interface CardFooterProps extends React.HTMLAttributes<HTMLDivElement> {
126+
className?: string;
127+
}
128+
129+
function CardFooter({ className, ...props }: CardFooterProps) {
130+
return (
131+
<div
132+
data-slot='card-footer'
133+
className={cn('flex items-center px-6 [.border-t]:pt-6', className)}
134+
{...props}
135+
/>
136+
);
137+
}
138+
139+
CardFooter.propTypes = {
140+
className: PropTypes.string,
141+
};
142+
143+
export {
144+
Card,
145+
CardHeader,
146+
CardFooter,
147+
CardTitle,
148+
CardAction,
149+
CardDescription,
150+
CardContent,
151+
};

0 commit comments

Comments
 (0)