Skip to content

Commit

Permalink
refactor: toolbar popover item component
Browse files Browse the repository at this point in the history
fix: disabled toolbar popover item
  • Loading branch information
hamed-musallam committed Jul 19, 2024
1 parent 2805ab4 commit 9c59558
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions src/component/elements/ToolbarPopoverItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,44 @@ import {
ToolbarItemProps,
} from 'react-science/ui';

export interface ToolbarPopoverMenuItem extends MenuItemProps {
data?: object;
export interface ToolbarPopoverMenuItem<T = object> extends MenuItemProps {
data?: T;
}

interface ToolbarPopoverItemProps
interface ToolbarPopoverItemProps<T = object>
extends Omit<
BaseToolbarPopoverItemProps,
'onClick' | 'content' | 'itemProps'
>,
ToolbarItemProps {
options: ToolbarPopoverMenuItem[];
onClick: (data?: object) => void;
Pick<
ToolbarItemProps,
'tooltip' | 'icon' | 'tooltipProps' | 'active' | 'id'
> {
itemProps?: Omit<ToolbarItemProps, 'onClick' | 'disabled'>;
options: Array<ToolbarPopoverMenuItem<T>>;
onClick: (data?: T) => void;
}

export function ToolbarPopoverItem(props: ToolbarPopoverItemProps) {
const { options, onClick, ...itemProps } = props;
export function ToolbarPopoverItem<T = object>(
props: ToolbarPopoverItemProps<T>,
) {
const {
options,
onClick,
icon,
tooltip,
tooltipProps,
active,
id,
itemProps,
disabled,
...otherPopoverItemProps
} = props;

return (
<Toolbar.PopoverItem
disabled={disabled}
{...otherPopoverItemProps}
content={
<Menu>
{options.map((option) => {
Expand All @@ -39,7 +58,15 @@ export function ToolbarPopoverItem(props: ToolbarPopoverItemProps) {
})}
</Menu>
}
itemProps={itemProps}
itemProps={{
icon,
tooltip,
tooltipProps,
active,
id,
disabled,
...itemProps,
}}
/>
);
}

0 comments on commit 9c59558

Please sign in to comment.