Skip to content

Commit 5eb1cf6

Browse files
feat: opacity prop
1 parent 419e582 commit 5eb1cf6

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const Tooltip = ({
4545
activeAnchor,
4646
setActiveAnchor,
4747
border,
48+
opacity,
4849
}: ITooltip) => {
4950
const tooltipRef = useRef<HTMLElement>(null)
5051
const tooltipArrowRef = useRef<HTMLElement>(null)
@@ -598,7 +599,11 @@ const Tooltip = ({
598599
[coreStyles['clickable']]: clickable,
599600
},
600601
)}
601-
style={{ ...externalStyles, ...inlineStyles }}
602+
style={{
603+
...externalStyles,
604+
...inlineStyles,
605+
opacity: opacity !== undefined && canShow ? opacity : undefined,
606+
}}
602607
ref={tooltipRef}
603608
>
604609
{content}

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ export interface ITooltip {
9090
activeAnchor: HTMLElement | null
9191
setActiveAnchor: (anchor: HTMLElement | null) => void
9292
border?: CSSProperties['border']
93+
opacity?: CSSProperties['opacity']
9394
}

src/components/TooltipController/TooltipController.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const TooltipController = ({
4545
position,
4646
isOpen,
4747
border,
48+
opacity,
4849
setIsOpen,
4950
afterShow,
5051
afterHide,
@@ -248,6 +249,14 @@ const TooltipController = ({
248249
// eslint-disable-next-line no-console
249250
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`)
250251
}
252+
if (style?.opacity) {
253+
// eslint-disable-next-line no-console
254+
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.')
255+
}
256+
if (opacity && !CSS.supports('opacity', `${opacity}`)) {
257+
// eslint-disable-next-line no-console
258+
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`)
259+
}
251260
}, [])
252261

253262
/**
@@ -299,6 +308,7 @@ const TooltipController = ({
299308
position,
300309
isOpen,
301310
border,
311+
opacity,
302312
setIsOpen,
303313
afterShow,
304314
afterHide,

src/components/TooltipController/TooltipControllerTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface ITooltipController {
6767
* might break the tooltip arrow positioning.
6868
*/
6969
border?: CSSProperties['border']
70+
opacity?: CSSProperties['opacity']
7071
setIsOpen?: (value: boolean) => void
7172
afterShow?: () => void
7273
afterHide?: () => void

0 commit comments

Comments
 (0)