Another attempt using a component property within the config

This commit is contained in:
Frank Johnson
2021-09-07 13:07:35 -04:00
parent 896baf08d1
commit 9887eb4804
4 changed files with 107 additions and 89 deletions

View File

@@ -0,0 +1,49 @@
import { Menu } from '@headlessui/react'
import { useHotkeys } from 'react-hotkeys-hook';
export function DropdownItem({ config, state, thunkDispatch }) {
console.log({ name: config.label, shortcut: config.shortcut, callback: handleClick})
useHotkeys(config.shortcut, handleClick)
function handleClick(e) {
console.log(e, config)
e.preventDefault()
config.callback(e, {state, thunkDispatch})
}
return (
<Menu.Item>
{({ active }) => (
<button
className={`${active && 'bg-gray-600'} px-2 py-1 text-left`}
onClick={handleClick}
>
{config.label}
{config.shortcutLabel && <span className="text-gray-400 pl-4">{ config.shortcutLabel }</span> }
</button>
)}
</Menu.Item>
)
}
export function Dropdown({
label,
disabled,
children,
}: {
label: string,
disabled: boolean,
children: React.ReactNode,
}) {
return (
<div className="relative">
<Menu>
<Menu.Button className={"text-gray-100" + (disabled ? " text-gray-400 cursor-not-allowed" : "")} disabled={disabled}>{label}</Menu.Button>
{ children &&
<Menu.Items className="absolute flex flex-col mt-4 bg-ch-gray-760 rounded text-gray-100 overflow-hidden whitespace-nowrap border border-ch-gray-700">
{children}
</Menu.Items>
}
</Menu>
</div>
)
}