Skip to content

Commit

Permalink
[core] Export core utils modules from barrel (#20354)
Browse files Browse the repository at this point in the history
  • Loading branch information
NMinhNguyen authored Apr 2, 2020
1 parent eb2decb commit c7c8f91
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/material-ui/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useForkRef from '../utils/useForkRef';
import useEventCallback from '../utils/useEventCallback';
import withStyles from '../styles/withStyles';
import NoSsr from '../NoSsr';
import { useIsFocusVisible } from '../utils/focusVisible';
import useIsFocusVisible from '../utils/useIsFocusVisible';
import TouchRipple from './TouchRipple';

export const styles = {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Link/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clsx from 'clsx';
import capitalize from '../utils/capitalize';
import withStyles from '../styles/withStyles';
import { elementTypeAcceptingRef } from '@material-ui/utils';
import { useIsFocusVisible } from '../utils/focusVisible';
import useIsFocusVisible from '../utils/useIsFocusVisible';
import useForkRef from '../utils/useForkRef';
import Typography from '../Typography';

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { chainPropTypes } from '@material-ui/utils';
import withStyles from '../styles/withStyles';
import useTheme from '../styles/useTheme';
import { fade, lighten, darken } from '../styles/colorManipulator';
import { useIsFocusVisible } from '../utils/focusVisible';
import useIsFocusVisible from '../utils/useIsFocusVisible';
import ownerDocument from '../utils/ownerDocument';
import useEventCallback from '../utils/useEventCallback';
import useForkRef from '../utils/useForkRef';
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Grow from '../Grow';
import Popper from '../Popper';
import useForkRef from '../utils/useForkRef';
import setRef from '../utils/setRef';
import { useIsFocusVisible } from '../utils/focusVisible';
import useIsFocusVisible from '../utils/useIsFocusVisible';
import useControlled from '../utils/useControlled';
import useTheme from '../styles/useTheme';

Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import * as colors from './colors';
export { colors };
export * from './styles';

export * from './utils';

export { default as AppBar } from './AppBar';
export * from './AppBar';

Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as colors from './colors';
export { colors };
export * from './styles';

export * from './utils';

export { default as AppBar } from './AppBar';
export * from './AppBar';

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/capitalize.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function capitalize(str: string): string;
export default function capitalize(string: string): string;
4 changes: 1 addition & 3 deletions packages/material-ui/src/utils/createSvgIcon.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import SvgIcon from '@material-ui/core/SvgIcon';

declare function createSvgIcon(path: React.ReactNode, displayName: string): typeof SvgIcon;

export default createSvgIcon;
export default function createSvgIcon(path: React.ReactNode, displayName: string): typeof SvgIcon;
8 changes: 8 additions & 0 deletions packages/material-ui/src/utils/debounce.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Cancelable {
clear(): void;
}

export default function debounce<T extends (...args: any[]) => any>(
func: T,
wait?: number,
): T & Cancelable;
1 change: 1 addition & 0 deletions packages/material-ui/src/utils/deprecatedPropType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function deprecatedPropType<T>(validator: T, reason: string): T;
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/focusVisible.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert } from 'chai';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { createMount } from '@material-ui/core/test-utils';
import { teardown as teardownFocusVisible, useIsFocusVisible } from './focusVisible';
import useIsFocusVisible, { teardown as teardownFocusVisible } from './useIsFocusVisible';
import useForkRef from './useForkRef';

function dispatchFocusVisible(element) {
Expand Down
13 changes: 13 additions & 0 deletions packages/material-ui/src/utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
export { default as capitalize } from './capitalize';
export { default as createChainedFunction } from './deprecatedPropType';
export { default as createSvgIcon } from './createSvgIcon';
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 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';
6 changes: 4 additions & 2 deletions packages/material-ui/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export { default as capitalize } from './capitalize';
export { default as createChainedFunction } from './deprecatedPropType';
export { default as createSvgIcon } from './createSvgIcon';
export { default as debounce } from './debounce';
export { default as deprecatedPropType } from './deprecatedPropType';
export { default as isMuiElement } from './isMuiElement';
export { default as createSvgIcon } from './createSvgIcon';
export { default as ownerDocument } from './ownerDocument';
export { default as ownerWindow } from './ownerWindow';
export { default as requirePropFactory } from './requirePropFactory';
Expand All @@ -10,4 +12,4 @@ 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 { useIsFocusVisible } from './focusVisible';
export { default as useIsFocusVisible } from './useIsFocusVisible';
1 change: 1 addition & 0 deletions packages/material-ui/src/utils/ownerDocument.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function ownerDocument(node?: Node): Document;
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/ownerWindow.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function ownerWindow(node: Node): Window;
export default function ownerWindow(node?: Node): Window;
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/setRef.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO v5: make it private
// TODO v5: consider to make it private
export default function setRef(ref, value) {
if (typeof ref === 'function') {
ref(value);
Expand Down
7 changes: 7 additions & 0 deletions packages/material-ui/src/utils/unsupportedProp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function unsupportedProp(
props: { [key: string]: any },
propName: string,
componentName: string,
location: string,
propFullName: string,
): Error | null;
5 changes: 5 additions & 0 deletions packages/material-ui/src/utils/useEventCallback.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Cancelable {
clear(): void;
}

export default function useEventCallback(...args: any[]): void;
5 changes: 5 additions & 0 deletions packages/material-ui/src/utils/useIsFocusVisible.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function useIsFocusVisible(): {
isFocusVisible: (event: React.ChangeEvent) => boolean;
onBlurVisible: () => void;
ref: React.Ref<unknown>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function handleBlurVisible() {
}, 100);
}

export function useIsFocusVisible() {
export default function useIsFocusVisible() {
const ref = React.useCallback((instance) => {
const node = ReactDOM.findDOMNode(instance);
if (node != null) {
Expand Down

0 comments on commit c7c8f91

Please sign in to comment.