Blame view

天文台pc/tianwentai-ui/node_modules/@emotion/styled/src/utils.ts 1.14 KB
bc518174   王天杨   提交两个项目文件
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
  import * as React from 'react'
  import isPropValid from '@emotion/is-prop-valid'
  import { StyledOptions, ElementType } from './types'
  
  const testOmitPropsOnStringTag = isPropValid
  const testOmitPropsOnComponent = (key: string) => key !== 'theme'
  
  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 const composeShouldForwardProps = (
    tag: ElementType,
    options: StyledOptions | undefined,
    isReal: boolean
  ) => {
    let shouldForwardProp
    if (options) {
      const optionsShouldForwardProp = options.shouldForwardProp
      shouldForwardProp =
        tag.__emotion_forwardProp && optionsShouldForwardProp
          ? (propName: string) =>
              tag.__emotion_forwardProp!(propName) &&
              optionsShouldForwardProp(propName)
          : optionsShouldForwardProp
    }
  
    if (typeof shouldForwardProp !== 'function' && isReal) {
      shouldForwardProp = tag.__emotion_forwardProp
    }
  
    return shouldForwardProp
  }