anyone got any experience using react-tooltip
with styled-components
?
I tried to wrap my tooltip inside a styled component but they styles weren't fully showing
I wanted a yellow background but got a yellow background with a massive black border
I also want to place the tooltip directly over the top of where I hover, can anyone show me how to do this if possible?
code:
<div>
<ReactTooltip className="extraClass" effect="solid">
{'I shall be the text and this is where I will go'}
</ReactTooltip>
</div>
how do I add the extraClass if im using styled-comps?
The Tooltip can be customized by using the cssClass property, which accepts custom CSS class names that define specific user-defined styles and themes to be applied on the Tooltip element.
This answer is maybe not by the book but I also did not manage to find a way to style at proper way using styled components.
This is my working example.
import styled from 'styled-components';
import ReactTooltip from 'react-tooltip';
export const ReactTooltipStyled = styled(ReactTooltip)`
&.type-dark.place-top {
background-color: blue;
padding: 0.3rem 1rem;
&:after {
border-top-color: blue;
}
}
`;
You just need to import the newly styled component in your React file and use it instead of original ReactTooltip component.
For me, this solution finally worked as expected.
const StyledTooltip = styled(ReactTooltip)`
max-width: 20vh;
white-space: normal;
`
const Tooltip = ({ ...props }) => (
<StyledTooltip effect="solid" multiline place="top" {...props} />
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With