mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 21:31:48 +08:00
28 lines
842 B
TypeScript
28 lines
842 B
TypeScript
import global from 'global';
|
|
|
|
export const clearStyles = (selector: string | string[]) => {
|
|
const selectors = Array.isArray(selector) ? selector : [selector];
|
|
selectors.forEach(clearStyle);
|
|
};
|
|
|
|
const clearStyle = (selector: string | string[]) => {
|
|
const element = global.document.getElementById(selector);
|
|
if (element && element.parentElement) {
|
|
element.parentElement.removeChild(element);
|
|
}
|
|
};
|
|
|
|
export const addOutlineStyles = (selector: string, css: string) => {
|
|
const existingStyle = global.document.getElementById(selector);
|
|
if (existingStyle) {
|
|
if (existingStyle.innerHTML !== css) {
|
|
existingStyle.innerHTML = css;
|
|
}
|
|
} else {
|
|
const style = global.document.createElement('style');
|
|
style.setAttribute('id', selector);
|
|
style.innerHTML = css;
|
|
global.document.head.appendChild(style);
|
|
}
|
|
};
|