forked from robinweser/fela
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFelaComponentFactory.js
More file actions
49 lines (43 loc) · 1.42 KB
/
FelaComponentFactory.js
File metadata and controls
49 lines (43 loc) · 1.42 KB
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
/* @flow */
import { combineRules } from 'fela'
export default function FelaComponentFactory(
createElement: Function,
RendererContext: any,
FelaTheme: Function
): Function {
function FelaComponent({ children, as = 'div', style, ...otherProps }) {
const renderFn = renderer => {
if (renderer.devMode && style == null) {
// eslint-disable-next-line no-console
console.warn(
'"FelaComponent" is being rendered without a style prop\nIf all you need is access to theme, try using "FelaTheme" or the "useFela" hook instead'
)
}
return createElement(FelaTheme, undefined, theme => {
// TODO: could optimize perf by not calling combineRules if not necessary
const renderedRule = renderer.renderRule(combineRules(style), {
...otherProps,
theme,
})
if (children instanceof Function) {
return children({
className: !renderer.isNativeRenderer && renderedRule,
style: renderer.isNativeRenderer && renderedRule,
theme,
as,
})
}
return createElement(
as,
{
className: !renderer.isNativeRenderer && renderedRule,
style: renderer.isNativeRenderer && renderedRule,
},
children
)
})
}
return createElement(RendererContext.Consumer, undefined, renderFn)
}
return FelaComponent
}