How to use the @material-ui/utils.chainPropTypes function in @material-ui/utils

To help you get started, we’ve selected a few @material-ui/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mui-org / material-ui / packages / material-ui / src / ListItem / ListItem.js View on Github external
alignItems: PropTypes.oneOf(['flex-start', 'center']),
  /**
   * If `true`, the list item will be focused during the first mount.
   * Focus will also be triggered if the value changes from false to true.
   */
  autoFocus: PropTypes.bool,
  /**
   * If `true`, the list item will be a button (using `ButtonBase`). Props intended
   * for `ButtonBase` can then be applied to `ListItem`.
   */
  button: PropTypes.bool,
  /**
   * The content of the component. If a `ListItemSecondaryAction` is used it must
   * be the last child.
   */
  children: chainPropTypes(PropTypes.node, props => {
    const children = React.Children.toArray(props.children);

    // React.Children.toArray(props.children).findLastIndex(isListItemSecondaryAction)
    let secondaryActionIndex = -1;
    for (let i = children.length - 1; i >= 0; i -= 1) {
      const child = children[i];
      if (isMuiElement(child, ['ListItemSecondaryAction'])) {
        secondaryActionIndex = i;
        break;
      }
    }

    //  is ListItemSecondaryAction the last child of ListItem
    if (secondaryActionIndex !== -1 && secondaryActionIndex !== children.length - 1) {
      return new Error(
        'Material-UI: you used an element after ListItemSecondaryAction. ' +
github mui-org / material-ui / packages / material-ui-styles / src / withTheme / withTheme.js View on Github external
);
      }
    }

    const WithTheme = React.forwardRef(function WithTheme(props, ref) {
      const { innerRef, ...other } = props;
      const theme = useTheme() || defaultTheme;
      return ;
    });

    WithTheme.propTypes = {
      /**
       * Use that prop to pass a ref to the decorated component.
       * @deprecated
       */
      innerRef: chainPropTypes(PropTypes.oneOfType([PropTypes.func, PropTypes.object]), props => {
        if (props.innerRef == null) {
          return null;
        }

        return new Error(
          'Material-UI: the `innerRef` prop is deprecated and will be removed in v5. ' +
            'Refs are now automatically forwarded to the inner component.',
        );
      }),
    };

    if (process.env.NODE_ENV !== 'production') {
      WithTheme.displayName = `WithTheme(${getDisplayName(Component)})`;
    }

    hoistNonReactStatics(WithTheme, Component);
github mui-org / material-ui / packages / material-ui-styles / src / styled / styled.js View on Github external
StyledComponent.propTypes = {
      /**
       * A render function or node.
       */
      children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
      /**
       * @ignore
       */
      className: PropTypes.string,
      /**
       * If `true`, the component will recycle it's children DOM element.
       * It's using `React.cloneElement` internally.
       *
       * This prop will be deprecated and removed in v5
       */
      clone: chainPropTypes(PropTypes.bool, props => {
        if (props.clone && props.component) {
          return new Error('You can not use the clone and component prop at the same time.');
        }
        return null;
      }),
      /**
       * The component used for the root node.
       * Either a string to use a DOM element or a component.
       */
      component: PropTypes.elementType,
      ...propTypes,
    };

    if (process.env.NODE_ENV !== 'production') {
      StyledComponent.displayName = `Styled(${classNamePrefix})`;
    }
github mui-org / material-ui / packages / material-ui / src / ExpansionPanel / ExpansionPanel.js View on Github external
{summary}
      
      
        <div role="region" id="{summary.props['aria-controls']}" aria-labelledby="{summary.props.id}">
          {children}
        </div>
      
    
  );
});

ExpansionPanel.propTypes = {
  /**
   * The content of the expansion panel.
   */
  children: chainPropTypes(PropTypes.node.isRequired, props =&gt; {
    const summary = React.Children.toArray(props.children)[0];
    if (isFragment(summary)) {
      return new Error(
        "Material-UI: the ExpansionPanel doesn't accept a Fragment as a child. " +
          'Consider providing an array instead.',
      );
    }

    if (!React.isValidElement(summary)) {
      return new Error(
        'Material-UI: expected the first child of ExpansionPanel to be a valid element.',
      );
    }

    return null;
  }),
github mui-org / material-ui / packages / material-ui / src / CardMedia / CardMedia.js View on Github external
)}
      ref={ref}
      style={composedStyle}
      src={isMediaComponent ? image || src : undefined}
      {...other}
    &gt;
      {children}
    
  );
});

