frigate/web/src/components/Menu.jsx

49 lines
1.4 KiB
React
Raw Normal View History

2021-02-02 07:28:25 +03:00
import { h } from 'preact';
import RelativeModal from './RelativeModal';
import { useCallback } from 'preact/hooks';
2021-02-02 07:28:25 +03:00
2021-02-07 07:59:11 +03:00
export default function Menu({ className, children, onDismiss, relativeTo, widthRelative }) {
2021-02-02 07:28:25 +03:00
return relativeTo ? (
<RelativeModal
children={children}
className={`${className || ''} py-2`}
2021-02-02 07:28:25 +03:00
role="listbox"
onDismiss={onDismiss}
portalRootID="menus"
relativeTo={relativeTo}
2021-02-07 07:59:11 +03:00
widthRelative={widthRelative}
2021-02-02 07:28:25 +03:00
/>
) : null;
}
2022-02-26 22:11:00 +03:00
export function MenuItem({ focus, icon: Icon, label, href, onSelect, value, ...attrs }) {
2021-02-02 07:28:25 +03:00
const handleClick = useCallback(() => {
onSelect && onSelect(value, label);
}, [onSelect, value, label]);
2022-02-26 22:11:00 +03:00
const Element = href ? 'a' : 'div';
2021-02-02 07:28:25 +03:00
return (
2022-02-26 22:11:00 +03:00
<Element
className={`flex space-x-2 p-2 px-5 hover:bg-gray-200 dark:hover:bg-gray-800 dark:hover:text-white cursor-pointer ${
2021-02-02 07:28:25 +03:00
focus ? 'bg-gray-200 dark:bg-gray-800 dark:text-white' : ''
}`}
2022-02-26 22:11:00 +03:00
href={href}
onClick={handleClick}
2021-02-02 07:28:25 +03:00
role="option"
2022-02-26 22:11:00 +03:00
{...attrs}
2021-02-02 07:28:25 +03:00
>
{Icon ? (
2021-02-07 07:59:11 +03:00
<div className="w-6 h-6 self-center mr-4 text-gray-500 flex-shrink-0">
<Icon />
</div>
) : null}
<div className="whitespace-nowrap">{label}</div>
2022-02-26 22:11:00 +03:00
</Element>
2021-02-02 07:28:25 +03:00
);
}
export function MenuSeparator() {
return <div className="border-b border-gray-200 dark:border-gray-800 my-2" />;
}