File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed
Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -98,8 +98,8 @@ const config = allBuildFormats.map(
9898 replaceBeforeSaveFile ( {
9999 // this only works for the react-tooltip.css because it's the first file
100100 // writen in our build process before the javascript files.
101- "'temp-content-for-styles '" : 'file:react-tooltip.css' ,
102- '"temp-content-for-styles "' : 'file:react-tooltip.css' ,
101+ "'react-tooltip-css-placeholder '" : 'file:react-tooltip.css' ,
102+ '"react-tooltip-css-placeholder "' : 'file:react-tooltip.css' ,
103103 } ) ,
104104 ]
105105
Original file line number Diff line number Diff line change 11import './tokens.css'
22
3- import styleInject from 'utils/style-inject '
3+ import { injectStyle } from 'utils/handle-style '
44
55import type {
66 ChildrenType ,
@@ -17,10 +17,9 @@ import type { ITooltipController } from './components/TooltipController/TooltipC
1717import type { ITooltipWrapper } from './components/TooltipProvider/TooltipProviderTypes'
1818
1919// this content will be replaced in build time with the `react-tooltip.css` builded content
20- const TooltipStyles = 'temp-content-for-styles '
20+ const TooltipStyles = 'react-tooltip-css-placeholder '
2121
22- // @ts -ignore
23- styleInject ( TooltipStyles )
22+ injectStyle ( TooltipStyles )
2423
2524export { TooltipController as Tooltip } from './components/TooltipController'
2625export { TooltipProvider , TooltipWrapper } from './components/TooltipProvider'
@@ -37,3 +36,5 @@ export type {
3736 IPosition ,
3837 Middleware ,
3938}
39+
40+ export { removeStyle } from './utils/handle-style'
Original file line number Diff line number Diff line change 1- function styleInject ( css : string , ref ?: any ) {
1+ const REACT_TOOLTIP_STYLES_ID = 'react-tooltip-styles'
2+
3+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4+ function injectStyle ( css : string , ref ?: any ) {
25 if ( ! ref ) {
36 // eslint-disable-next-line no-param-reassign
47 ref = { }
58 }
69 const { insertAt } = ref
710
8- if ( ! css || typeof document === 'undefined' || document . getElementById ( 'react-tooltip-styles' ) ) {
11+ if ( ! css || typeof document === 'undefined' || document . getElementById ( REACT_TOOLTIP_STYLES_ID ) ) {
912 return
1013 }
1114
1215 const head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ]
16+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1317 const style : any = document . createElement ( 'style' )
14- style . id = 'react-tooltip-styles'
18+ style . id = REACT_TOOLTIP_STYLES_ID
1519 style . type = 'text/css'
1620
1721 if ( insertAt === 'top' ) {
@@ -31,4 +35,12 @@ function styleInject(css: string, ref?: any) {
3135 }
3236}
3337
34- export default styleInject
38+ function removeStyle ( ) {
39+ const style = document . getElementById ( REACT_TOOLTIP_STYLES_ID )
40+ if ( ! style ) {
41+ return
42+ }
43+ style . remove ( )
44+ }
45+
46+ export { injectStyle , removeStyle }
You can’t perform that action at this time.
0 commit comments