display ChevronUp icon when openSelect is true

This commit is contained in:
Teddir 2024-07-25 07:08:37 +07:00
parent 7c1b34abdb
commit 4bd23011ff

View File

@ -1,9 +1,9 @@
'use client'; 'use client';
import { usePathname, useSearchParams } from 'next/navigation'; import { usePathname, useSearchParams } from 'next/navigation';
import { useEffect, useRef, useState } from 'react'; import { SVGProps, useEffect, useRef, useState } from 'react';
import { ChevronDownIcon } from '@heroicons/react/24/outline'; import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline';
import type { ListItem } from '.'; import type { ListItem } from '.';
import { FilterItem } from './item'; import { FilterItem } from './item';
@ -36,6 +36,9 @@ export default function FilterItemDropdown({ list }: { list: ListItem[] }) {
}); });
}, [pathname, list, searchParams]); }, [pathname, list, searchParams]);
const ChevronUpDownIcon = (props: SVGProps<SVGSVGElement>) =>
openSelect ? <ChevronUpIcon {...props} /> : <ChevronDownIcon {...props} />;
return ( return (
<div className="relative" ref={ref}> <div className="relative" ref={ref}>
<div <div
@ -45,7 +48,7 @@ export default function FilterItemDropdown({ list }: { list: ListItem[] }) {
className="flex w-full items-center justify-between rounded border border-black/30 px-4 py-2 text-sm dark:border-white/30" className="flex w-full items-center justify-between rounded border border-black/30 px-4 py-2 text-sm dark:border-white/30"
> >
<div>{active}</div> <div>{active}</div>
<ChevronDownIcon className="h-4" /> <ChevronUpDownIcon className="h-4" />
</div> </div>
{openSelect && ( {openSelect && (
<div <div