utils.js
1.07 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
// @flow
import * as React from 'react'
import isPropValid from '@emotion/is-prop-valid'
export type Interpolations = Array<any>
export const testOmitPropsOnStringTag: (key: string) => boolean = isPropValid
export const testOmitPropsOnComponent = (key: string) =>
key !== 'theme' && key !== 'innerRef'
export const testAlwaysTrue = () => true
export const pickAssign: (
testFn: (key: string) => boolean,
target: {},
...sources: Array<{}>
) => Object = function(testFn, target) {
let i = 2
let length = arguments.length
for (; i < length; i++) {
let source = arguments[i]
let key
for (key in source) {
if (testFn(key)) {
target[key] = source[key]
}
}
}
return target
}
export type StyledOptions = {
label?: string,
shouldForwardProp?: string => boolean,
target?: string
}
type CreateStyledComponent = (...args: Interpolations) => *
type BaseCreateStyled = (
tag: React.ElementType,
options?: StyledOptions
) => CreateStyledComponent
export type CreateStyled = BaseCreateStyled & {
[key: string]: CreateStyledComponent
}