-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a45e4f
commit 935a0e1
Showing
4 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.arrow { | ||
transition: transform 0.3s ease-in-out; | ||
transform: rotate(90deg); | ||
} | ||
|
||
.arrowOpen { | ||
transform: rotate(270deg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
Disclosure as DisclosureComponent, | ||
Transition, | ||
} from '@headlessui/react'; | ||
|
||
import ArrowRightLight from '@media/UI/arrow-right-light.svg'; | ||
import ArrowRightDark from '@media/UI/arrow-right-dark.svg'; | ||
import React, { Fragment, useContext } from 'react'; | ||
import ThemeContext from '@context/ThemeContext'; | ||
|
||
import classes from './Disclosure.module.scss'; | ||
|
||
interface DisclosureProps { | ||
title: string; | ||
children: React.ReactNode; | ||
defaultOpen?: boolean; | ||
buttonClassName?: string; | ||
conentClassName?: string; | ||
} | ||
|
||
export default function Disclosure({ | ||
title, | ||
children, | ||
defaultOpen, | ||
buttonClassName, | ||
conentClassName, | ||
}: DisclosureProps) { | ||
const { theme } = useContext(ThemeContext); | ||
|
||
const getArrowClasses = (open: boolean) => | ||
`absolute right-4 top-5 ${classes.arrow} ${open ? classes.arrowOpen : ''}`; | ||
|
||
return ( | ||
<DisclosureComponent defaultOpen={defaultOpen}> | ||
{({ open }) => ( | ||
<> | ||
<DisclosureComponent.Button | ||
className={`flex relative w-full justify-between py-2 text-left text-sm font-medium bg-color-shade-white-night dark:bg-color-shade-dark-1-night text-color-accents-purple-black dark:text-color-accents-grey-lavendar text-base py-3 px-8 dark:text-color-shade-light-2-night bg-none text-color-shade-light-3-night rounded ${buttonClassName}`} | ||
> | ||
<span>{title}</span> | ||
{theme === 'light' ? ( | ||
<ArrowRightLight className={getArrowClasses(open)} /> | ||
) : ( | ||
<ArrowRightDark className={getArrowClasses(open)} /> | ||
)} | ||
</DisclosureComponent.Button> | ||
<div className="overflow-hidden"> | ||
<Transition | ||
as={Fragment} | ||
enter="transition ease-in-out duration-300 transform" | ||
enterFrom="-translate-y-full" | ||
enterTo="translate-y-0" | ||
leave="transition ease-in-out duration-300 transform" | ||
leaveFrom="translate-y-0" | ||
leaveTo="-translate-y-full" | ||
> | ||
<DisclosureComponent.Panel | ||
className={`px-4 pt-4 pb-2 text-sm text-gray-500 ${conentClassName}`} | ||
> | ||
{children} | ||
</DisclosureComponent.Panel> | ||
</Transition> | ||
</div> | ||
</> | ||
)} | ||
</DisclosureComponent> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters