11import { Card , Container , Flex , Heading , Spinner , Stack , Text } from '@sanity/ui'
2- import type { Display } from '@sanity/ui/css '
3- import { memo , useMemo , useState } from 'react'
2+ import { assignInlineVars } from '@vanilla-extract/dynamic '
3+ import { memo , useState } from 'react'
44
5- import { iframe } from '#styles'
5+ import {
6+ iframe ,
7+ iframeContainer ,
8+ viewportMaxHeight ,
9+ viewportMaxWidth ,
10+ zoom as zoomVar ,
11+ } from '#styles'
612
713import { VIEWPORT_OPTIONS } from './constants'
814import { buildFrameUrl } from './helpers'
@@ -23,27 +29,8 @@ export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
2329 buildFrameUrl ( { baseUrl : frameUrl , path, payload, scheme, viewport, zoom} ) ,
2430 )
2531
26- const containerStyle = useMemo (
27- ( ) => ( {
28- maxWidth : viewportW === 'auto' ? undefined : `${ ( viewportW || 1 ) * zoom } px` ,
29- maxHeight : viewportH ? `${ ( viewportH || 1 ) * zoom } px` : undefined ,
30- } ) ,
31- [ viewportW , viewportH , zoom ] ,
32- )
33-
34- const display = useMemo < Display > ( ( ) => ( hidden ? 'none' : 'block' ) , [ hidden ] )
35-
36- const frameStyle = useMemo (
37- ( ) => ( {
38- transform : `scale(${ zoom } )` ,
39- width : `${ 100 / zoom } %` ,
40- height : `${ 100 / zoom } %` ,
41- } ) ,
42- [ zoom ] ,
43- )
44-
4532 return (
46- < Card display = { display } flex = { 1 } overflow = "hidden" tone = "transparent" >
33+ < Card display = { hidden ? 'none' : 'block' } flex = { 1 } overflow = "hidden" tone = "transparent" >
4734 < Flex align = "center" height = "fill" justify = "center" sizing = "border" >
4835 { path === '/' && (
4936 < Container width = { 0 } >
@@ -59,13 +46,18 @@ export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
5946 { ! frameReady && path !== '/' && < Spinner muted /> }
6047
6148 < Container
49+ className = { iframeContainer }
6250 height = "fill"
6351 hidden = { ! frameReady || path === '/' }
64- style = { containerStyle }
52+ style = { assignInlineVars ( {
53+ [ viewportMaxWidth ] : viewportW === 'auto' ? undefined : `${ viewportW } px` ,
54+ [ viewportMaxHeight ] : viewportH ? `${ viewportH } px` : undefined ,
55+ [ zoomVar ] : `${ zoom } ` ,
56+ } ) }
6557 width = "auto"
6658 >
6759 < Card height = "fill" shadow = { 1 } >
68- < iframe className = { iframe } ref = { frameRef } src = { initialFrameUrl } style = { frameStyle } />
60+ < iframe className = { iframe } ref = { frameRef } src = { initialFrameUrl } />
6961 </ Card >
7062 </ Container >
7163 </ Flex >
0 commit comments