-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcreateStyled.js
More file actions
47 lines (38 loc) · 1.15 KB
/
createStyled.js
File metadata and controls
47 lines (38 loc) · 1.15 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
import styled from './styled'
import type {
BaseStylesType,
ComponentStyleType,
StyledType,
StyledElementAttrsType,
StyledElementType,
TagNameOrStyledElementType
} from './types'
const createStyled = (jss: Function) => (
baseStyles: BaseStylesType = {}
): StyledType => {
let staticSheet
let dynamicSheet
const mountSheets = () => {
if (!staticSheet) {
staticSheet = jss.createStyleSheet(baseStyles, {
meta: 'StaticBaseSheet',
}).attach()
dynamicSheet = jss.createStyleSheet({}, {
link: true,
meta: 'DynamicComponentSheet',
}).attach()
}
return {staticSheet, dynamicSheet}
}
return Object.assign((
tagNameOrStyledElement: TagNameOrStyledElementType,
ownStyle: ComponentStyleType
): StyledElementType => {
const {tagName, style}: StyledElementAttrsType = typeof tagNameOrStyledElement === 'string'
? {tagName: tagNameOrStyledElement, style: {}}
: tagNameOrStyledElement
const elementStyle = {...style, ...ownStyle}
return styled({tagName, baseStyles, elementStyle, mountSheets})
}, {mountSheets, styles: baseStyles})
}
export default createStyled