-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcreateStyled.js
More file actions
35 lines (27 loc) · 825 Bytes
/
createStyled.js
File metadata and controls
35 lines (27 loc) · 825 Bytes
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
import styled from './styled'
import type {
BaseStylesType,
ComponentStyleType,
StyledType,
StyledElementType,
} from './types'
const createStyled = (jss: Function) => (baseStyles: BaseStylesType = {}): StyledType => {
let sheet
const mountSheet = () => {
if (!sheet) {
sheet = jss.createStyleSheet(baseStyles, {
link: true,
meta: 'styled-jss',
}).attach()
}
return sheet
}
const styledWrapper = element =>
(...ownStyle: ComponentStyleType[]): StyledElementType =>
styled({element, ownStyle, mountSheet, jss})
Object.defineProperty(styledWrapper, 'sheet', ({
get: () => sheet,
}: Object)) // https://github.com/facebook/flow/issues/285
return Object.assign(styledWrapper, {jss, mountSheet, styles: baseStyles})
}
export default createStyled