Blame view

天文台pc/tianwentai-ui/node_modules/@mui/system/esm/styleFunctionSx/extendSxProp.js 1.07 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
39
40
41
42
43
44
45
46
47
48
49
50
51
  import { isPlainObject } from '@mui/utils/deepmerge';
  import defaultSxConfig from "./defaultSxConfig.js";
  const splitProps = props => {
    const result = {
      systemProps: {},
      otherProps: {}
    };
    const config = props?.theme?.unstable_sxConfig ?? defaultSxConfig;
    Object.keys(props).forEach(prop => {
      if (config[prop]) {
        result.systemProps[prop] = props[prop];
      } else {
        result.otherProps[prop] = props[prop];
      }
    });
    return result;
  };
  export default function extendSxProp(props) {
    const {
      sx: inSx,
      ...other
    } = props;
    const {
      systemProps,
      otherProps
    } = splitProps(other);
    let finalSx;
    if (Array.isArray(inSx)) {
      finalSx = [systemProps, ...inSx];
    } else if (typeof inSx === 'function') {
      finalSx = (...args) => {
        const result = inSx(...args);
        if (!isPlainObject(result)) {
          return systemProps;
        }
        return {
          ...systemProps,
          ...result
        };
      };
    } else {
      finalSx = {
        ...systemProps,
        ...inSx
      };
    }
    return {
      ...otherProps,
      sx: finalSx
    };
  }