-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathuseStyledSystemPropsResolver.ts
61 lines (55 loc) · 1.78 KB
/
useStyledSystemPropsResolver.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { getStyleAndFilteredProps } from '../theme/styled-system';
import { useTheme } from './useTheme';
import React from 'react';
import { useNativeBaseConfig } from '../core/NativeBaseContext';
import { useResponsiveQuery } from '../utils/useResponsiveQuery';
import { getStyledSystemPropsAndRestProps } from '../utils/getStyledSystemPropsAndRestProps';
//@ts-ignore
import stableHash from 'stable-hash';
export const useStyledSystemPropsResolver = ({
style: propStyle,
debug,
...props
}: any) => {
const theme = useTheme();
const { currentBreakpoint, config } = useNativeBaseConfig(
'makeStyledComponent'
);
const strictMode = config.strictMode;
const { getResponsiveStyles } = useResponsiveQuery();
const { styledSystemProps, restProps } = getStyledSystemPropsAndRestProps(
props
);
const { style, dataSet, styleFromProps } = React.useMemo(() => {
const { styleSheet, dataSet, styleFromProps } = getStyleAndFilteredProps({
styledSystemProps,
theme,
debug,
currentBreakpoint,
strictMode,
getResponsiveStyles,
});
if (propStyle) {
return { style: [styleSheet.box, propStyle], dataSet, styleFromProps };
} else {
return { style: styleSheet.box, dataSet, styleFromProps };
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
// eslint-disable-next-line react-hooks/exhaustive-deps
stableHash(styledSystemProps),
theme,
debug,
currentBreakpoint,
strictMode,
propStyle,
getResponsiveStyles,
props,
]);
if (process.env.NODE_ENV === 'development' && debug) {
/* eslint-disable-next-line */
console.log('style,resprops', currentBreakpoint);
}
restProps.dataSet = { ...restProps.dataSet, ...dataSet };
return [style, restProps, styleFromProps];
};