feat: native carousel
This commit is contained in:
1 parent
4ddaa89032
commit
5733bc0af0
20 files changed
+961
-534
No files matched your search
@@ -1,25 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Menu } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
NavigationMenu,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuLink,
|
||||
NavigationMenuList,
|
||||
navigationMenuTriggerStyle
|
||||
} from '@/components/ui/navigation-menu';
|
||||
Drawer,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDescription,
|
||||
DrawerHeader,
|
||||
DrawerTitle,
|
||||
DrawerTrigger
|
||||
} from '@/components/ui/drawer';
|
||||
|
||||
const paths = [
|
||||
{ path: '/popular', title: 'Popular' },
|
||||
@@ -27,54 +22,61 @@ const paths = [
|
||||
{ path: '/favorites', title: 'Favorites' }
|
||||
];
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function NavigationSmall({ className }: Props) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
export function MobileNavigation() {
|
||||
const currentPath = usePathname();
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<div className='flex xs:hidden'>
|
||||
<Drawer>
|
||||
<DrawerTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<Menu size={19} />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuRadioGroup value={currentPath}>
|
||||
</DrawerTrigger>
|
||||
<DrawerContent>
|
||||
<DrawerHeader className='pointer-events-none absolute'>
|
||||
<DrawerTitle />
|
||||
<DrawerDescription />
|
||||
</DrawerHeader>
|
||||
<ul className='flex flex-col gap-2 p-2'>
|
||||
{paths.map(({ path, title }) => (
|
||||
<Link href={path} legacyBehavior shallow key={path}>
|
||||
<DropdownMenuRadioItem value={path} onClick={() => setIsOpen(false)}>
|
||||
{title}
|
||||
</DropdownMenuRadioItem>
|
||||
</Link>
|
||||
<li key={path}>
|
||||
<DrawerClose asChild>
|
||||
<Button className='w-full relative' variant={currentPath === path ? 'default' : 'outline'}>
|
||||
<Link href={path} className='absolute flex items-center justify-center w-full h-full top-0 left-0'>
|
||||
{title}
|
||||
</Link>
|
||||
</Button>
|
||||
</DrawerClose>
|
||||
</li>
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</ul>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Navigation({ className }: Props) {
|
||||
export function DesktopNavigation() {
|
||||
const currentPath = usePathname();
|
||||
|
||||
return (
|
||||
<NavigationMenu className={className}>
|
||||
<NavigationMenuList>
|
||||
{paths.map(({ path, title }) => (
|
||||
<NavigationMenuItem key={path}>
|
||||
<Link href={path} shallow passHref legacyBehavior>
|
||||
<NavigationMenuLink active={path === currentPath} className={navigationMenuTriggerStyle()}>
|
||||
{title}
|
||||
</NavigationMenuLink>
|
||||
</Link>
|
||||
</NavigationMenuItem>
|
||||
))}
|
||||
</NavigationMenuList>
|
||||
</NavigationMenu>
|
||||
<ul className='hidden xs:flex items-center whitespace-nowrap text-sm gap-3'>
|
||||
{paths.map(({ path, title }) => (
|
||||
<li key={path} className={currentPath === path ? undefined : 'cursor-pointer'}>
|
||||
<Link href={path} shallow passHref legacyBehavior>
|
||||
<div>
|
||||
{currentPath === path ? (
|
||||
<Badge className='text-sm font-normal pointer-events-none' variant='secondary'>
|
||||
{title}
|
||||
</Badge>
|
||||
) : (
|
||||
title
|
||||
)}
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
@@ -3,23 +3,23 @@ import Link from 'next/link';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
|
||||
import Navigation, { NavigationSmall } from './components/Navigation';
|
||||
import { DesktopNavigation, MobileNavigation } from './components/Navigation';
|
||||
import ToggleSearch from './components/Search';
|
||||
import ToggleTheme from './components/ThemeToggle';
|
||||
|
||||
const Header: FC = () => (
|
||||
<header className='flex justify-center bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 sticky py-2 top-0 z-20'>
|
||||
<header className='flex justify-center bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 py-2'>
|
||||
<div className='max-w-[1252px] w-full px-2'>
|
||||
<div className='flex items-center justify-between gap-2 md:flex-nowrap'>
|
||||
<div className='flex items-center justify-between gap-2 xs:flex-nowrap'>
|
||||
<Link href='/' shallow legacyBehavior>
|
||||
<Badge className='whitespace-nowrap cursor-pointer'>Movie advisor</Badge>
|
||||
<Badge className='whitespace-nowrap cursor-pointer font-normal'>Movie advisor</Badge>
|
||||
</Link>
|
||||
<Navigation className='hidden sm:flex' />
|
||||
<DesktopNavigation />
|
||||
<div className='flex items-center gap-2'>
|
||||
<div id='actions' className='empty:hidden' />
|
||||
<ToggleTheme />
|
||||
<ToggleSearch />
|
||||
<div id='actions' className='empty:hidden' />
|
||||
<NavigationSmall className='flex sm:hidden' />
|
||||
<MobileNavigation />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+28
-29
@@ -1,19 +1,19 @@
|
||||
import { FC } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
|
||||
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Rating from '@/components/Movie/components/Rating';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
import { AspectRatio } from '@/components/ui/aspect-ratio';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
onClick?: () => void;
|
||||
fit?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
||||
const Card: FC<Props> = ({ movie, onClick, className }) => {
|
||||
const { add, remove } = useFavoritesMutation();
|
||||
const { map } = useFavorites();
|
||||
|
||||
@@ -24,38 +24,37 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
||||
const handleToggleFavorite = () => (isFavorite ? remove(movie.id) : add(movie));
|
||||
|
||||
return (
|
||||
<div
|
||||
onDoubleClick={handleToggleFavorite}
|
||||
className={cn(
|
||||
'w-[300px] h-[450px] shrink-0 mx-auto relative',
|
||||
fit ? 'xs:w-[300px] xs:h-[450px] w-full h-full aspect-w-2 aspect-h-3' : undefined
|
||||
)}
|
||||
>
|
||||
<motion.div className='absolute top-0 left-0 flex flex-col w-full h-full mx-auto bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg'>
|
||||
<motion.div onTap={onClick} className='flex w-full h-full'>
|
||||
<Poster title={movie?.name || movie.title} size={100} poster={movie.poster_path} />
|
||||
</motion.div>
|
||||
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-75 rounded-t-lg'>
|
||||
<div className='h-full w-full mx-auto pt-1 px-3 text-white'>
|
||||
<div className='grid items-center grid-cols-[1fr_50px]'>
|
||||
<div className='xs:w-[300px] xs:h-[450px] w-full h-full shrink-0'>
|
||||
<AspectRatio ratio={2 / 3}>
|
||||
<div
|
||||
onClick={onClick}
|
||||
onDoubleClick={handleToggleFavorite}
|
||||
className={cn(
|
||||
'h-full relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className='flex w-full h-full'>
|
||||
<Poster title={movie?.name || movie.title} poster={movie.poster_path} />
|
||||
</div>
|
||||
<div className='text-white absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 card-gradient'>
|
||||
<div className='grid items-center grid-cols-[1fr_50px] mt-[-5px] opacity-75'>
|
||||
<Title key={movie?.name || movie.title} title={movie?.name || movie.title} />
|
||||
{movie.release_date && (
|
||||
<span className='flex justify-end text-lg font-semibold'>
|
||||
{new Date(movie.release_date).getFullYear()}
|
||||
</span>
|
||||
<span className='flex justify-end text-lg'>{new Date(movie.release_date).getFullYear()}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className='opacity-75 mb-[-5px]'>
|
||||
<Rating
|
||||
isFavorite={isFavorite}
|
||||
toggleFavorite={handleToggleFavorite}
|
||||
rating={movie.vote_average}
|
||||
iconsFillColor='fill-white'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='absolute left-0 bottom-0 w-full bg-gradient-to-t from-black to-transparent h-20 text-white p-3 pb-2 flex flex-col justify-end opacity-75'>
|
||||
<Rating
|
||||
isFavorite={isFavorite}
|
||||
toggleFavorite={handleToggleFavorite}
|
||||
rating={movie.vote_average}
|
||||
iconsFillColor='fill-white'
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
</AspectRatio>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
+32
-44
@@ -1,5 +1,5 @@
|
||||
import { FC, Fragment, useLayoutEffect, useMemo, useState } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { FC, forwardRef, useMemo } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
import { showPreviewModal } from '@/components/Movie/Preview';
|
||||
@@ -31,6 +31,18 @@ const item = {
|
||||
}
|
||||
};
|
||||
|
||||
const components: VirtuosoGridProps<Movie, { shows: Movie[]; onClick: (movie: Movie) => void }>['components'] = {
|
||||
List: forwardRef(function List(props, ref) {
|
||||
return <div {...props} className='flex gap-3 flex-wrap justify-center grow empty:hidden' ref={ref} />;
|
||||
}),
|
||||
Item: ({ context, 'data-index': index }) => {
|
||||
const { shows, onClick } = context || {};
|
||||
const movie = shows?.[index];
|
||||
|
||||
return <Card movie={movie} onClick={() => onClick?.(movie!)} />;
|
||||
}
|
||||
};
|
||||
|
||||
const List: FC<Props> = ({
|
||||
pages,
|
||||
hasNextPage,
|
||||
@@ -39,27 +51,6 @@ const List: FC<Props> = ({
|
||||
onPreviewClose,
|
||||
type = 'movie'
|
||||
}) => {
|
||||
const [loader, setLoader] = useState<HTMLLIElement>();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!loader || !hasNextPage) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([{ isIntersecting }]) => {
|
||||
if (!isIntersecting) return;
|
||||
|
||||
fetchNextPage?.();
|
||||
},
|
||||
{
|
||||
threshold: 1
|
||||
}
|
||||
);
|
||||
|
||||
observer.observe(loader);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [fetchNextPage, loader, hasNextPage]);
|
||||
|
||||
const shows = useMemo(
|
||||
() =>
|
||||
pages?.reduce((shows, page) => {
|
||||
@@ -71,29 +62,26 @@ const List: FC<Props> = ({
|
||||
|
||||
if (!shows.length) return null;
|
||||
|
||||
const context = {
|
||||
shows,
|
||||
onClick: (movie: Movie) => showPreviewModal({ movie, onClose: onPreviewClose, type })
|
||||
};
|
||||
|
||||
const handleFetchMore = () => {
|
||||
if (!hasNextPage) return;
|
||||
fetchNextPage?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<motion.ul
|
||||
className='flex gap-3 flex-wrap justify-center grow empty:hidden'
|
||||
variants={container}
|
||||
initial={pages.length === 1 ? 'hidden' : false}
|
||||
animate='visible'
|
||||
>
|
||||
{shows?.map((movie, index, array) => {
|
||||
const isAnchor = Math.round(array.length / 2) === index;
|
||||
|
||||
return (
|
||||
<motion.li
|
||||
key={movie.id}
|
||||
variants={item}
|
||||
className='flex xs:w-auto w-full cursor-pointer'
|
||||
ref={isAnchor ? (element) => setLoader(element!) : undefined}
|
||||
>
|
||||
<Card fit movie={movie} onClick={() => showPreviewModal({ movie, onClose: onPreviewClose, type })} />
|
||||
</motion.li>
|
||||
);
|
||||
})}
|
||||
</motion.ul>
|
||||
<VirtuosoGrid
|
||||
useWindowScroll
|
||||
totalCount={shows.length}
|
||||
endReached={handleFetchMore}
|
||||
data={shows}
|
||||
context={context}
|
||||
components={components}
|
||||
/>
|
||||
{withBottomGap && <div className='h-2 w-full' />}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -13,7 +13,6 @@ import Card from '../Card';
|
||||
import Actions from './components/Actions';
|
||||
|
||||
interface Props {
|
||||
fit?: boolean;
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
onClose?: () => void;
|
||||
@@ -22,29 +21,27 @@ interface Props {
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit, type = 'movie' }) => {
|
||||
const Preview: FC<Props> = ({ movie, className, onClose, children, card, type = 'movie' }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div className={cn('rounded-xl text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-2'>
|
||||
{card || (
|
||||
<div className='xs:w-[300px] w-full shrink-0 mx-auto'>
|
||||
<Card fit={fit} movie={movie} />
|
||||
</div>
|
||||
)}
|
||||
<div className='flex flex-col md:flex-row max-w-[100%] gap-2'>
|
||||
{card || <Card className='mx-auto' movie={movie} />}
|
||||
<div className='flex flex-col grow'>
|
||||
{children && <div className='flex hover-none:hidden w-full max-sm:mb-0 mb-2 gap-2'>{children}</div>}
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions type={type} movie={movie} onClose={onClose} />
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<p key={movie.id} className='leading-7'>
|
||||
<p key={movie.id} className='leading-7 mb-3'>
|
||||
{movie.overview}
|
||||
</p>
|
||||
<div className='mt-auto grid grid-cols-1 rounded-lg'>
|
||||
<Credits type={type} movieId={movie.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Credits type={type} movieId={movie.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -52,7 +49,6 @@ const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit, ty
|
||||
export const showPreviewModal = create(({ onResolve, onClose, movie, type = 'movie' }: Props & InstanceProps<void>) => (
|
||||
<Modal className='block p-0' onClose={onResolve}>
|
||||
<Preview
|
||||
fit
|
||||
type={type}
|
||||
movie={movie}
|
||||
className='border-none'
|
||||
|
||||
@@ -37,42 +37,48 @@ const Credits: FC<Props> = ({ movieId, onPersonClick, type = 'movie' }) => {
|
||||
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
<div className='overflow-auto no-scrollbar max-w-[100%] py-2 pb-3 mb-[-0.75rem]'>
|
||||
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' whileInView='visible'>
|
||||
{credits?.map((actor) => (
|
||||
<motion.li
|
||||
variants={item}
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
onTap={() => {
|
||||
router.push(`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`);
|
||||
onPersonClick?.(actor.id.toString());
|
||||
}}
|
||||
className='p-2 rounded-lg border bg-card text-card-foreground self-end max-w-[150px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg'
|
||||
>
|
||||
{Boolean(actor.character) && (
|
||||
<p className='pb-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
||||
<motion.ul
|
||||
className='flex gap-2 no-scrollbar overflow-auto rounded-lg snap-mandatory snap-x'
|
||||
variants={container}
|
||||
initial='hidden'
|
||||
animate='visible'
|
||||
whileInView='visible'
|
||||
>
|
||||
{credits?.map((actor) => (
|
||||
<motion.li
|
||||
variants={item}
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
onTap={() => {
|
||||
router.push(`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`);
|
||||
onPersonClick?.(actor.id.toString());
|
||||
}}
|
||||
className='bg-card text-card-foreground self-end max-w-[120px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg relative snap-start'
|
||||
>
|
||||
<div className='rounded-lg overflow-hidden'>
|
||||
{actor.profile_path ? (
|
||||
<Image
|
||||
unoptimized
|
||||
height={180}
|
||||
width={120}
|
||||
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
||||
alt={actor.name}
|
||||
/>
|
||||
) : (
|
||||
<div className='h-[180px] w-[120px] flex items-center justify-center rounded-lg'>
|
||||
<User2 size={120} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
<div className='rounded-md overflow-hidden'>
|
||||
{actor.profile_path ? (
|
||||
<Image
|
||||
unoptimized
|
||||
height={225}
|
||||
width={150}
|
||||
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
||||
alt={actor.name}
|
||||
/>
|
||||
) : (
|
||||
<div className='w-[132px] h-[198px] flex items-center justify-center rounded-lg border'>
|
||||
<User2 size={120} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
</motion.li>
|
||||
))}
|
||||
</motion.ul>
|
||||
</div>
|
||||
</div>
|
||||
<div className='text-white text-sm absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 py-1 card-gradient'>
|
||||
<p className=' overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
{Boolean(actor.character) && (
|
||||
<p className='overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
||||
)}
|
||||
</div>
|
||||
</motion.li>
|
||||
))}
|
||||
</motion.ul>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,19 +4,18 @@ import { ImageOff } from 'lucide-react';
|
||||
interface Props {
|
||||
title: string;
|
||||
poster: string;
|
||||
size: number;
|
||||
}
|
||||
|
||||
const Poster: FC<Props> = ({ title, poster, size = 250 }) => {
|
||||
const Poster: FC<Props> = ({ title, poster }) => {
|
||||
return poster ? (
|
||||
<img
|
||||
className='rounded-lg w-full h-full object-fill'
|
||||
className='rounded-lg w-full h-full object-cover'
|
||||
src={`https://image.tmdb.org/t/p/w500/${poster}`}
|
||||
alt={title}
|
||||
/>
|
||||
) : (
|
||||
<div className={'w-full flex items-center justify-center rounded-lg grow'}>
|
||||
<ImageOff size={size} strokeWidth={1} color='hsl(215.4 16.3% 46.9%)' />
|
||||
<ImageOff size={100} strokeWidth={1} color='hsl(215.4 16.3% 46.9%)' />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ const Rating: FC<Props> = ({ isFavorite, rating, toggleFavorite, iconsFillColor
|
||||
</motion.span>
|
||||
<span className='flex items-center'>
|
||||
<Star size={18} className={`mr-1 ${iconsFillColor}`} />
|
||||
<span className='font-semibold'>{rating?.toFixed(1)}</span>
|
||||
<p className='mt-[3px]'>{rating?.toFixed(1)}</p>
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import * as AspectRatioPrimitive from '@radix-ui/react-aspect-ratio';
|
||||
|
||||
const AspectRatio = AspectRatioPrimitive.Root;
|
||||
|
||||
export { AspectRatio };
|
||||
@@ -154,6 +154,9 @@ const Modal: React.FC<{
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<DialogHeader>
|
||||
<DialogTitle />
|
||||
</DialogHeader>
|
||||
<DialogContent forceMount onClose={handleClose} className={className}>
|
||||
{children}
|
||||
</DialogContent>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { Drawer as DrawerPrimitive } from 'vaul';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const Drawer = ({ shouldScaleBackground = true, ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
|
||||
<DrawerPrimitive.Root shouldScaleBackground={shouldScaleBackground} {...props} />
|
||||
);
|
||||
Drawer.displayName = 'Drawer';
|
||||
|
||||
const DrawerTrigger = DrawerPrimitive.Trigger;
|
||||
|
||||
const DrawerPortal = DrawerPrimitive.Portal;
|
||||
|
||||
const DrawerClose = DrawerPrimitive.Close;
|
||||
|
||||
const DrawerOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DrawerPrimitive.Overlay ref={ref} className={cn('fixed inset-0 z-50 bg-black/80', className)} {...props} />
|
||||
));
|
||||
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
|
||||
|
||||
const DrawerContent = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DrawerPortal>
|
||||
<DrawerOverlay />
|
||||
<DrawerPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className='mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted' />
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
));
|
||||
DrawerContent.displayName = 'DrawerContent';
|
||||
|
||||
const DrawerHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)} {...props} />
|
||||
);
|
||||
DrawerHeader.displayName = 'DrawerHeader';
|
||||
|
||||
const DrawerFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('mt-auto flex flex-col gap-2 p-4', className)} {...props} />
|
||||
);
|
||||
DrawerFooter.displayName = 'DrawerFooter';
|
||||
|
||||
const DrawerTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DrawerPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn('text-lg font-semibold leading-none tracking-tight', className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
|
||||
|
||||
const DrawerDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DrawerPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
||||
));
|
||||
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDescription,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerOverlay,
|
||||
DrawerPortal,
|
||||
DrawerTitle,
|
||||
DrawerTrigger
|
||||
};
|
||||
@@ -1,120 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import * as NavigationMenuPrimitive from '@radix-ui/react-navigation-menu';
|
||||
import { cva } from 'class-variance-authority';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const NavigationMenu = React.forwardRef<
|
||||
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<NavigationMenuPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn('relative z-10 flex max-w-max flex-1 items-center justify-center', className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<NavigationMenuViewport />
|
||||
</NavigationMenuPrimitive.Root>
|
||||
));
|
||||
NavigationMenu.displayName = NavigationMenuPrimitive.Root.displayName;
|
||||
|
||||
const NavigationMenuList = React.forwardRef<
|
||||
React.ElementRef<typeof NavigationMenuPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<NavigationMenuPrimitive.List
|
||||
ref={ref}
|
||||
className={cn('group flex flex-1 list-none items-center justify-center space-x-1', className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
NavigationMenuList.displayName = NavigationMenuPrimitive.List.displayName;
|
||||
|
||||
const NavigationMenuItem = NavigationMenuPrimitive.Item;
|
||||
|
||||
const navigationMenuTriggerStyle = cva(
|
||||
'group inline-flex h-10 w-max items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/90 data-[state=open]:bg-accent/50'
|
||||
);
|
||||
|
||||
const NavigationMenuTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<NavigationMenuPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(navigationMenuTriggerStyle(), 'group', className)}
|
||||
{...props}
|
||||
>
|
||||
{children}{' '}
|
||||
<ChevronDown
|
||||
className='relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180'
|
||||
aria-hidden='true'
|
||||
/>
|
||||
</NavigationMenuPrimitive.Trigger>
|
||||
));
|
||||
NavigationMenuTrigger.displayName = NavigationMenuPrimitive.Trigger.displayName;
|
||||
|
||||
const NavigationMenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof NavigationMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<NavigationMenuPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'left-0 top-0 w-full data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 md:absolute md:w-auto ',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
NavigationMenuContent.displayName = NavigationMenuPrimitive.Content.displayName;
|
||||
|
||||
const NavigationMenuLink = NavigationMenuPrimitive.Link;
|
||||
|
||||
const NavigationMenuViewport = React.forwardRef<
|
||||
React.ElementRef<typeof NavigationMenuPrimitive.Viewport>,
|
||||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Viewport>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div className={cn('absolute left-0 top-full flex justify-center')}>
|
||||
<NavigationMenuPrimitive.Viewport
|
||||
className={cn(
|
||||
'origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 md:w-[var(--radix-navigation-menu-viewport-width)]',
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
NavigationMenuViewport.displayName = NavigationMenuPrimitive.Viewport.displayName;
|
||||
|
||||
const NavigationMenuIndicator = React.forwardRef<
|
||||
React.ElementRef<typeof NavigationMenuPrimitive.Indicator>,
|
||||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Indicator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<NavigationMenuPrimitive.Indicator
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className='relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md' />
|
||||
</NavigationMenuPrimitive.Indicator>
|
||||
));
|
||||
NavigationMenuIndicator.displayName = NavigationMenuPrimitive.Indicator.displayName;
|
||||
|
||||
export {
|
||||
NavigationMenu,
|
||||
NavigationMenuContent,
|
||||
NavigationMenuIndicator,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuLink,
|
||||
NavigationMenuList,
|
||||
NavigationMenuTrigger,
|
||||
navigationMenuTriggerStyle,
|
||||
NavigationMenuViewport
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const ScrollArea = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn('relative overflow-hidden', className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
))
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
||||
|
||||
const ScrollBar = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
>(({ className, orientation = 'vertical', ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
ref={ref}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
'flex touch-none select-none transition-colors',
|
||||
orientation === 'vertical' &&
|
||||
'h-full w-2.5 border-l border-l-transparent p-[1px]',
|
||||
orientation === 'horizontal' &&
|
||||
'h-2.5 border-t border-t-transparent p-[1px]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
))
|
||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
Reference in new issue
Block a user