forked from emotion-js/emotion
/
utils.js
47 lines (40 loc) · 1.26 KB
/
utils.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
// @flow
import * as React from 'react'
import type { ElementType } from 'react'
import isPropValid from '@emotion/is-prop-valid'
export type Interpolations = Array<any>
export type StyledOptions = {
label?: string,
shouldForwardProp?: string => boolean,
target?: string
}
export type StyledComponent = {
(Interpolations): React$Node,
withComponent: (
nextTag: ElementType,
nextOptions?: StyledOptions
) => StyledComponent,
displayName: string,
defaultProps: any,
__emotion_real: StyledComponent,
__emotion_base: any,
__emotion_styles: any,
__emotion_forwardProp: any,
toString: () => string
}
const testOmitPropsOnStringTag = isPropValid
const testOmitPropsOnComponent = (key: string) =>
key !== 'theme' && key !== 'innerRef'
export const getDefaultShouldForwardProp = (tag: React.ElementType) =>
typeof tag === 'string' &&
// 96 is one less than the char code
// for "a" so this is checking that
// it's a lowercase character
tag.charCodeAt(0) > 96
? testOmitPropsOnStringTag
: testOmitPropsOnComponent
export type CreateStyledComponent = (...args: Interpolations) => StyledComponent
export type CreateStyled = {
(tag: React.ElementType, options?: StyledOptions): CreateStyledComponent,
[key: string]: CreateStyledComponent
}