mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added node edit menu
This commit is contained in:
parent
f185914c7c
commit
74f4c7562b
16 changed files with 320 additions and 175 deletions
64
src/components/menu/MenuButton/index.tsx
Normal file
64
src/components/menu/MenuButton/index.tsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
import React, { FC, ReactNode } from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
import { Manager, Popper, Reference } from 'react-popper';
|
||||
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { useFocusEvent } from '~/hooks/dom/useFocusEvent';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
interface MenuButtonProps {
|
||||
icon?: ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const modifiers = [
|
||||
{
|
||||
name: 'offset',
|
||||
options: {
|
||||
offset: [5, 10],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const MenuButton: FC<MenuButtonProps> = ({
|
||||
children,
|
||||
className,
|
||||
icon = <Icon icon="dots-vertical" size={24} />,
|
||||
}) => {
|
||||
const { focused, onFocus, onBlur } = useFocusEvent(false, 150);
|
||||
|
||||
return (
|
||||
<Manager>
|
||||
<Reference>
|
||||
{({ ref }) => (
|
||||
<button
|
||||
className={classNames(styles.menu, className)}
|
||||
ref={ref}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
>
|
||||
{icon}
|
||||
</button>
|
||||
)}
|
||||
</Reference>
|
||||
|
||||
{focused && (
|
||||
<Popper placement="bottom-end" modifiers={modifiers}>
|
||||
{({ style, ref, placement }) => (
|
||||
<div
|
||||
style={style}
|
||||
ref={ref}
|
||||
className={classNames(styles.popper, { [styles.top]: placement === 'top-end' })}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
</Popper>
|
||||
)}
|
||||
</Manager>
|
||||
);
|
||||
};
|
||||
|
||||
export { MenuButton };
|
Loading…
Add table
Add a link
Reference in a new issue