Skip to content

Commit 48047ea

Browse files
Sholto Maudyoshuawuyts
authored andcommitted
added static vs dynamic to doco (#132)
1 parent 875753f commit 48047ea

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,54 @@ By using `:host` we are able to provide styles for the parent element:
9999
</style>
100100
```
101101

102+
## Dynamic vs static
103+
Sheetify is very good for namespacing static css assets in your javaScript code. Currently there is no support for dynamic variables within sheetify, however you could achieve this by setting the inline style property of an element.
104+
105+
```js
106+
const css = require('sheetify')
107+
const html = require('bel')
108+
109+
const sectionWidth = '100px';
110+
const prefix = css`
111+
:host {
112+
background-color: blue;
113+
}
114+
115+
:host > h1 {
116+
text-decoration: underline;
117+
}
118+
`
119+
120+
const tree = html`
121+
<section class=${prefix} style="width:${sectionWidth}">
122+
<h1>My beautiful, centered title</h1>
123+
</section>
124+
`
125+
126+
document.body.appendChild(tree)
127+
```
128+
129+
Should you want to, you could even set dynamic variables in an object and do a rather complicated JSON.stringify with a replace on that object to turn it into a style for an element.
130+
131+
```js
132+
133+
const dynamicStyles = {
134+
width: global.window.innerWidth,
135+
height: global.window.innerHeight,
136+
}
137+
138+
let dynamicStyleString = JSON.stringify(dynamicStyles)
139+
.replace(/\,/g,';')
140+
.replace(/\"/g,'')
141+
.replace(/\{|\}/g,'')
142+
143+
const tree = html`
144+
<div style="${dynamicStyleString}">
145+
<h1>My beautiful, window width</h1>
146+
</div>
147+
`
148+
```
149+
102150

103151
## External files
104152
To include an external CSS file you can pass a path to sheetify as

0 commit comments

Comments
 (0)