change(ui) - removed floating-ui
This commit is contained in:
parent
e00cf0354e
commit
44a2b2898a
3 changed files with 1 additions and 72 deletions
|
|
@ -1,69 +0,0 @@
|
|||
import React, { cloneElement, useMemo, useState } from 'react';
|
||||
import {
|
||||
Placement,
|
||||
offset,
|
||||
flip,
|
||||
shift,
|
||||
autoUpdate,
|
||||
useFloating,
|
||||
useInteractions,
|
||||
useHover,
|
||||
useFocus,
|
||||
useRole,
|
||||
useDismiss,
|
||||
useClick,
|
||||
} from '@floating-ui/react-dom-interactions';
|
||||
import { mergeRefs } from 'react-merge-refs';
|
||||
|
||||
interface Props {
|
||||
label: string;
|
||||
placement?: Placement;
|
||||
children: JSX.Element;
|
||||
}
|
||||
|
||||
function AnimatedTooltip({ children, label, placement = 'top' }: Props) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const { x, y, reference, floating, strategy, context } = useFloating({
|
||||
placement,
|
||||
open,
|
||||
onOpenChange: setOpen,
|
||||
middleware: [offset(5), flip(), shift({ padding: 8 })],
|
||||
whileElementsMounted: autoUpdate,
|
||||
});
|
||||
|
||||
const { getReferenceProps, getFloatingProps } = useInteractions([
|
||||
// useHover(context),
|
||||
useFocus(context),
|
||||
useRole(context, { role: 'tooltip' }),
|
||||
useDismiss(context),
|
||||
useClick(context),
|
||||
]);
|
||||
|
||||
// Preserve the consumer's ref
|
||||
const ref = useMemo(() => mergeRefs([reference, (children as any).ref]), [reference, children]);
|
||||
const ppp = getReferenceProps({ ref, ...children.props });
|
||||
// console.log('ppp', ppp);
|
||||
return (
|
||||
<div>
|
||||
{/* {cloneElement(children, getReferenceProps({ ref, ...children.props }))} */}
|
||||
<button ref={reference} {...getReferenceProps({ ref, ...children.props })}>Button</button>
|
||||
{open && (
|
||||
<div
|
||||
ref={floating}
|
||||
className="Tooltip"
|
||||
style={{
|
||||
position: strategy,
|
||||
top: y ?? 0,
|
||||
left: x ?? 0,
|
||||
}}
|
||||
{...getFloatingProps()}
|
||||
>
|
||||
{label}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AnimatedTooltip;
|
||||
|
|
@ -1 +0,0 @@
|
|||
export { default } from './AnimatedTooltip';
|
||||
|
|
@ -56,5 +56,4 @@ export { default as Toggler } from './Toggler';
|
|||
export { default as Input } from './Input';
|
||||
export { default as Form } from './Form';
|
||||
export { default as Modal } from './Modal';
|
||||
export { default as Message } from './Message';
|
||||
export { default as AnimatedTooltip } from './AnimatedTooltip';
|
||||
export { default as Message } from './Message';
|
||||
Loading…
Add table
Reference in a new issue