Skip to content

Commit 4054d4b

Browse files
committed
feat(styles service): for creating helper css classes to prevent fouc
1 parent 785d693 commit 4054d4b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/client/scripts/private/mixins/base.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { props, withComponent } from '../../../../../skatejs/dist/esnext/index.j
55
import { html, render } from '../../../../../lit-html/lit-html.js';
66
import EventService from '../../private/services/event.js';
77
import ViewService from '../../private/services/view.js';
8+
import Styles from '../../private/services/styles.js';
9+
Styles.addUtils(); // only runs once
810

911
const Base = (BaseElm = HTMLElement) => class extends withComponent(BaseElm) {
1012
/* Lifecycle
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/************************************
2+
* STYLES SERVICE
3+
* ---------------------------------
4+
* HOW TO USE
5+
- import Styles from './styles.js';
6+
* API
7+
- Styles.addUtils(); :void
8+
************************************/
9+
const ID = 'rb-style-helpers';
10+
const STYLES = `
11+
[rb-hide] { display: none !important; }
12+
`;
13+
14+
const StylesService = {
15+
addUtils() { // :void (ex: rb-toggle.js)
16+
if (document.getElementById(ID)) return;
17+
const styleElm = document.createElement('style');
18+
styleElm.id = ID;
19+
document.head.appendChild(styleElm);
20+
styleElm.appendChild(document.createTextNode(STYLES));
21+
}
22+
};
23+
24+
/* Export it!
25+
*************/
26+
export default StylesService;

0 commit comments

Comments
 (0)