Skip to content

Commit 494f0bc

Browse files
committed
Added css function
1 parent 98c78b4 commit 494f0bc

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-element",
3-
"version": "0.0.213",
3+
"version": "0.0.215",
44
"description": "",
55
"license": "LGPL-3.0",
66
"main": "./index.js",

src/main/js-element.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// === exports =======================================================
22

33
// functions and singletons
4-
export { component, createCtx, elem, intercept, prop, setMethods, Attrs }
4+
export { component, createCtx, css, elem, intercept, prop, setMethods, Attrs }
55

66
// types
77
export { Ctx, Ctrl, MethodsOf }
@@ -435,6 +435,30 @@ function addPropHandling(obj: any) {
435435
})
436436
}
437437

438+
// === css ===========================================================
439+
440+
function css(strings: TemplateStringsArray, data?: any[]): string {
441+
const tokens: string[] = []
442+
443+
if (!data) {
444+
return strings[0]
445+
}
446+
447+
for (let i = 0; i < strings.length; ++i) {
448+
tokens.push(stringify(strings[i]))
449+
450+
if (i < data.length - 1) {
451+
tokens.push(stringify(data[i]))
452+
}
453+
}
454+
console.log(tokens.join(''))
455+
return tokens.join('')
456+
}
457+
458+
function stringify(val: any): string {
459+
return val == null ? '' : String(val)
460+
}
461+
438462
// === Attrs =========================================================
439463

440464
const Attrs = {

src/stories/demos/counter-demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { component, elem, prop, setMethods, Attrs } from 'js-element'
1+
import { component, css, elem, prop, setMethods, Attrs } from 'js-element'
22
import { useState } from 'js-element/hooks'
33
import { createRef, html, lit, ref } from 'js-element/lit'
44

@@ -64,7 +64,7 @@ function counterDemo() {
6464
`
6565
}
6666

67-
const styles = `
67+
const styles = css`
6868
* {
6969
font-family: Helvetica, Arial, sans-serif;
7070
}

0 commit comments

Comments
 (0)