Skip to content

Commit

Permalink
fix: export Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancarloscorrea committed Jul 17, 2024
1 parent 706503e commit 76d9f21
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/cortex-react/docs/tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { StoryFn } from '@storybook/react';
import { button } from '../../cortex-core/src';
import Tooltip from '../src/components/Tooltip';
import { Tooltip } from '../src/components';

export default {
title: 'Cortex/Tooltip',
Expand Down
96 changes: 49 additions & 47 deletions packages/cortex-react/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,56 @@ interface TooltipProps {
style?: React.CSSProperties;
}

const Tooltip = forwardRef<HTMLDivElement, TooltipProps>((props, ref) => {
const {
children,
text,
trigger = 'hover',
placement = 'top',
width,
height,
} = props;
const arrowRef = useRef(null);
export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
(props, ref) => {
const {
children,
text,
trigger = 'hover',
placement = 'top',
width,
height,
} = props;
const arrowRef = useRef(null);

const {
isOpen,
triggerProps,
x,
y,
strategy,
refs,
context,
floatingStyles,
} = useFloatingLogic({ placement, arrowRef, trigger });
const {
isOpen,
triggerProps,
x,
y,
strategy,
refs,
context,
floatingStyles,
} = useFloatingLogic({ placement, arrowRef, trigger });

return (
<>
{React.cloneElement(children, triggerProps)}
{isOpen ? (
<div
ref={ref || refs.setFloating}
className={
'bg-black text-white p-2 rounded z-50 shadow-md text-justify'
}
style={{
position: strategy,
top: y ?? 0,
left: x ?? 0,
width,
height,
...floatingStyles,
}}
>
{text}
<FloatingArrow ref={arrowRef} context={context} fill="black" />
</div>
) : (
<></>
)}
</>
);
});
return (
<>
{React.cloneElement(children, triggerProps)}
{isOpen ? (
<div
ref={ref || refs.setFloating}
className={
'bg-black text-white p-2 rounded z-50 shadow-md text-justify'
}
style={{
position: strategy,
top: y ?? 0,
left: x ?? 0,
width,
height,
...floatingStyles,
}}
>
{text}
<FloatingArrow ref={arrowRef} context={context} fill="black" />
</div>
) : (
<></>
)}
</>
);
}
);

export default Tooltip;

0 comments on commit 76d9f21

Please sign in to comment.