Skip to content

Commit

Permalink
allow adding tooltips to table header
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Jul 31, 2024
1 parent da12ac7 commit 38e9d07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import styled, { useTheme } from 'styled-components'
import { isEmpty, isNil } from 'lodash-es'

import usePrevious from '../hooks/usePrevious'
import { InfoOutlineIcon, Tooltip } from '../index'

import Button from './Button'
import CaretUpIcon from './icons/CaretUpIcon'
Expand Down Expand Up @@ -725,6 +726,11 @@ function TableRef(
header.getContext()
)}
</div>
{header.column.columnDef.meta?.tooltip && (
<Tooltip label={header.column.columnDef.meta.tooltip}>
<InfoOutlineIcon />
</Tooltip>
)}
<SortIndicator
direction={header.column.getIsSorted()}
/>
Expand Down
11 changes: 2 additions & 9 deletions src/stories/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
AppIcon,
ArrowRightLeftIcon,
CollapseIcon,
IconFrame,
InfoIcon,
LogsIcon,
Table,
Tooltip,
Expand Down Expand Up @@ -145,20 +143,15 @@ const columns = [
columnHelper.accessor((row) => row.description, {
id: 'description',
enableGlobalFilter: true,
meta: { tooltip: 'Tooltip message' },
cell: (info: any) => <span>{info.getValue()}</span>,
header: () => (
<Flex
gap="xsmall"
alignItems="center"
justifyContent="space-between"
>
Description{' '}
<IconFrame
clickable
textValue="Book"
icon={<InfoIcon />}
size="small"
/>
Description
</Flex>
),
}),
Expand Down
1 change: 1 addition & 0 deletions src/types/react-table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ declare module '@tanstack/table-core' {
truncate?: boolean
gridTemplate?: string
center?: boolean
tooltip?: string
}
}

0 comments on commit 38e9d07

Please sign in to comment.