Skip to content

Commit

Permalink
chore: update use to hooks (#1165)
Browse files Browse the repository at this point in the history
* chore: update use to hooks

* fix: copyright

Co-authored-by: David Menendez <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 17, 2021
1 parent 9113a26 commit 3131a77
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import {
} from 'carbon-components-react';
import { CreateInfluencer } from '../CreateInfluencer';
import { ActionSet } from '../ActionSet';
import { usePreviousValue } from '../../global/js/use/usePreviousValue';
import { useValidCreateStepCount } from '../../global/js/use/useValidCreateStepCount';
import { useCreateComponentFocus } from '../../global/js/use/useCreateComponentFocus';
import {
usePreviousValue,
useValidCreateStepCount,
useCreateComponentFocus,
} from '../../global/js/hooks';
import { hasValidChildType } from '../../global/js/utils/hasValidChildType';

const blockClass = `${pkg.prefix}--create-full-page`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import { CreateInfluencer } from '../CreateInfluencer';
import { CreateTearsheetDivider } from './CreateTearsheetDivider';
import { carbon, pkg } from '../../settings';
import { CREATE_TEARSHEET_SECTION, CREATE_TEARSHEET_STEP } from './constants';
import { usePreviousValue } from '../../global/js/use/usePreviousValue';
import { useValidCreateStepCount } from '../../global/js/use/useValidCreateStepCount';
import { useResetCreateComponent } from '../../global/js/use/useResetCreateComponent';
import { useCreateComponentFocus } from '../../global/js/use/useCreateComponentFocus';
import { useCreateComponentStepChange } from '../../global/js/use/useCreateComponentStepChange';
import {
usePreviousValue,
useValidCreateStepCount,
useResetCreateComponent,
useCreateComponentFocus,
useCreateComponentStepChange,
} from '../../global/js/hooks';
import { hasValidChildType } from '../../global/js/utils/hasValidChildType';

const componentName = 'CreateTearsheet';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useEffect, useState, useRef } from 'react';
// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import useClickOutside from '../../global/js/use/useClickOutside';
import { useClickOutside } from '../../global/js/hooks';
import { pkg } from '../../settings';
import { timeAgo } from './utils';
import { NotificationsEmptyState } from '../EmptyStates/NotificationsEmptyState';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { extractShapesArray } from '../../global/js/utils/props-helper';
import { layout05, baseFontSize } from '@carbon/layout';
import cx from 'classnames';
import { useResizeDetector } from 'react-resize-detector';
import { useWindowResize, useWindowScroll } from '../../global/js/use';
import { useWindowResize, useWindowScroll } from '../../global/js/hooks';
import {
BreadcrumbItem,
Grid,
Expand Down
15 changes: 15 additions & 0 deletions packages/cloud-cognitive/src/global/js/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright IBM Corp. 2020, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

export { useWindowScroll } from './useWindowScroll';
export { useWindowResize } from './useWindowResize';
export { useClickOutside } from './useClickOutside';
export { useCreateComponentFocus } from './useCreateComponentFocus';
export { useCreateComponentStepChange } from './useCreateComponentStepChange';
export { usePreviousValue } from './usePreviousValue';
export { useResetCreateComponent } from './useResetCreateComponent';
export { useValidCreateStepCount } from './useValidCreateStepCount';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useEffect } from 'react';

const useOutsideClick = (ref, callback) => {
export const useClickOutside = (ref, callback) => {
const handleClick = (event) => {
if (ref.current && !ref.current.contains(event.target)) {
callback();
Expand All @@ -22,5 +22,3 @@ const useOutsideClick = (ref, callback) => {
};
});
};

export default useOutsideClick;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getWindowSize = () => {
return { innerHeight, innerWidth, outerHeight, outerWidth };
};

export function useWindowResize(effect, deps, throttleInterval = 0) {
export const useWindowResize = (effect, deps, throttleInterval = 0) => {
const windowSize = useRef({});
const throttleTimeout = useRef(null);

Expand Down Expand Up @@ -45,4 +45,4 @@ export function useWindowResize(effect, deps, throttleInterval = 0) {
return () => window.removeEventListener('resize', handleResize);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getScrollPosition = () => {
return { scrollX, scrollY };
};

export function useWindowScroll(effect, deps, throttleInterval = 0) {
export const useWindowScroll = (effect, deps, throttleInterval = 0) => {
const scrollPosition = useRef({});
const throttleTimeout = useRef(null);

Expand Down Expand Up @@ -49,4 +49,4 @@ export function useWindowScroll(effect, deps, throttleInterval = 0) {
return () => window.removeEventListener('scroll', handleScroll);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}
};
2 changes: 0 additions & 2 deletions packages/cloud-cognitive/src/global/js/use/index.js

This file was deleted.

0 comments on commit 3131a77

Please sign in to comment.