Skip to content

Commit

Permalink
Merge branch 'next' into remove-unused-import-in-mdx-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniebigodes authored May 3, 2023
2 parents 51a4c6f + bc93263 commit 425e566
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
39 changes: 15 additions & 24 deletions code/addons/viewport/src/Tool.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-fallthrough */
import type { ReactNode, FC } from 'react';
import React, { useState, Fragment, useEffect, useRef, memo } from 'react';
import memoize from 'memoizerific';
Expand Down Expand Up @@ -37,25 +36,16 @@ const baseViewports: ViewportItem[] = [responsiveViewport];

const toLinks = memoize(50)((list: ViewportItem[], active: LinkBase, set, state, close): Link[] => {
return list
.filter((i) => i.id !== responsiveViewport.id || active.id !== i.id)
.map((i) => {
switch (i.id) {
case responsiveViewport.id: {
if (active.id === i.id) {
return null;
}
}
default: {
return {
...i,
onClick: () => {
set({ ...state, selected: i.id });
close();
},
};
}
}
})
.filter(Boolean);
return {
...i,
onClick: () => {
set({ ...state, selected: i.id });
close();
},
};
});
});

const wrapperId = 'storybook-preview-wrapper';
Expand Down Expand Up @@ -112,12 +102,12 @@ interface ViewportToolState {
}

const getStyles = (
prevStyles: ViewportStyles,
prevStyles: ViewportStyles | undefined,
styles: Styles,
isRotated: boolean
): ViewportStyles => {
if (styles === null) {
return null;
): ViewportStyles | undefined => {
if (!styles || !prevStyles) {
return undefined;
}
const result = typeof styles === 'function' ? styles(prevStyles) : styles;
return isRotated ? flip(result) : result;
Expand Down Expand Up @@ -154,7 +144,8 @@ export const ViewportTool: FC = memo(
useEffect(() => {
setState({
selected:
defaultViewport || (viewports[state.selected] ? state.selected : responsiveViewport.id),
defaultViewport ||
(state.selected && viewports[state.selected] ? state.selected : responsiveViewport.id),
isRotated: defaultOrientation === 'landscape',
});
}, [defaultOrientation, defaultViewport]);
Expand Down
2 changes: 1 addition & 1 deletion code/addons/viewport/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
"strict": false
"strict": true
}
}

0 comments on commit 425e566

Please sign in to comment.