You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
2 years ago
|
import React from "react";
|
||
2 years ago
|
import {
|
||
2 years ago
|
getDropdownMenuItemClassName,
|
||
2 years ago
|
useHandleDropdownMenuItemClick,
|
||
|
} from "./common";
|
||
2 years ago
|
import MenuItemContent from "./DropdownMenuItemContent";
|
||
|
|
||
|
const DropdownMenuItem = ({
|
||
|
icon,
|
||
|
onSelect,
|
||
|
children,
|
||
|
shortcut,
|
||
|
className,
|
||
1 year ago
|
selected,
|
||
2 years ago
|
...rest
|
||
2 years ago
|
}: {
|
||
|
icon?: JSX.Element;
|
||
2 years ago
|
onSelect: (event: Event) => void;
|
||
2 years ago
|
children: React.ReactNode;
|
||
|
shortcut?: string;
|
||
1 year ago
|
selected?: boolean;
|
||
2 years ago
|
className?: string;
|
||
2 years ago
|
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
||
|
const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect);
|
||
|
|
||
2 years ago
|
return (
|
||
|
<button
|
||
2 years ago
|
{...rest}
|
||
2 years ago
|
onClick={handleClick}
|
||
2 years ago
|
type="button"
|
||
1 year ago
|
className={getDropdownMenuItemClassName(className, selected)}
|
||
2 years ago
|
title={rest.title ?? rest["aria-label"]}
|
||
2 years ago
|
>
|
||
|
<MenuItemContent icon={icon} shortcut={shortcut}>
|
||
|
{children}
|
||
|
</MenuItemContent>
|
||
|
</button>
|
||
|
);
|
||
|
};
|
||
1 year ago
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
||
|
|
||
|
export const DropDownMenuItemBadge = ({
|
||
|
children,
|
||
|
}: {
|
||
|
children: React.ReactNode;
|
||
|
}) => {
|
||
|
return (
|
||
|
<div
|
||
|
style={{
|
||
|
display: "inline-flex",
|
||
|
marginLeft: "auto",
|
||
1 year ago
|
padding: "2px 4px",
|
||
1 year ago
|
background: "pink",
|
||
|
borderRadius: 6,
|
||
1 year ago
|
fontSize: 9,
|
||
1 year ago
|
color: "black",
|
||
1 year ago
|
fontFamily: "Cascadia, monospace",
|
||
1 year ago
|
}}
|
||
|
>
|
||
|
{children}
|
||
|
</div>
|
||
|
);
|
||
|
};
|
||
|
DropDownMenuItemBadge.displayName = "DropdownMenuItemBadge";
|
||
|
|
||
|
DropdownMenuItem.Badge = DropDownMenuItemBadge;
|
||
2 years ago
|
|
||
|
export default DropdownMenuItem;
|