Skip to content

Commit d3ea0c8

Browse files
committed
fix: handle line clamp prop for tooltip
1 parent 7f2997f commit d3ea0c8

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

src/Common/ClipboardButton/ClipboardButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function ClipboardButton({
7575
>
7676
<button
7777
type="button"
78-
className={`dc__outline-none-imp p-0 flex bcn-0 dc__no-border ${rootClassName}`}
78+
className={`dc__outline-none-imp p-0 flex dc__transparent--imp dc__no-border ${rootClassName}`}
7979
onMouseEnter={handleEnableTippy}
8080
onMouseLeave={handleDisableTippy}
8181
onClick={handleCopyContent}

src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ const SortableTableHeaderCell = ({
6767
onClick={isSortable ? triggerSorting : noop}
6868
disabled={disabled}
6969
>
70-
<Tooltip
71-
showOnTruncate={showTippyOnTruncate}
72-
className="default-tt"
73-
placement="top"
74-
arrow={false}
75-
content={title}
76-
>
70+
<Tooltip showOnTruncate={showTippyOnTruncate} content={title}>
7771
<span className="dc__uppercase dc__ellipsis-right">{title}</span>
7872
</Tooltip>
7973
{renderSortIcon()}

src/Common/Tooltip/Tooltip.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useCallback, useState, cloneElement } from 'react'
2+
import TippyJS from '@tippyjs/react'
3+
import { TooltipProps } from './types'
4+
5+
const Tooltip = ({
6+
showOnTruncate = false,
7+
alwaysShowTippyOnHover = false,
8+
children: child,
9+
...rest
10+
}: TooltipProps) => {
11+
const [isTextTruncated, setIsTextTruncated] = useState(false)
12+
13+
const refCallback = useCallback((node: HTMLDivElement) => {
14+
if (node) {
15+
setIsTextTruncated(node.scrollWidth > node.clientWidth || node.scrollHeight > node.clientHeight)
16+
}
17+
}, [])
18+
19+
return (!isTextTruncated || !showOnTruncate) && !alwaysShowTippyOnHover ? (
20+
cloneElement(child, { ...child.props, ref: refCallback })
21+
) : (
22+
<TippyJS
23+
arrow={false}
24+
placement="top"
25+
{...rest}
26+
className={`default-tt dc__word-break-all dc__mxw-200 ${rest.className}`}
27+
>
28+
{cloneElement(child, { ...child.props, ref: refCallback })}
29+
</TippyJS>
30+
)
31+
}
32+
33+
export default Tooltip

src/Common/Tooltip/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Tooltip } from './Tooltip'

src/Common/Tooltip/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { TippyProps } from '@tippyjs/react'
2+
3+
export interface TooltipProps extends TippyProps {
4+
/**
5+
* If true, show tippy on truncate
6+
* @default false
7+
*/
8+
showOnTruncate?: boolean
9+
/**
10+
* If true, wrap with tippy irrespective of other options
11+
* @default false
12+
*/
13+
alwaysShowTippyOnHover?: boolean
14+
}

0 commit comments

Comments
 (0)