Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opacity prop #1054

Merged
merged 3 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import { Tooltip } from 'react-tooltip';
| `afterHide` | `function` | no | | | A function to be called after the tooltip is hidden |
| `middlewares` | `Middleware[]` | no | | array of valid `floating-ui` middlewares | Allows for advanced customization. Check the [`floating-ui` docs](https://floating-ui.com/docs/middleware) for more information |
| `border` | `CSSProperties['border']` | no | | a CSS border style | Change the style of the tooltip border (including the arrow) |
| `opacity` | `CSSProperties['opacity']` | no | `0.9` | a CSS opacity value | Change the opacity of the tooltip |

### Envs

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/upgrade-guide/changelog-v4-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ If you run into any problems with the tooltip not updating after changes are mad
- [x] `offset` - also available on anchor element as `data-tooltip-offset`
- [ ] `padding` - use `className` and custom CSS
- [ ] `multiline` - supported by default in `content` and `html` props
- [ ] `border` - use `className` and custom CSS
- [ ] `borderClass` - use `className` and custom CSS
- [x] `border`
- [ ] `borderClass` - use `border` prop
- [ ] `textColor` - use `className` and custom CSS
- [ ] `backgroundColor` - use `className` and custom CSS
- [ ] `borderColor` - use `className` and custom CSS
- [ ] `borderColor` - use `border` prop
- [ ] `arrowColor` - use `className` and custom CSS
- [ ] `arrowRadius` - use `className` and custom CSS
- [ ] `tooltipRadius` - use `className` and custom CSS
Expand Down
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