-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: further build out resuable components
- Loading branch information
1 parent
39f317c
commit db7c249
Showing
3 changed files
with
88 additions
and
70 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 |
---|---|---|
@@ -1,26 +1,40 @@ | ||
// 'use client'; | ||
import React from 'react'; | ||
import { BsFillCaretDownFill } from 'react-icons/bs'; | ||
|
||
interface IDropdown { | ||
value: string; | ||
items: string[]; | ||
action: () => void; | ||
action: (item: string) => void; | ||
} | ||
|
||
export const Dropdown = ({ value, items, action }: IDropdown) => ( | ||
<div className='dropdown'> | ||
<div tabIndex={0} role='button' className='btn btn-ghost rounded-btn'> | ||
{value} <BsFillCaretDownFill /> | ||
export const Dropdown = ({ value, items, action }: IDropdown) => { | ||
const handleClick = (item: string) => { | ||
action(item); | ||
|
||
const activeEl = document.activeElement as HTMLElement; | ||
activeEl && activeEl.blur(); | ||
}; | ||
|
||
return ( | ||
<div className='dropdown' data-cy='dropdown'> | ||
<div | ||
tabIndex={0} | ||
role='button' | ||
className='btn btn-ghost btn-sm rounded-btn underline' | ||
> | ||
{value} <BsFillCaretDownFill /> | ||
</div> | ||
<ul | ||
tabIndex={0} | ||
className='menu dropdown-content z-[1] mt-2 max-h-64 w-52 flex-nowrap overflow-scroll rounded-box bg-base-100 p-2 shadow lg:max-h-96' | ||
> | ||
{items.map((item) => ( | ||
<li key={item} data-cy='dropdown-item'> | ||
<a onClick={() => handleClick(item)}>{item}</a> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
<ul | ||
tabIndex={0} | ||
className='menu dropdown-content z-[1] mt-4 max-h-96 w-52 flex-nowrap overflow-scroll rounded-box bg-base-100 p-2 shadow' | ||
> | ||
{items.map((item) => ( | ||
<li key={item}> | ||
<a onClick={action}>{item}</a> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
); | ||
}; |
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