Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/MultiRange/MultiRange.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ export const MultiRangeSingleValue: Story = {
export const MultiRangeWithNumberField: Story = {
args: { values: [20], showNumber: true },
render: Template,
};
};
5 changes: 1 addition & 4 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ const Table = <RowDataType extends TableData>({
key={row.id}
>
{enableRowFocusOnClick && (
<td
role="cell"
className={focusedTdClass(row.id === focusedRowId)}
>
<td role="cell" className={focusedTdClass(row.id === focusedRowId)}>
<button
type="button"
aria-label="Focus row"
Expand Down
11 changes: 0 additions & 11 deletions src/components/Tooltip/Tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,3 @@
display: inline-block;
}

.c-tooltip-component {
position: absolute;
max-width: 48rem;
user-select: none;
visibility: hidden;
z-index: 75;
}

.c-tooltip-component--show {
visibility: visible;
}
2 changes: 1 addition & 1 deletion src/components/Tooltip/Tooltip.slots.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FC, ReactNode } from 'react';

export const TooltipContent: FC<{ children?: ReactNode }> = ({ children }) => <>{children}</>;
export const TooltipTrigger: FC<{ children?: ReactNode }> = ({ children }) => <>{children}</>;
export const TooltipContent: FC<{ children?: ReactNode }> = ({ children }) => <>{children}</>;
21 changes: 21 additions & 0 deletions src/components/Tooltip/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,24 @@ export const TooltipDynamicPosition: Story = {
</div>
),
};

export const TooltipStyling: Story = {
render: () => (
<div className="u-text-center" style={{ paddingTop: '200px', paddingLeft: '200px' }}>
<Tooltip
position="top"
arrowFillColor="yellow"
arrowStrokeColor="red"
arrowStrokeWidth={2}
style={{ backgroundColor: 'yellow', border: '2px solid red', padding: '10px' }}
>
<TooltipTrigger>
<span>Hover me!</span>
</TooltipTrigger>
<TooltipContent>
<span>This is a tooltip</span>
</TooltipContent>
</Tooltip>
</div>
),
};
68 changes: 41 additions & 27 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import clsx from 'clsx';
import { type FunctionComponent, type ReactNode, useRef, useState } from 'react';
import {
type CSSProperties,
type FunctionComponent,
type ReactNode,
useRef,
useState,
} from 'react';

import { useSlot } from '../../hooks/use-slot';
import { generateRandomId } from '../../utils/generate-random-id/generate-random-id';
Expand All @@ -25,19 +31,27 @@ interface TooltipPropsSchema {
position: Placement;
offset?: number;
contentClassName?: string;
style?: CSSProperties;
arrowFillColor?: string; // https://floating-ui.com/docs/floatingarrow#fill
arrowStrokeColor?: string; // https://floating-ui.com/docs/floatingarrow#stroke
arrowStrokeWidth?: number; // https://floating-ui.com/docs/FloatingArrow#strokewidth
}

const Tooltip: FunctionComponent<TooltipPropsSchema> = ({
children,
position = 'top',
offset = 10,
contentClassName,
style,
arrowFillColor = '#FFF',
arrowStrokeColor,
arrowStrokeWidth = 0,
}) => {
const [show, setShow] = useState(false);
const [id] = useState(generateRandomId());

const tooltipSlot = useSlot(TooltipContent, children);
const triggerSlot = useSlot(TooltipTrigger, children);
const triggerElement = useSlot(TooltipTrigger, children);
const contentElement = useSlot(TooltipContent, children);
const arrowRef = useRef(null);

const { refs, floatingStyles, context } = useFloating({
Expand Down Expand Up @@ -67,39 +81,39 @@ const Tooltip: FunctionComponent<TooltipPropsSchema> = ({
click,
]);

return tooltipSlot && triggerSlot ? (
return contentElement && triggerElement ? (
<>
<div
className="c-tooltip-component-trigger"
data-id={id}
ref={refs.setReference}
{...getReferenceProps()}
>
{triggerSlot}
{triggerElement}
</div>

<div
className={clsx(
contentClassName,
'c-tooltip-component',
`c-tooltip-component--${position}`,
{
'c-tooltip-component--show': show,
}
)}
ref={refs.setFloating}
style={floatingStyles}
{...getFloatingProps()}
>
{tooltipSlot}
<FloatingArrow
ref={arrowRef}
context={context}
className="c-tooltip-component__arrow"
fill="green"
stroke="red"
/>
</div>
{show && (
Comment thread
bertyhell marked this conversation as resolved.
<div
className={clsx(
contentClassName,
'c-tooltip-component',
`c-tooltip-component--${position}`
)}
ref={refs.setFloating}
style={{ ...floatingStyles, ...style }}
{...getFloatingProps()}
>
{contentElement}
<FloatingArrow
ref={arrowRef}
context={context}
className="c-tooltip-component__arrow"
fill={arrowFillColor}
stroke={arrowStrokeColor}
strokeWidth={arrowStrokeWidth}
/>
</div>
)}
</>
) : null;
};
Expand Down