Skip to content

Commit

Permalink
- Add appendTooltipTo prop to StandardTable, which is passed to the…
Browse files Browse the repository at this point in the history
… Tooltip `appendTo` prop.
  • Loading branch information
mattias800 committed Sep 7, 2023
1 parent 36e0436 commit a79ddce
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ColGroups } from "./ColGroups";
import styles from "./StandardTable.module.css";
import { StandardTableContent } from "./StandardTableContent";
import { StandardTableHeadRow } from "./StandardTableHeadRow";
import { TooltipProps } from "@stenajs-webui/tooltip";

export interface StandardTableProps<
TItem,
Expand Down Expand Up @@ -75,6 +76,12 @@ export interface StandardTableProps<
*/
config: StandardTableConfig<TItem, TColumnKey, TColumnGroupKey>;

/**
* Append tooltip to HTML element. This prop is passed to Tippy.
* This is useful to solve z-index problems.
*/
appendTooltipTo?: TooltipProps["appendTo"];

/**
* Items to list in the table.
*/
Expand Down Expand Up @@ -160,6 +167,7 @@ export const StandardTable = function StandardTable<
variant = "standard",
onKeyDown,
onSortOrderChange,
appendTooltipTo,
...props
}: StandardTableProps<TItem, TColumnKey, TColumnGroupKey>) {
const generatedTableId = useId();
Expand Down Expand Up @@ -297,6 +305,7 @@ export const StandardTable = function StandardTable<
<StandardTableHeadRow
items={props.items}
height={"var(--current-row-height)"}
appendTooltipTo={appendTooltipTo}
/>
</thead>
<StandardTableContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { useColumnConfigById } from "../hooks/UseColumnConfigById";
import { useStandardTableConfig } from "../hooks/UseStandardTableConfig";
import { getCellBorder } from "../util/CellBorderCalculator";
import { formatColumnIdToHeaderCellLabel } from "../util/LabelFormatter";
import { TooltipProps } from "@stenajs-webui/tooltip";

export interface StandardTableHeaderItemProps {
columnId: string;
disableBorderLeft?: boolean;
borderFromGroup?: boolean | string;
stickyHeader?: boolean;
top?: string | number;
appendTooltipTo?: TooltipProps["appendTo"];
}

export const StandardTableHeadItem = React.memo(
Expand All @@ -23,6 +25,7 @@ export const StandardTableHeadItem = React.memo(
disableBorderLeft,
stickyHeader,
top,
appendTooltipTo,
}: StandardTableHeaderItemProps) {
const {
justifyContentHeader,
Expand Down Expand Up @@ -102,6 +105,7 @@ export const StandardTableHeadItem = React.memo(
sortOrderIconVariant={
sortOrderIconVariant ?? defaultSortOrderIconVariant
}
appendTooltipTo={appendTooltipTo}
selected={selected}
height={"100%"}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { useStandardTableConfig } from "../hooks/UseStandardTableConfig";
import { getCellBorderFromGroup } from "../util/CellBorderCalculator";
import { StandardTableHeadItem } from "./StandardTableHeadItem";
import { TrWithHoverBackground } from "./TrWithHoverBackground";
import { TooltipProps } from "@stenajs-webui/tooltip";

interface StandardTableHeaderProps<TItem> {
items?: Array<TItem>;
height?: string;
appendTooltipTo?: TooltipProps["appendTo"];
}

const getTopPosition = (
Expand All @@ -43,7 +45,11 @@ const getTopPosition = (

export const StandardTableHeadRow = React.memo(function StandardTableHeadRow<
TItem
>({ items, height = defaultTableRowHeight }: StandardTableHeaderProps<TItem>) {
>({
items,
appendTooltipTo,
height = defaultTableRowHeight,
}: StandardTableHeaderProps<TItem>) {
const groupConfigsAndIds = useGroupConfigsAndIdsForRows();

const {
Expand Down Expand Up @@ -171,6 +177,7 @@ export const StandardTableHeadRow = React.memo(function StandardTableHeadRow<
disableBorderLeft={groupIndex === 0 && index === 0}
stickyHeader={stickyHeader}
top={stickyHeaderStyle.top}
appendTooltipTo={appendTooltipTo}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ButtonWithPopoverProps,
Popover,
Tooltip,
TooltipProps,
} from "@stenajs-webui/tooltip";
import * as React from "react";
import { CSSProperties, useRef } from "react";
Expand All @@ -30,6 +31,7 @@ export interface TableHeadProps extends BoxProps {
selected?: boolean;
alignRight?: boolean;
sortOrderIconVariant?: SortOrderIconVariant;
appendTooltipTo?: TooltipProps["appendTo"];
}

export const TableHeadItem: React.FC<TableHeadProps> = React.memo(
Expand All @@ -45,6 +47,7 @@ export const TableHeadItem: React.FC<TableHeadProps> = React.memo(
overflow = "hidden",
alignRight,
sortOrderIconVariant,
appendTooltipTo,
...boxProps
}) => {
const containerRef = useRef(null);
Expand Down Expand Up @@ -120,6 +123,7 @@ export const TableHeadItem: React.FC<TableHeadProps> = React.memo(
<Tooltip
label={infoIconTooltipText}
zIndex={"var(--swui-sticky-popover-z-index)" as any}
appendTo={appendTooltipTo}
>
<Icon
icon={stenaInfoCircle}
Expand Down

0 comments on commit a79ddce

Please sign in to comment.