Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/modules/components/AdManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/core/utils';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/utils';

export const AdContext = React.createContext();

Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/BundleSizeIcon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

export default createSvgIcon(
<g fill="currentColor" fillRule="nonzero">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/FigmaIcon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

export default createSvgIcon(
<g fillRule="nonzero" fill="none">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/MaterialDesignIcon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

export default createSvgIcon(
<g fill="none" fillRule="evenodd">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/SketchIcon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

export default createSvgIcon(
<g fillRule="nonzero" fill="none">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSelector } from 'react-redux';
import useMediaQuery from '@material-ui/core/useMediaQuery';
import { enUS, zhCN, faIR, ruRU, ptBR, esES, frFR, deDE, jaJP } from '@material-ui/core/locale';
import { blue, pink } from '@material-ui/core/colors';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/core/utils';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/utils';
import { getCookie } from 'docs/src/modules/utils/helpers';
import useLazyCSS from 'docs/src/modules/utils/useLazyCSS';

Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/W3CIcon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

export default createSvgIcon(
<g fillRule="nonzero" fill="none">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/icons/CreateSvgIcon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

const useStyles = makeStyles((theme) => ({
root: {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/icons/CreateSvgIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
import { createSvgIcon } from '@material-ui/core/utils';
import { createSvgIcon } from '@material-ui/core/SvgIcon';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/customization/color/ColorTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import CheckIcon from '@material-ui/icons/Check';
import Slider from '@material-ui/core/Slider';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import { DispatchContext } from 'docs/src/modules/components/ThemeContext';
import ColorDemo from './ColorDemo';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import List, {
} from '@material-ui/core/List';
import Dialog, { DialogTitle } from '@material-ui/core/Dialog';
import {
withMobileDialog,
DialogActions,
DialogContent,
DialogContentText,
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-icons/src/utils/createSvgIcon.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { createSvgIcon as default } from '@material-ui/core/utils';
export { createSvgIcon as default } from '@material-ui/core/SvgIcon';
3 changes: 1 addition & 2 deletions packages/material-ui-lab/src/LoadingButton/LoadingButton.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { chainPropTypes } from '@material-ui/utils';
import { capitalize } from '@material-ui/core/utils';
import { capitalize, chainPropTypes } from '@material-ui/utils';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import CircularProgress from '@material-ui/core/CircularProgress';
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/SliderStyled/SliderStyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
lighten,
darken,
} from '@material-ui/core/styles';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import SliderUnstyled from '../SliderUnstyled';
import ValueLabelStyled from './ValueLabelStyled';

Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-lab/src/SliderUnstyled/SliderUnstyled.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { chainPropTypes } from '@material-ui/utils';
import {
chainPropTypes,
useIsFocusVisible,
unstable_useEnhancedEffect as useEnhancedEffect,
ownerDocument,
useEventCallback,
useForkRef,
capitalize,
useControlled,
} from '@material-ui/core/utils';
} from '@material-ui/utils';
import ValueLabelComponent from './ValueLabelUnstyled';

function asc(a, b) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import clsx from 'clsx';

const getUtilityClass = (name) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/Timeline/Timeline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import { withStyles } from '@material-ui/core/styles';
import TimelineContext from './TimelineContext';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import { withStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import TimelineContext from '../Timeline/TimelineContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/TimelineDot/TimelineDot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import { withStyles, useThemeVariants } from '@material-ui/core/styles';

export const styles = (theme) => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/TimelineItem/TimelineItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { capitalize, isMuiElement } from '@material-ui/core/utils';
import { capitalize, isMuiElement } from '@material-ui/utils';
import { withStyles } from '@material-ui/core/styles';
import TimelineContext from '../Timeline/TimelineContext';
import TimelineItemContext from './TimelineItemContext';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { capitalize } from '@material-ui/core/utils';
import { capitalize } from '@material-ui/utils';
import { withStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import TimelineContext from '../Timeline/TimelineContext';
Expand Down
8 changes: 6 additions & 2 deletions packages/material-ui-lab/src/TreeItem/TreeItem.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { elementTypeAcceptingRef } from '@material-ui/utils';
import {
elementTypeAcceptingRef,
ownerDocument,
useForkRef,
unsupportedProp,
} from '@material-ui/utils';
import Collapse from '@material-ui/core/Collapse';
import { alpha, withStyles } from '@material-ui/core/styles';
import { ownerDocument, useForkRef, unsupportedProp } from '@material-ui/core/utils';
import TreeViewContext from '../TreeView/TreeViewContext';
import { DescendantProvider, useDescendant } from '../TreeView/descendants';
import TreeItemContent from './TreeItemContent';
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useForkRef,
ownerDocument,
unstable_useId as useId,
} from '@material-ui/core/utils';
} from '@material-ui/utils';
import TreeViewContext from './TreeViewContext';
import { DescendantProvider } from './descendants';

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/TreeView/descendants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/core/utils';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/utils';

/** Credit: https://github.com/reach/reach-ui/blob/86a046f54d53b6420e392b3fa56dd991d9d4e458/packages/descendants/README.md
* Modified slightly to suit our purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { stub } from 'sinon';
import { SheetsRegistry } from 'jss';
import { Input } from '@material-ui/core';
import { createClientRender, screen } from 'test/utils';
import { isMuiElement } from '@material-ui/core/utils';
import { isMuiElement } from '@material-ui/utils';
import { createMuiTheme } from '@material-ui/core/styles';
import StylesProvider from '../StylesProvider';
import createGenerateClassName from '../createGenerateClassName';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { expect } from 'chai';
import { createClientRender } from 'test/utils';
import { Input } from '@material-ui/core';
import { isMuiElement } from '@material-ui/core/utils';
import { isMuiElement } from '@material-ui/utils';
import PropTypes from 'prop-types';
import withTheme from './withTheme';
import ThemeProvider from '../ThemeProvider';
Expand Down
13 changes: 13 additions & 0 deletions packages/material-ui-utils/src/capitalize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// TODO: error TS7016: Could not find a declaration file for module '../macros/MuiError.macro'. '/tmp/material-ui/packages/material-ui-utils/macros/MuiError.macro.js' implicitly has an 'any' type.
// import MuiError from '../macros/MuiError.macro';
// It should to be noted that this function isn't equivalent to `text-transform: capitalize`.
//
// A strict capitalization should uppercase the first letter of each word a the sentence.
// We only handle the first word.
export default function capitalize(string: string): string {
if (typeof string !== 'string') {
throw new Error('Material-UI: capitalize(string) expects a string argument.');
}

return string.charAt(0).toUpperCase() + string.slice(1);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type ChainedFunction = ((...args: any[]) => void) | undefined | null;

/**
* Safe chained function
*
Expand All @@ -6,7 +8,9 @@
* @param {function} functions to chain
* @returns {function|null}
*/
export default function createChainedFunction(...funcs) {
export default function createChainedFunction(
...funcs: ChainedFunction[]
): (...args: any[]) => never {
return funcs.reduce(
(acc, func) => {
if (func == null) {
Expand All @@ -22,10 +26,12 @@ export default function createChainedFunction(...funcs) {
}

return function chainedFunction(...args) {
// @ts-ignore
acc.apply(this, args);
// @ts-ignore
func.apply(this, args);
};
},
() => {},
);
) as (...args: any[]) => never;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
export interface Cancelable {
clear(): void;
}

// Corresponds to 10 frames at 60 Hz.
// A few bytes payload overhead when lodash/debounce is ~3 kB and debounce ~300 B.
export default function debounce(func, wait = 166) {
let timeout;
function debounced(...args) {
export default function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number = 166,
): T & Cancelable {
let timeout: any;
function debounced(...args: any[]) {
const later = () => {
// @ts-ignore
func.apply(this, args);
};
clearTimeout(timeout);
Expand All @@ -14,5 +22,5 @@ export default function debounce(func, wait = 166) {
clearTimeout(timeout);
};

return debounced;
return debounced as T & Cancelable;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default function deprecatedPropType(validator, reason) {
export default function deprecatedPropType<T>(validator: T, reason: string): T | Function {
if (process.env.NODE_ENV === 'production') {
return () => null;
}

// @ts-ignore
return (props, propName, componentName, location, propFullName) => {
const componentNameSafe = componentName || '<<anonymous>>';
const propFullNameSafe = propFullName || propName;
Expand Down
18 changes: 18 additions & 0 deletions packages/material-ui-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,21 @@ export { default as getDisplayName } from './getDisplayName';
export { default as HTMLElementType } from './HTMLElementType';
export { default as ponyfillGlobal } from './ponyfillGlobal';
export { default as refType } from './refType';
export { default as capitalize } from './capitalize';
export { default as createChainedFunction } from './createChainedFunction';
export { default as debounce } from './debounce';
export { default as deprecatedPropType } from './deprecatedPropType';
export { default as isMuiElement } from './isMuiElement';
export { default as ownerDocument } from './ownerDocument';
export { default as ownerWindow } from './ownerWindow';
export { default as requirePropFactory } from './requirePropFactory';
export { default as setRef } from './setRef';
export { default as unstable_useEnhancedEffect } from './useEnhancedEffect';
export { default as unstable_useId } from './useId';
export { default as unsupportedProp } from './unsupportedProp';
export { default as useControlled } from './useControlled';
export { default as useEventCallback } from './useEventCallback';
export { default as useForkRef } from './useForkRef';
export { default as useIsFocusVisible } from './useIsFocusVisible';
export { default as getScrollbarSize } from './getScrollbarSize';
export { detectScrollType, getNormalizedScrollLeft } from './scrollLeft';
40 changes: 40 additions & 0 deletions packages/material-ui-utils/src/isMuiElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';

export type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>;

export interface StyledComponentProps<ClassKey extends string = string> {
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<ClassNameMap<ClassKey>>;
innerRef?: React.Ref<any>;
}

/**
* @private ONLY USE FROM WITHIN mui-org/material-ui
*
* Internal helper type for conform (describeConformance) components that are decorated with `withStyles
* However, we don't declare classes on this type.
* It is recommended to declare them manually with an interface so that each class can have a separate JSDOC.
*/
export type StandardProps<C, Removals extends keyof C = never> = Omit<C, 'classes' | Removals> &
// each component declares it's classes in a separate interface for proper JSDOC
StyledComponentProps<never> & {
ref?: C extends { ref?: infer RefType } ? RefType : React.Ref<unknown>;
// TODO: Remove implicit props. Up to each component.
className?: string;
style?: React.CSSProperties;
};

export type NamedMuiComponent = React.ComponentType & { muiName: string };

export interface NamedMuiElement {
type: NamedMuiComponent;
props: StandardProps<{}>;
key: string | number | null;
}

export default function isMuiElement(element: any, muiNames: string[]): element is NamedMuiElement {
// @ts-ignore
return React.isValidElement(element) && muiNames.indexOf(element.type.muiName) !== -1;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export default function requirePropFactory(componentNameInError) {
export default function requirePropFactory(componentNameInError: string): any {
if (process.env.NODE_ENV === 'production') {
return () => null;
}

const requireProp = (requiredProp) => (
props,
propName,
componentName,
location,
propFullName,
const requireProp = (requiredProp: string): any => (
props: { [key: string]: any },
propName: string,
componentName: string,
location: string,
propFullName: string,
) => {
const propFullNameSafe = propFullName || propName;

Expand Down
Loading