|
1 |
| -import React, { useEffect, useState, useContext } from 'react' |
2 |
| -import { isFn, isStr } from '@exah/utils' |
3 |
| -import isPropValid from '@emotion/is-prop-valid' |
| 1 | +import { useContext } from 'react' |
4 | 2 | import { ThemeContext } from '@emotion/core'
|
| 3 | +import isPropValid from '@emotion/is-prop-valid' |
5 | 4 | import { createBaseFactory } from 'react-styled-base'
|
6 | 5 |
|
7 | 6 | export const createBase = createBaseFactory({ filter: isPropValid })
|
8 | 7 | export const blacklistOf = (styles) => Object.keys(Object(styles.propTypes))
|
9 | 8 |
|
10 |
| -export const getDisplayName = (comp, fallback = 'Component') => |
11 |
| - (isStr(comp) ? comp : (comp.displayName || comp.name || fallback)) |
12 |
| - |
13 |
| -export const mapProps = (fn) => (Comp) => { |
14 |
| - const HOC = (props) => ( |
15 |
| - <Comp {...fn(props)} /> |
16 |
| - ) |
17 |
| - |
18 |
| - HOC.displayName = `mapProps(${getDisplayName(Comp)})` |
19 |
| - return HOC |
20 |
| -} |
21 |
| - |
22 |
| -export const defaultProps = (data) => mapProps((props) => ({ |
23 |
| - ...isFn(data) ? data(props) : data, |
24 |
| - ...props |
25 |
| -})) |
26 |
| - |
27 |
| -export const withProps = (data) => mapProps((props) => ({ |
28 |
| - ...props, |
29 |
| - ...isFn(data) ? data(props) : data |
30 |
| -})) |
31 |
| - |
32 |
| -export function useIsMounted () { |
33 |
| - const [ isMounted, setIsMounted ] = useState(false) |
34 |
| - |
35 |
| - useEffect(() => setIsMounted(true), []) |
36 |
| - |
37 |
| - return isMounted |
38 |
| -} |
39 |
| - |
40 | 9 | export function useTheme () {
|
41 | 10 | return useContext(ThemeContext)
|
42 | 11 | }
|
0 commit comments