-
-
Notifications
You must be signed in to change notification settings - Fork 533
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
feat: add manual inject styles function into the project #1041
Conversation
I created the flow to inject the styles manually from the package instead of letting Rollup handle it by itself. what is pending?
Suggestion: But this doesn't sound like the best way to handle this switch. So, I need help here :) |
src/utils/handle-style.ts
Outdated
function removeStyle() { | ||
const style = document.getElementById(REACT_TOOLTIP_STYLES_ID) | ||
if (!style) { | ||
return | ||
} | ||
style.remove() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test if something like this works (too lazy to setup and test it myself 😑)
The idea is to use import { removeStyle } from 'react-tooltip'
How does removing the style injection affect the tooltip functionally? Since it depends on the |
This will probably break the tooltip feature, one thing that we can do is separate it into 2 CSS files:
please let me know your thoughts about it |
@gabrieljablonski confirming that this works but breaks the tooltip, please let me know your thoughts about my previous message |
@danielbarion Having a separate injection for functional styling seems like an adequate solution. My suggestion (make sure to check if I missed something): /* react-tooltip-core.css (feel free to choose a better name for the file) */
.tooltip {
position: absolute;
visibility: hidden;
opacity: 0;
}
.fixed {
position: fixed;
}
.arrow {
position: absolute;
}
.noArrow {
display: none;
}
.show {
visibility: visible;
opacity: var(--rt-opacity);
}
|
Beta version released with the last commit:
or
I only tested without the styles, I'll test everything later, but feel free to test it or update anything. Thanks! |
coreStyles['arrow'], | ||
styles['arrow'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is keeping both styles intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but please feel free to reorganize the styles, I tried to keep the necessary CSS for position and basic behavior into the Core file, I'll check again this week when I have more time, but please, go ahead if you want to change anything
Yes, if you check, they have different attributes on their files (if I'm not
wrong)
I will run more tests, I had to leave the computer, so, this is just to
validate the idea
|
Screen.Recording.2023-06-18.at.23.08.17.movThe code can be used in a button or inside of a
|
Does calling it globally (outside any components) work? That would be the most convenient IMO |
@gabrieljablonski I'm not totally sure that I got how to test it on Next 13, but it breaks because I'm importing from a custom export:
and importing this function from the package also breaks it too. Can you test it or guide me on how to test it, please? My test environment is just a fresh Next 13 project and I'm using Yalc to test the implementation, but you can try the beta release from NPM instead of Yalc |
@gabrieljablonski another option is:
|
If we do this we're basically back to how it was before, which would not be ideal IMO. What I meant with the import { removeStyle } from 'react-tooltip'
removeStyle()
function MyComponent() {
...
} This way, there's no need to put it inside a As for doing this with the "use client"
export { Tooltip } from 'react-tooltip' Either way, users should be fine to create the |
I do agree, but now we have the basic feature of the Tooltip with the Core styles, before nothing was working because of 0 styles of tooltip on the page. I'm just thinking of projects that don't want to inject the colors from react-tooltip and this can cause re-paint of the elements in the page (probably this impact will be minimal, but I'm thinking if it's possible to reduce it to 0). Does it make sense? edit: maybe adding an option using environment variable to prevent the colors being injected and if no environment variable set, always inject all the styles (and keep the option to use the |
Since most users will probably just use the default styling and partially override the styling, I really like the idea of not having to import something to apply the styles. I'm fine with the env variable approach, but then we should consider how useful still having |
Keeping the I don't know, I'm probably overthinking here, if you believe it's not useful to keep the remove styles function, I'll agree with you and all good :) |
Hadn't thought of these use cases, so yeah, keeping both methods should be fine then. Though I'll suggest using the env variable should be the preferred method suggested in the docs. |
ec1c3d9
to
5379e94
Compare
@gabrieljablonski the |
or
Check the PR changes for more information. |
@danielbarion any idea when this is going to be merged officially? :) |
@dsternlicht just working out the final kinks. An official version should be released in a couple days. Until then, don't worry about using the beta version, it should work just fine. |
Sounds good. Thanks @gabrieljablonski! |
@gabrieljablonski I tested again and I did two new small commits, please check them before we merge this PR thanks! |
🎉 |
Co-authored-by: Gabriel Jablonski <gabriel.g.jablonski@gmail.com>
40d404d
to
424ef70
Compare
available at v5.16.0 |
idea from #1025