-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
113 lines (90 loc) · 1.99 KB
/
test.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import PropTypes from 'prop-types'
import { html } from 'js-beautify'
import withThemes, {
ThemeTypes,
propTypesFromThemeTypes
} from './src'
var GrandChild = ({ theme }) => (
<div>
<div className={theme.heading}>GRAND</div>
</div>
)
GrandChild.themeTypes = {
heading: ThemeTypes.className
}
GrandChild.propTypes = {
theme: propTypesFromThemeTypes(GrandChild.themeTypes)
}
GrandChild = withThemes({
default: {
heading: 'base_grand'
}
})(GrandChild)
// --
var Child = ({ theme }) => (
<div>
<div className={theme.heading}>BAR</div>
<div className={theme.body}>FOOBAR</div>
<GrandChild theme={theme.grand} />
</div>
)
Child.foo = 'BAR'
Child.themeTypes = {
heading: ThemeTypes.className,
body: ThemeTypes.className,
grand: ThemeTypes.themeOf(GrandChild)
}
Child.propTypes = {
theme: propTypesFromThemeTypes(Child.themeTypes)
}
Child = withThemes({
default: {
heading: 'base_hed',
body: 'base_body',
grand: GrandChild.themes.default
}
})(Child)
// --
var Test = ({ prop1, theme }) => (
<div>
<div className={theme.heading}>FOO</div>
<Child theme={theme.child1} />
<Child theme={theme.child2} />
</div>
)
Test.propTypes = {
prop1: PropTypes.string
}
Test.themeTypes = {
heading: ThemeTypes.className,
child1: ThemeTypes.themeOf(Child),
child2: ThemeTypes.themeOf(Child)
}
Test.propTypes = {
theme: propTypesFromThemeTypes(Test.themeTypes)
}
const THEMES = {
bla: {
heading: 'base_hed',
child1: Child.themes.default.add({
heading: 'child1'
})
},
other: {
heading: 'other_base_hed'
}
}
Test = withThemes(THEMES, THEMES.other)(Test)
// --
// const theme = Test.themes.default.add({
// heading: 'added_heading',
// child1: {
// heading: 'added_heading_grand'
// }
// })
const element = (
<Test prop1={1} theme={Test.themes.blaa} />
)
console.log(html(ReactDOMServer.renderToStaticMarkup(element), { indent_size: 2 }))