Blame view

天文台pc/tianwentai-ui/node_modules/@mui/system/Grid/deleteLegacyGridProps.js 1.45 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
  "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = deleteLegacyGridProps;
  const getLegacyGridWarning = propName => {
    if (['item', 'zeroMinWidth'].includes(propName)) {
      return `The \`${propName}\` prop has been removed and is no longer necessary. You can safely remove it.`;
    }
  
    // #host-reference
    return `The \`${propName}\` prop has been removed. See https://mui.com/material-ui/migration/upgrade-to-grid-v2/ for migration instructions.`;
  };
  const warnedAboutProps = [];
  
  /**
   * Deletes the legacy Grid component props from the `props` object and warns once about them if found.
   *
   * @param {object} props The props object to remove the legacy Grid props from.
   * @param {Breakpoints} breakpoints The breakpoints object.
   */
  function deleteLegacyGridProps(props, breakpoints) {
    const propsToWarn = [];
    if (props.item !== undefined) {
      delete props.item;
      propsToWarn.push('item');
    }
    if (props.zeroMinWidth !== undefined) {
      delete props.zeroMinWidth;
      propsToWarn.push('zeroMinWidth');
    }
    breakpoints.keys.forEach(breakpoint => {
      if (props[breakpoint] !== undefined) {
        propsToWarn.push(breakpoint);
        delete props[breakpoint];
      }
    });
    if (process.env.NODE_ENV !== 'production') {
      propsToWarn.forEach(prop => {
        if (!warnedAboutProps.includes(prop)) {
          warnedAboutProps.push(prop);
          console.warn(`MUI Grid: ${getLegacyGridWarning(prop)}\n`);
        }
      });
    }
  }