Files
feishin/src/renderer/components/context-menu/context-menu.tsx
T
Jeff c1330d92b2 Migrate to Mantine v8 and Design Changes (#961)
* mantine v8 migration

* various design changes and improvements
2025-06-24 00:04:36 -07:00

92 lines
2.2 KiB
TypeScript

import { motion, Variants } from 'motion/react';
import { ComponentPropsWithoutRef, forwardRef, ReactNode, Ref } from 'react';
import styles from './context-menu.module.css';
import { Group } from '/@/shared/components/group/group';
interface ContextMenuProps {
children: ReactNode;
maxWidth?: number;
minWidth?: number;
xPos: number;
yPos: number;
}
export const ContextMenuButton = forwardRef(
(
{
children,
leftIcon,
rightIcon,
...props
}: ComponentPropsWithoutRef<'button'> & {
leftIcon?: ReactNode;
rightIcon?: ReactNode;
},
ref: any,
) => {
return (
<button
{...props}
className={styles.contextMenuButton}
disabled={props.disabled}
key={props.key}
onClick={props.onClick}
ref={ref}
>
<Group
justify="space-between"
w="100%"
>
<Group
className={styles.left}
gap="md"
>
{leftIcon}
{children}
</Group>
{rightIcon}
</Group>
</button>
);
},
);
const variants: Variants = {
closed: {
opacity: 0,
transition: {
duration: 0.1,
},
},
open: {
opacity: 1,
transition: {
duration: 0.1,
},
},
};
export const ContextMenu = forwardRef(
({ children, maxWidth, minWidth, xPos, yPos }: ContextMenuProps, ref: Ref<HTMLDivElement>) => {
return (
<motion.div
animate="open"
className={styles.container}
initial="closed"
ref={ref}
style={{
left: xPos,
maxWidth,
minWidth,
top: yPos,
}}
variants={variants}
>
{children}
</motion.div>
);
},
);