Skip to content

Commit

Permalink
feat: opacity prop
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed Jul 3, 2023
1 parent 419e582 commit 5eb1cf6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Tooltip = ({
activeAnchor,
setActiveAnchor,
border,
opacity,
}: ITooltip) => {
const tooltipRef = useRef<HTMLElement>(null)
const tooltipArrowRef = useRef<HTMLElement>(null)
Expand Down Expand Up @@ -598,7 +599,11 @@ const Tooltip = ({
[coreStyles['clickable']]: clickable,
},
)}
style={{ ...externalStyles, ...inlineStyles }}
style={{
...externalStyles,
...inlineStyles,
opacity: opacity !== undefined && canShow ? opacity : undefined,
}}
ref={tooltipRef}
>
{content}
Expand Down
1 change: 1 addition & 0 deletions src/components/Tooltip/TooltipTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ export interface ITooltip {
activeAnchor: HTMLElement | null
setActiveAnchor: (anchor: HTMLElement | null) => void
border?: CSSProperties['border']
opacity?: CSSProperties['opacity']
}
10 changes: 10 additions & 0 deletions src/components/TooltipController/TooltipController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const TooltipController = ({
position,
isOpen,
border,
opacity,
setIsOpen,
afterShow,
afterHide,
Expand Down Expand Up @@ -248,6 +249,14 @@ const TooltipController = ({
// eslint-disable-next-line no-console
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`)
}
if (style?.opacity) {
// eslint-disable-next-line no-console
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.')
}
if (opacity && !CSS.supports('opacity', `${opacity}`)) {
// eslint-disable-next-line no-console
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`)
}
}, [])

/**
Expand Down Expand Up @@ -299,6 +308,7 @@ const TooltipController = ({
position,
isOpen,
border,
opacity,
setIsOpen,
afterShow,
afterHide,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ITooltipController {
* might break the tooltip arrow positioning.
*/
border?: CSSProperties['border']
opacity?: CSSProperties['opacity']
setIsOpen?: (value: boolean) => void
afterShow?: () => void
afterHide?: () => void
Expand Down

0 comments on commit 5eb1cf6

Please sign in to comment.