deno.land / x / nano_jsx@v0.1.0 / withStyles.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { h } from './core.ts'import { Component } from './component.ts'import { Fragment } from './fragment.ts'import { Helmet } from './components/helmet.ts'
interface ObjectHasToString { toString: () => string}type Styles = stringtype FunctionReturnsString = () => stringtype WithStylesType = Styles | ObjectHasToString | FunctionReturnsString
export const withStyles: any = (...styles: WithStylesType[]) => (WrappedComponent: any) => { return class extends Component { render() { const { children, ...rest } = this.props
const helmets: any[] = [] styles.forEach(style => { if (typeof style === 'string') { helmets.push(h(Helmet, null, h('style', null, style))) } else if (typeof style === 'function') { const _style = style() if (typeof _style === 'string') { helmets.push(h(Helmet, null, h('style', null, _style))) } } else if (typeof style === 'object') { const _style = style.toString?.() if (typeof _style === 'string') { helmets.push(h(Helmet, null, h('style', null, _style))) } } })
const component = children && children.length > 0 ? h(WrappedComponent, { ...rest }, children) : h(WrappedComponent, { ...this.props })
return h(Fragment, null, ...helmets, component) } } }
nano_jsx

Version Info

Tagged at
8 months ago