Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace useWindowSize with Paragon's useWindowSize #1006

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions src/components/IconWithTooltip/IconWithTooltip.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { render, screen, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import IconWithTooltip from './index';
import useWindowSize from '../../hooks/useWindowSize';

jest.mock('./../../hooks/useWindowSize');

const defaultAltText = 'infoooo';
const defaultTooltipText = 'Tooool';
Expand All @@ -17,7 +14,8 @@ const DEFAULT_PROPS = {

describe('<IconWithTooltip />', () => {
it('renders the icon passed to it with alt text', () => {
useWindowSize.mockReturnValue({ width: 800 });
global.innerWidth = 800;
global.dispatchEvent(new Event('resize'));
const { container } = render(<IconWithTooltip {...DEFAULT_PROPS} />);
expect(container.querySelector(`[data-icon=${faInfoCircle.iconName}]`)).toBeTruthy();
});
Expand All @@ -26,7 +24,8 @@ describe('<IconWithTooltip />', () => {
{ windowSize: 700, expectedLocation: 'top' },
].forEach((data) => {
it(`renders the tooltip on the ${data.expectedLocation} for ${data.windowSize}px screen`, () => {
useWindowSize.mockReturnValue({ width: data.windowSize });
global.innerWidth = data.windowSize;
global.dispatchEvent(new Event('resize'));
const { container } = render(<IconWithTooltip {...DEFAULT_PROPS} />);
const icon = container.querySelector(`[data-icon=${faInfoCircle.iconName}]`);
expect(icon).toBeTruthy();
Expand Down
9 changes: 4 additions & 5 deletions src/components/IconWithTooltip/index.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { OverlayTrigger, Tooltip } from '@edx/paragon';
import useWindowSize from '../../hooks/useWindowSize';
import { OverlayTrigger, Tooltip, useWindowSize } from '@edx/paragon';

const IconWithTooltip = ({
icon, altText, tooltipText, placementSm = 'right', placementLg = 'top', trigger = ['hover', 'focus'], breakpoint = 768, iconClassNames = 'ml-1',
}) => {
const windowSize = useWindowSize();
const placement = windowSize.width >= breakpoint ? placementSm : placementLg;
const { width } = useWindowSize();
const placement = width >= breakpoint ? placementSm : placementLg;
return (
<OverlayTrigger
trigger={trigger}
placement={windowSize.width >= breakpoint ? placementSm : placementLg}
placement={placement}
data-testid={`tooltip-${placement}`}
overlay={(
<Tooltip id={`tooltip-${placement}`}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/tests/ValidatedFormControl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const ValidatedFormControlWrapper = ({
formFields: { [formId]: formValue },
};
if (formError) {
contextValue =
{ ...contextValue,
contextValue = {
...contextValue,
errorMap: { [formId]: [formError] },
showErrors: true,
};
Expand Down
1 change: 0 additions & 1 deletion src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as useInterval } from './useInterval';
export { default as useWindowSize } from './useWindowSize';
export { default as useOnMount } from './useOnMount';
35 changes: 0 additions & 35 deletions src/hooks/useWindowSize.jsx

This file was deleted.