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: Remove css zoom #21303

Merged
merged 8 commits into from
Jul 10, 2023
25 changes: 6 additions & 19 deletions code/ui/components/src/Zoom/ZoomElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ import type { ReactElement } from 'react';
import React, { useEffect, useRef, useState, useCallback } from 'react';
import useResizeObserver from 'use-resize-observer';
import { styled } from '@storybook/theming';
import { browserSupportsCssZoom } from './browserSupportsCssZoom';

const hasBrowserSupportForCssZoom = browserSupportsCssZoom();

const ZoomElementWrapper = styled.div<{ scale: number; elementHeight: number }>(
({ scale = 1, elementHeight }) =>
hasBrowserSupportForCssZoom
? {
'> *': {
zoom: 1 / scale,
},
}
: {
height: elementHeight || 'auto',
transformOrigin: 'top left',
transform: `scale(${1 / scale})`,
}
({ scale = 1, elementHeight }) => ({
height: elementHeight || 'auto',
transformOrigin: 'top left',
transform: `scale(${1 / scale})`,
})
);

type ZoomProps = {
Expand Down Expand Up @@ -52,10 +42,7 @@ export function ZoomElement({ scale, children }: ZoomProps) {

return (
<ZoomElementWrapper scale={scale} elementHeight={elementHeight}>
<div
ref={hasBrowserSupportForCssZoom ? null : componentWrapperRef}
className="innerZoomElementWrapper"
>
<div ref={componentWrapperRef} className="innerZoomElementWrapper">
{children}
</div>
</ZoomElementWrapper>
Expand Down
20 changes: 6 additions & 14 deletions code/ui/components/src/Zoom/ZoomIFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { RefObject, ReactElement } from 'react';
import { Component } from 'react';
import { browserSupportsCssZoom } from './browserSupportsCssZoom';

export type IZoomIFrameProps = {
scale: number;
Expand Down Expand Up @@ -36,19 +35,12 @@ export class ZoomIFrame extends Component<IZoomIFrameProps> {

setIframeInnerZoom(scale: number) {
try {
if (browserSupportsCssZoom()) {
Object.assign(this.iframe.contentDocument.body.style, {
zoom: 1 / scale,
minHeight: `calc(100vh / ${1 / scale})`,
});
} else {
Object.assign(this.iframe.contentDocument.body.style, {
width: `${scale * 100}%`,
height: `${scale * 100}%`,
transform: `scale(${1 / scale})`,
transformOrigin: 'top left',
});
}
Object.assign(this.iframe.contentDocument.body.style, {
width: `${scale * 100}%`,
height: `${scale * 100}%`,
transform: `scale(${1 / scale})`,
transformOrigin: 'top left',
});
} catch (e) {
this.setIframeZoom(scale);
}
Expand Down
13 changes: 0 additions & 13 deletions code/ui/components/src/Zoom/browserSupportsCssZoom.ts

This file was deleted.