CardMedia.propTypes = {
  /**
   * The content of the component.
   */
  children: chainPropTypes(PropTypes.node, props =&gt; {
    if (!props.children &amp;&amp; !props.image &amp;&amp; !props.src) {
      return new Error('Material-UI: either `children`, `image` or `src` prop must be specified.');
    }
    return null;
  }),
  /**
   * Override or extend the styles applied to the component.
   * See [CSS API](#css) below for more details.
   */
  classes: PropTypes.object.isRequired,
  /**
   * @ignore
   */
  className: PropTypes.string,
  /**
   * Component for rendering image.
github mui-org / material-ui / packages / material-ui / src / Slider / Slider.js View on Github external
onBlur={handleBlur}
              onMouseOver={handleMouseOver}
              onMouseLeave={handleMouseLeave}
            /&gt;
          
        );
      })}
    
  );
});

Slider.propTypes = {
  /**
   * The label of the slider.
   */
  'aria-label': chainPropTypes(PropTypes.string, props =&gt; {
    const range = Array.isArray(props.value || props.defaultValue);

    if (range &amp;&amp; props['aria-label'] != null) {
      return new Error(
        'Material-UI: you need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.',
      );
    }

    return null;
  }),
  /**
   * The id of the element containing a label for the slider.
   */
  'aria-labelledby': PropTypes.string,
  /**
   * A string value that provides a user-friendly name for the current value of the slider.
github mui-org / material-ui / packages / material-ui / src / Slider / Slider.js View on Github external
if (range && props['aria-label'] != null) {
      return new Error(
        'Material-UI: you need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.',
      );
    }

    return null;
  }),
  /**
   * The id of the element containing a label for the slider.
   */
  'aria-labelledby': PropTypes.string,
  /**
   * A string value that provides a user-friendly name for the current value of the slider.
   */
  'aria-valuetext': chainPropTypes(PropTypes.string, props => {
    const range = Array.isArray(props.value || props.defaultValue);

    if (range && props['aria-valuetext'] != null) {
      return new Error(
        'Material-UI: you need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.',
      );
    }

    return null;
  }),
  /**
   * Override or extend the styles applied to the component.
   * See [CSS API](#css) below for more details.
   */
  classes: PropTypes.object.isRequired,
  /**
github mui-org / material-ui / packages / material-ui-lab / src / Rating / Rating.js View on Github external
*/
  icon: PropTypes.node,
  /**
   * The component containing the icon.
   */
  IconContainerComponent: PropTypes.elementType,
  /**
   * Maximum rating.
   */
  max: PropTypes.number,
  /**
   * The name attribute of the radio `input` elements.
   * If `readOnly` is false, the prop is required,
   * this input name`should be unique within the parent form.
   */
  name: chainPropTypes(PropTypes.string, props => {
    if (!props.readOnly && !props.name) {
      return new Error(
        [
          'Material-UI: the prop `name` is required (when `readOnly` is false).',
          'Additionally, the input name should be unique within the parent form.',
        ].join('\n'),
      );
    }
    return null;
  }),
  /**
   * Callback fired when the value changes.
   *
   * @param {object} event The event source of the callback.
   * @param {number} value The new value.
   */
github mui-org / material-ui / packages / material-ui / src / Popper / Popper.js View on Github external
);
});

Popper.propTypes = {
  /**
   * This is the reference element, or a function that returns the reference element,
   * that may be used to set the position of the popover.
   * The return value will passed as the reference object of the Popper
   * instance.
   *
   * The reference element should be an HTML Element instance or a referenceObject:
   * https://popper.js.org/popper-documentation.html#referenceObject.
   */
  anchorEl: chainPropTypes(PropTypes.oneOfType([PropTypes.object, PropTypes.func]), props =&gt; {
    if (props.open) {
      const resolvedAnchorEl = getAnchorEl(props.anchorEl);
      const containerWindow = ownerWindow(resolvedAnchorEl);

      if (resolvedAnchorEl instanceof containerWindow.Element) {
        const box = resolvedAnchorEl.getBoundingClientRect();

        if (
          process.env.NODE_ENV !== 'test' &amp;&amp;
          box.top === 0 &amp;&amp;
          box.left === 0 &amp;&amp;
          box.right === 0 &amp;&amp;
          box.bottom === 0
        ) {
          return new Error(
            [
github mui-org / material-ui / packages / material-ui / src / TablePagination / TablePagination.js View on Github external
* Callback fired when the page is changed.
   *
   * @param {object} event The event source of the callback.
   * @param {number} page The page selected.
   */
  onChangePage: PropTypes.func.isRequired,
  /**
   * Callback fired when the number of rows per page is changed.
   *
   * @param {object} event The event source of the callback.
   */
  onChangeRowsPerPage: PropTypes.func,
  /**
   * The zero-based index of the current page.
   */
  page: chainPropTypes(PropTypes.number.isRequired, props =&gt; {
    const { count, page, rowsPerPage } = props;
    const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
    if (page &lt; 0 || page &gt; newLastPage) {
      return new Error(
        'Material-UI: the page prop of a TablePagination is out of range ' +
          `(0 to ${newLastPage}, but page is ${page}).`,
      );
    }
    return null;
  }),
  /**
   * The number of rows per page.
   */
  rowsPerPage: PropTypes.number.isRequired,
  /**
   * Customizes the options of the rows per page select field. If less than two options are