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

UI: swap react-sizeme for react-resize-detector #20333

Merged
merged 3 commits into from
Dec 20, 2022
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
3 changes: 2 additions & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@
"axe-core": "^4.2.0",
"global": "^4.4.0",
"lodash": "^4.17.21",
"react-sizeme": "^3.0.1"
"react-resize-detector": "^7.1.2"
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
"resize-observer-polyfill": "^1.5.1",
"typescript": "~4.9.3"
},
"peerDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions code/addons/a11y/src/components/A11YPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { A11YPanel } from './A11YPanel';
import { EVENTS } from '../constants';

jest.mock('@storybook/manager-api');

global.ResizeObserver = require('resize-observer-polyfill');
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

const mockedApi = api as jest.Mocked<typeof api>;

const axeResult = {
Expand Down
8 changes: 4 additions & 4 deletions code/addons/a11y/src/components/Report/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { styled } from '@storybook/theming';
import { Badge } from '@storybook/components';
import type { CheckResult } from 'axe-core';
import { SizeMe } from 'react-sizeme';
import ReactResizeDetector from 'react-resize-detector';

const List = styled.div({
display: 'flex',
Expand Down Expand Up @@ -71,14 +71,14 @@ const Rule: FC<RuleProps> = ({ rule }) => {
break;
}
return (
<SizeMe refreshMode="debounce">
{({ size }) => (
<ReactResizeDetector handleWidth handleHeight refreshMode="debounce">
{(size) => (
<Item elementWidth={size.width || 0}>
<StyledBadge status={badgeType}>{formatSeverityText(rule.impact)}</StyledBadge>
<Message>{rule.message}</Message>
</Item>
)}
</SizeMe>
</ReactResizeDetector>
);
};

Expand Down
8 changes: 4 additions & 4 deletions code/addons/a11y/src/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

import { styled } from '@storybook/theming';
import type { NodeResult, Result } from 'axe-core';
import { SizeMe } from 'react-sizeme';
import ReactResizeDetector from 'react-resize-detector';
import HighlightToggle from './Report/HighlightToggle';

import type { RuleType } from './A11YPanel';
Expand Down Expand Up @@ -111,8 +111,8 @@ export const Tabs: React.FC<TabsProps> = ({ tabs }) => {
const highlightToggleId = `${tabs[activeTab].type}-global-checkbox`;
const highlightLabel = `Highlight results`;
return (
<SizeMe refreshMode="debounce">
{({ size }) => (
<ReactResizeDetector handleWidth handleHeight refreshMode="debounce">
{(size) => (
<Container>
<List>
<TabsWrapper>
Expand Down Expand Up @@ -143,6 +143,6 @@ export const Tabs: React.FC<TabsProps> = ({ tabs }) => {
{tabs[activeTab].panel}
</Container>
)}
</SizeMe>
</ReactResizeDetector>
);
};
2 changes: 1 addition & 1 deletion code/addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@storybook/preview-api": "7.0.0-beta.12",
"@storybook/theming": "7.0.0-beta.12",
"global": "^4.4.0",
"react-sizeme": "^3.0.1",
"react-resize-detector": "^7.1.2",
"upath": "^1.2.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions code/addons/jest/src/components/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { FC } from 'react';
import React, { Fragment } from 'react';
import { styled, themes, convert } from '@storybook/theming';
import { ScrollArea, TabsState, Link, Placeholder } from '@storybook/components';
import { SizeMe } from 'react-sizeme';
import Result from './Result';
import ResizeObserver from 'react-resize-detector';
import { Result } from './Result';
import type { Test } from '../hoc/provideJestResult';
import provideJestResult from '../hoc/provideJestResult';
import { provideTests as provideJestResult } from '../hoc/provideJestResult';

const StatusTypes = {
PASSED_TYPE: 'passed',
Expand Down Expand Up @@ -134,8 +134,8 @@ const Content = styled(({ tests, className }: ContentProps) => (
const sortedTestsByCount = [...entries].sort((a, b) => a[1].length - b[1].length);

return (
<SizeMe refreshMode="debounce" key={name}>
{({ size }: { size: any }) => {
<ResizeObserver refreshMode="debounce" key={name}>
{(size) => {
const { width } = size;
return (
<section>
Expand Down Expand Up @@ -259,7 +259,7 @@ const Content = styled(({ tests, className }: ContentProps) => (
</section>
);
}}
</SizeMe>
</ResizeObserver>
);
})}
</div>
Expand Down
2 changes: 0 additions & 2 deletions code/addons/jest/src/components/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,3 @@ export function Result(props: ResultProps) {
</Fragment>
);
}

export default Result;
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 1 addition & 3 deletions code/addons/jest/src/hoc/provideJestResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface HocState {
tests?: Test[];
}

const provideTests = (Component: ComponentType<InjectedProps>) =>
export const provideTests = (Component: ComponentType<InjectedProps>) =>
class TestProvider extends ReactComponent<HocProps, HocState> {
state: HocState = {};

Expand Down Expand Up @@ -82,5 +82,3 @@ const provideTests = (Component: ComponentType<InjectedProps>) =>
return active ? <Component tests={tests} /> : null;
}
};

export default provideTests;
2 changes: 1 addition & 1 deletion code/ui/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"react-dom": "^16.8.0",
"react-draggable": "^4.4.3",
"react-helmet-async": "^1.0.7",
"react-sizeme": "^3.0.1",
"react-resize-detector": "^7.1.2",
"resolve-from": "^5.0.0",
"semver": "^7.3.7",
"store2": "^2.14.2",
Expand Down
16 changes: 9 additions & 7 deletions code/ui/manager/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FC } from 'react';
import React, { useMemo } from 'react';
import sizeMe from 'react-sizeme';
import ResizeObserver from 'react-resize-detector';

import { type State } from '@storybook/manager-api';
import { Symbols } from '@storybook/components';
Expand All @@ -27,14 +27,12 @@ export interface AppProps {
viewMode: State['viewMode'];
layout: State['layout'];
panelCount: number;
size: {
width: number;
height: number;
};
width: number;
height: number;
}

const App = React.memo<AppProps>(
({ viewMode, layout, panelCount, size: { width, height } }) => {
({ viewMode, layout, panelCount, width, height }) => {
let content;

const props = useMemo(
Expand Down Expand Up @@ -109,7 +107,11 @@ const App = React.memo<AppProps>(
}
);

const SizedApp = sizeMe({ monitorHeight: true })(App);
const SizedApp = (props: Omit<AppProps, 'width' | 'height'>) => (
<ResizeObserver>
{({ width, height }) => <App {...props} {...{ width, height }} />}
</ResizeObserver>
);

App.displayName = 'App';

Expand Down
61 changes: 23 additions & 38 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5283,7 +5283,8 @@ __metadata:
axe-core: ^4.2.0
global: ^4.4.0
lodash: ^4.17.21
react-sizeme: ^3.0.1
react-resize-detector: ^7.1.2
resize-observer-polyfill: ^1.5.1
typescript: ~4.9.3
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
Expand Down Expand Up @@ -5496,7 +5497,7 @@ __metadata:
"@storybook/preview-api": 7.0.0-beta.12
"@storybook/theming": 7.0.0-beta.12
global: ^4.4.0
react-sizeme: ^3.0.1
react-resize-detector: ^7.1.2
typescript: ~4.9.3
upath: ^1.2.0
peerDependencies:
Expand Down Expand Up @@ -6728,7 +6729,7 @@ __metadata:
react-dom: ^16.8.0
react-draggable: ^4.4.3
react-helmet-async: ^1.0.7
react-sizeme: ^3.0.1
react-resize-detector: ^7.1.2
resolve-from: ^5.0.0
semver: ^7.3.7
store2: ^2.14.2
Expand Down Expand Up @@ -11462,13 +11463,6 @@ __metadata:
languageName: node
linkType: hard

"batch-processor@npm:1.0.0":
version: 1.0.0
resolution: "batch-processor@npm:1.0.0"
checksum: 048b868811bed4cd03a0eec35264055f0f3fe4ab62f501809dce4a8a7b845d905fa5051b4af8b3c5123181116b1e2b6dfabf608829043b60cf61f4da3a359b60
languageName: node
linkType: hard

"batch@npm:0.6.1":
version: 0.6.1
resolution: "batch@npm:0.6.1"
Expand Down Expand Up @@ -14871,15 +14865,6 @@ __metadata:
languageName: node
linkType: hard

"element-resize-detector@npm:^1.2.2":
version: 1.2.4
resolution: "element-resize-detector@npm:1.2.4"
dependencies:
batch-processor: 1.0.0
checksum: 8c180c8c2a6d5b83678f994e937890f06db6355009cce2bde3c690a45510c92f53f927431926b27db416739aa7b661c7d3afe237d17cd16491ecccfa740cda08
languageName: node
linkType: hard

"ember-cli-babel-plugin-helpers@npm:^1.1.1":
version: 1.1.1
resolution: "ember-cli-babel-plugin-helpers@npm:1.1.1"
Expand Down Expand Up @@ -27476,6 +27461,18 @@ __metadata:
languageName: node
linkType: hard

"react-resize-detector@npm:^7.1.2":
version: 7.1.2
resolution: "react-resize-detector@npm:7.1.2"
dependencies:
lodash: ^4.17.21
peerDependencies:
react: ^16.0.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.0.0 || ^17.0.0 || ^18.0.0
checksum: 2285b0024bcc736c7d5e80279e819835a5e8bef0899778100d2434b1c4b10971e6ae253df073ca96a20cacc47b3c249bc675479e5fc4ec1f6652fcca7f48ec22
languageName: node
linkType: hard

"react-router-dom@npm:6.0.2":
version: 6.0.2
resolution: "react-router-dom@npm:6.0.2"
Expand All @@ -27500,18 +27497,6 @@ __metadata:
languageName: node
linkType: hard

"react-sizeme@npm:^3.0.1":
version: 3.0.2
resolution: "react-sizeme@npm:3.0.2"
dependencies:
element-resize-detector: ^1.2.2
invariant: ^2.2.4
shallowequal: ^1.1.0
throttle-debounce: ^3.0.1
checksum: e6b336bbc1e9de78de5c7177afd398f6ea14c4284af698475f08d34389e9307cbc36c0125a61b158e026f182ae4dd17b13c28683bbc1a371792bccd1e51cccff
languageName: node
linkType: hard

"react-syntax-highlighter@npm:^15.4.5, react-syntax-highlighter@npm:^15.5.0":
version: 15.5.0
resolution: "react-syntax-highlighter@npm:15.5.0"
Expand Down Expand Up @@ -28633,6 +28618,13 @@ __metadata:
languageName: node
linkType: hard

"resize-observer-polyfill@npm:^1.5.1":
version: 1.5.1
resolution: "resize-observer-polyfill@npm:1.5.1"
checksum: 5e882475067f0b97dc07e0f37c3e335ac5bc3520d463f777cec7e894bb273eddbfecb857ae668e6fb6881fd6f6bb7148246967172139302da50fa12ea3a15d95
languageName: node
linkType: hard

"resolve-cwd@npm:^2.0.0":
version: 2.0.0
resolution: "resolve-cwd@npm:2.0.0"
Expand Down Expand Up @@ -31284,13 +31276,6 @@ __metadata:
languageName: node
linkType: hard

"throttle-debounce@npm:^3.0.1":
version: 3.0.1
resolution: "throttle-debounce@npm:3.0.1"
checksum: c8e558479463b7ed8bac30d6b10cc87abd1c9fc64edfce2db4109be1a04acaef5d2d0557f49c1a3845ea07d9f79e6e0389b1b60db0a77c44e5b7a1216596f285
languageName: node
linkType: hard

"through2@npm:^2.0.0, through2@npm:^2.0.2, through2@npm:~2.0.3":
version: 2.0.5
resolution: "through2@npm:2.0.5"
Expand Down