Skip to content

Commit

Permalink
Adding Tooltip support on header
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncid committed Jan 16, 2025
1 parent bffcefb commit ba8b785
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sparkle/src/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ declare module "@tanstack/react-table" {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface ColumnMeta<TData, TValue> {
className?: string;
width?: string;
flex?: number;
tooltip?: string;
}
}

Expand Down Expand Up @@ -304,7 +303,7 @@ DataTable.Head = function Head({
column,
...props
}: HeadProps) {
return (
const content = (
<th
className={classNames(
"s-py-2 s-pr-3 s-text-left s-text-xs s-font-medium s-capitalize s-text-foreground",
Expand All @@ -316,6 +315,12 @@ DataTable.Head = function Head({
{children}
</th>
);

if (column.columnDef.meta?.tooltip) {
return <Tooltip label={column.columnDef.meta.tooltip} trigger={content} />;
}

return content;
};

DataTable.Body = function Body({
Expand Down
1 change: 1 addition & 0 deletions sparkle/src/stories/DataTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const columns: ColumnDef<Data>[] = [
sortingFn: "text",
meta: {
className: "s-w-full",
tooltip: "User's full name",
},
cell: (info) => (
<DataTable.CellContent
Expand Down

0 comments on commit ba8b785

Please sign in to comment.