* Note about `state` parameter: * This parameter is used to keep track of the state of the styles * into the tests since the const `injected` is not acessible or resettable in the tests
({
css,
id = REACT_TOOLTIP_BASE_STYLES_ID,
type = 'base',
ref,
state = {},
}: {
css: string
id?: string
type?: 'core' | 'base'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ref?: any
state?: { [key: string]: boolean }
})
| 14 | * into the tests since the const `injected` is not acessible or resettable in the tests |
| 15 | */ |
| 16 | function injectStyle({ |
| 17 | css, |
| 18 | id = REACT_TOOLTIP_BASE_STYLES_ID, |
| 19 | type = 'base', |
| 20 | ref, |
| 21 | state = {}, |
| 22 | }: { |
| 23 | css: string |
| 24 | id?: string |
| 25 | type?: 'core' | 'base' |
| 26 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 27 | ref?: any |
| 28 | state?: { [key: string]: boolean } |
| 29 | }) { |
| 30 | if ( |
| 31 | !css || |
| 32 | typeof document === 'undefined' || |
| 33 | (typeof state[type] !== 'undefined' ? state[type] : injected[type]) |
| 34 | ) { |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | if ( |
| 39 | type === 'core' && |
| 40 | typeof process !== 'undefined' && // this validation prevents docs from breaking even with `process?` |
| 41 | process.env && |
| 42 | process.env.REACT_TOOLTIP_DISABLE_CORE_STYLES |
| 43 | ) { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | if ( |
| 48 | type === 'base' && |
| 49 | typeof process !== 'undefined' && // this validation prevents docs from breaking even with `process?` |
| 50 | process.env && |
| 51 | process.env.REACT_TOOLTIP_DISABLE_BASE_STYLES |
| 52 | ) { |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | if (type === 'core') { |
| 57 | id = REACT_TOOLTIP_CORE_STYLES_ID |
| 58 | } |
| 59 | |
| 60 | if (!ref) { |
| 61 | ref = {} |
| 62 | } |
| 63 | const { insertAt } = ref |
| 64 | |
| 65 | if (document.getElementById(id)) { |
| 66 | // this could happen in cases the tooltip is imported by multiple js modules |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | const head = document.head || document.getElementsByTagName('head')[0] |
| 71 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 72 | const style: any = document.createElement('style') |
| 73 | style.id = id |
no outgoing calls
no test coverage detected
searching dependent graphs…