Browse Source

chore(sandpack): remove unused code (#4674)

main
Danilo Woznica 3 years ago
committed by GitHub
parent
commit
1cf3c1b1a0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      beta/src/components/MDX/Sandpack/Preview.tsx
  2. 46
      beta/src/components/MDX/Sandpack/computeViewportSize.ts

6
beta/src/components/MDX/Sandpack/Preview.tsx

@ -6,10 +6,8 @@
import * as React from 'react';
import {useSandpack, LoadingOverlay} from '@codesandbox/sandpack-react';
import cn from 'classnames';
import {Error} from './Error';
import {computeViewportSize} from './computeViewportSize';
import type {LintDiagnostic} from './useSandpackLint';
import type {LintDiagnostic} from './utils';
const generateRandomId = (): string =>
Math.floor(Math.random() * 10000).toString();
@ -119,7 +117,6 @@ export function Preview({
[status === 'idle']
);
const viewportStyle = computeViewportSize('auto', 'portrait');
const overrideStyle = error
? {
// Don't collapse errors
@ -149,7 +146,6 @@ export function Preview({
style={{
// TODO: clean up this mess.
...customStyle,
...viewportStyle,
...overrideStyle,
}}>
<div

46
beta/src/components/MDX/Sandpack/computeViewportSize.ts

@ -1,46 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
export type ViewportSizePreset =
| 'iPhone X'
| 'Pixel 2'
| 'iPad'
| 'Moto G4'
| 'Surface Duo';
export type ViewportSize =
| ViewportSizePreset
| 'auto'
| {width: number; height: number};
export type ViewportOrientation = 'portrait' | 'landscape';
const VIEWPORT_SIZE_PRESET_MAP: Record<
ViewportSizePreset,
{x: number; y: number}
> = {
'iPhone X': {x: 375, y: 812},
iPad: {x: 768, y: 1024},
'Pixel 2': {x: 411, y: 731},
'Moto G4': {x: 360, y: 640},
'Surface Duo': {x: 540, y: 720},
};
export const computeViewportSize = (
viewport: ViewportSize,
orientation: ViewportOrientation
): {width?: number; height?: number} => {
if (viewport === 'auto') {
return {};
}
if (typeof viewport === 'string') {
const {x, y} = VIEWPORT_SIZE_PRESET_MAP[viewport];
return orientation === 'portrait'
? {width: x, height: y}
: {width: y, height: x};
}
return viewport;
};
Loading…
Cancel
Save