Skip to content

Commit 5b7a4a1

Browse files
committed
imlement shadcn in NavigationButtons
1 parent 1ac0817 commit 5b7a4a1

File tree

1 file changed

+53
-57
lines changed

1 file changed

+53
-57
lines changed

components/NavigationButtons.tsx

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import Image from 'next/image';
1+
/* eslint-disable linebreak-style */
22
import React from 'react';
33
import Link from 'next/link';
4+
import { ChevronLeft, ChevronRight } from 'lucide-react';
5+
import { Card } from '@/components/ui/card';
6+
import { Button } from '@/components/ui/button';
47

58
/*
69
To use this component:
@@ -26,68 +29,61 @@ import NextPrevButton from '~/components/NextPrevButton';
2629
<NextPrevButton prevLabel={frontmatter.prev.label} prevURL={frontmatter.prev.url} nextLabel={frontmatter.next.label} nextURL={frontmatter.next.url} />
2730
*/
2831

29-
export default function NextPrevButton({
32+
interface NavigationButtonsProps {
33+
prevLabel?: string;
34+
prevURL?: string;
35+
nextLabel?: string;
36+
nextURL?: string;
37+
}
38+
39+
const NavButton = ({
40+
label,
41+
url,
42+
direction,
43+
}: {
44+
label?: string;
45+
url?: string;
46+
direction: 'prev' | 'next';
47+
}) => {
48+
if (!url || !label) return <div className='h-auto w-1/2' />;
49+
50+
const isPrev = direction === 'prev';
51+
const Icon = isPrev ? ChevronLeft : ChevronRight;
52+
const buttonText = isPrev ? 'Go Back' : 'Up Next';
53+
54+
return (
55+
<div className='h-auto w-1/2'>
56+
<Card className='h-full cursor-pointer border-gray-200 p-4 text-center shadow-md transition-all duration-300 ease-in-out hover:border-gray-300 hover:shadow-lg dark:shadow-xl dark:hover:shadow-lg dark:drop-shadow-lg lg:text-left'>
57+
<Link href={url} className='block'>
58+
<Button
59+
variant='ghost'
60+
className={`w-full gap-5 p-0 text-[18px] hover:bg-transparent ${isPrev ? 'justify-start' : 'justify-end'}`}
61+
>
62+
{isPrev && <Icon className='h-5 w-5' />}
63+
<div className='my-auto inline font-bold uppercase text-primary dark:text-slate-300'>
64+
{buttonText}
65+
</div>
66+
{!isPrev && <Icon className='h-5 w-5' />}
67+
</Button>
68+
<div className='my-2 text-base font-medium text-slate-600 dark:text-slate-300'>
69+
{label}
70+
</div>
71+
</Link>
72+
</Card>
73+
</div>
74+
);
75+
};
76+
77+
export default function NavigationButtons({
3078
prevLabel,
3179
prevURL,
3280
nextLabel,
3381
nextURL,
34-
}: any) {
82+
}: NavigationButtonsProps) {
3583
return (
3684
<div className='mb-4 flex flex-row gap-4'>
37-
{prevURL && prevLabel ? (
38-
<div className='h-auto w-1/2'>
39-
<div
40-
className='cursor-pointer rounded border border-gray-200 p-4 text-center shadow-md transition-all duration-300 ease-in-out hover:border-gray-300 hover:shadow-lg dark:shadow-xl dark:hover:shadow-2xl dark:drop-shadow-lg
41-
lg:text-left'
42-
>
43-
<Link href={prevURL}>
44-
<div className='text-primary dark:text-slate-300 flex flex-row gap-5 text-[18px]'>
45-
<Image
46-
src={'/icons/arrow.svg'}
47-
height={10}
48-
width={10}
49-
alt='prev icon'
50-
className='rotate-180 w-5 '
51-
/>
52-
<div className='my-auto inline font-bold uppercase'>
53-
Go Back
54-
</div>
55-
</div>
56-
<div className='my-2 text-base font-medium text-slate-600 dark:text-slate-300'>
57-
{prevLabel}
58-
</div>
59-
</Link>
60-
</div>
61-
</div>
62-
) : (
63-
<div className='h-auto w-1/2'></div>
64-
)}
65-
66-
{nextURL && nextLabel ? (
67-
<div className='h-auto w-1/2'>
68-
<div className='h-full cursor-pointer rounded border border-gray-200 p-4 text-center shadow-md transition-all duration-300 ease-in-out hover:border-gray-300 hover:shadow-lg dark:shadow-xl dark:drop-shadow-lg dark:hover:shadow-2xl lg:text-right'>
69-
<Link href={nextURL}>
70-
<div className='text-primary dark:text-slate-300 flex flex-row-reverse gap-5 text-[18px]'>
71-
<Image
72-
src={'/icons/arrow.svg'}
73-
height={10}
74-
width={10}
75-
alt='next icon '
76-
className='w-5'
77-
/>
78-
<div className='my-auto inline font-bold uppercase '>
79-
Up Next
80-
</div>
81-
</div>
82-
<div className='my-2 text-base font-medium text-slate-600 dark:text-slate-300'>
83-
{nextLabel}
84-
</div>
85-
</Link>
86-
</div>
87-
</div>
88-
) : (
89-
<div className='h-auto w-1/2'></div>
90-
)}
85+
<NavButton label={prevLabel} url={prevURL} direction='prev' />
86+
<NavButton label={nextLabel} url={nextURL} direction='next' />
9187
</div>
9288
);
9389
}

0 commit comments

Comments
 (0)