mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
40 lines
943 B
TypeScript
40 lines
943 B
TypeScript
import clsx from 'clsx';
|
|
import type { HTMLAttributes, PropsWithChildren, ReactNode } from 'react';
|
|
import { forwardRef, useMemo } from 'react';
|
|
|
|
import { menuItemIcon } from './styles.css';
|
|
|
|
export interface MenuIconProps
|
|
extends PropsWithChildren,
|
|
HTMLAttributes<HTMLDivElement> {
|
|
icon?: ReactNode;
|
|
position?: 'start' | 'end';
|
|
}
|
|
|
|
export const MenuIcon = forwardRef<HTMLDivElement, MenuIconProps>(
|
|
({ children, icon, position = 'start', className, ...otherProps }, ref) => {
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
className={useMemo(
|
|
() =>
|
|
clsx(
|
|
menuItemIcon,
|
|
{
|
|
end: position === 'end',
|
|
start: position === 'start',
|
|
},
|
|
className
|
|
),
|
|
[className, position]
|
|
)}
|
|
{...otherProps}
|
|
>
|
|
{icon || children}
|
|
</div>
|
|
);
|
|
}
|
|
);
|
|
|
|
MenuIcon.displayName = 'MenuIcon';
|