Skip to content

Commit

Permalink
fix: css mode directive applied multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
KHOUBZA Younes committed Jul 2, 2022
1 parent cdc0478 commit c7a60a8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/flasher/src/flasherFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export default class FlasherFactory implements NotificationFactoryInterface {
const nOptions = notification.options || {};
const options = Array.isArray(nOptions) ? this.options : Object.assign({}, this.options, nOptions);

this.applyDarkMode();

const onContainerReady = () => {
const container = this.createContainer(options);
this.addToContainer(container, envelope, options);
Expand All @@ -102,6 +100,8 @@ export default class FlasherFactory implements NotificationFactoryInterface {

renderOptions(options: FlasherOptions): void {
this.options = Object.assign({}, this.options, options);

this.applyDarkMode();
}

createContainer(options: { position: string; style: Properties }): HTMLDivElement {
Expand Down Expand Up @@ -200,6 +200,10 @@ export default class FlasherFactory implements NotificationFactoryInterface {
}

applyDarkMode(): void {
if (document.body.classList.contains('fl-dark-mode')) {
return;
}

let [mode, className = '.dark'] = [].concat(this.options.darkMode as unknown as ConcatArray<never>);
let css = '.fl-main-container .fl-container.fl-flasher {background-color: rgb(15, 23, 42);color: rgb(255, 255, 255);}';

Expand All @@ -211,6 +215,8 @@ export default class FlasherFactory implements NotificationFactoryInterface {
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);

document.body.classList.add('fl-dark-mode');
}

stringToHTML(str: string): HTMLElement {
Expand Down

0 comments on commit c7a60a8

Please sign in to comment.