Skip to content

Commit ba4e695

Browse files
committed
fix: replace inline styles
1 parent 658a8c2 commit ba4e695

File tree

10 files changed

+84
-44
lines changed

10 files changed

+84
-44
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sanity/ui-workshop",
3-
"version": "3.2.0-static.1",
3+
"version": "3.2.0-static.2",
44
"keywords": [
55
"sanity",
66
"ui",
@@ -109,6 +109,8 @@
109109
"dependencies": {
110110
"@sanity/icons": "^3.7.4",
111111
"@vanilla-extract/css": "^1.17.4",
112+
"@vanilla-extract/css-utils": "^0.1.6",
113+
"@vanilla-extract/dynamic": "^2.1.5",
112114
"@vanilla-extract/vite-plugin": "^5.1.1",
113115
"@vitejs/plugin-react": "^4.7.0",
114116
"axe-core": "^4.10.3",

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/WorkshopCanvas.tsx

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import {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

713
import {VIEWPORT_OPTIONS} from './constants'
814
import {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>

src/core/inspector/InspectorHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {Card, Layer, Tab, TabList} from '@sanity/ui'
2-
import {CSSProperties, memo, useCallback, useMemo} from 'react'
2+
import {memo, useCallback} from 'react'
3+
4+
import {inspectorHeader} from '#styles'
35

46
import {InspectorTab} from './types'
57

@@ -10,10 +12,8 @@ export const InspectorHeader = memo(function InspectorHeader(props: {
1012
}) {
1113
const {currentTabId, onTabChange, tabs} = props
1214

13-
const layerStyle: CSSProperties = useMemo(() => ({flex: 'none', position: 'sticky', top: 0}), [])
14-
1515
return (
16-
<Layer style={layerStyle}>
16+
<Layer className={inspectorHeader} flex="none" position="sticky">
1717
<Card padding={2} shadow={1}>
1818
<TabList gap={1}>
1919
{tabs.map((tab) => (

src/core/navbar/NavbarBreadcrumbs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {Breadcrumbs, Text} from '@sanity/ui'
22
import {memo, useCallback} from 'react'
33

4+
import {forceColorInherit} from '#styles'
5+
46
import {useWorkshop} from '../useWorkshop'
57

68
/** @internal */
@@ -43,7 +45,7 @@ const NavbarBreadcrumbsView = memo(function NavbarBreadcrumbsView(props: {
4345
gap={2}
4446
>
4547
<Text size={[2, 2, 1]} weight="bold">
46-
<a href="/" onClick={onHomeClick} style={{color: 'inherit'}}>
48+
<a className={forceColorInherit} href="/" onClick={onHomeClick}>
4749
{title}
4850
</a>
4951
</Text>

src/core/navbar/WorkshopNavbar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {ControlsIcon, MenuIcon} from '@sanity/icons'
22
import {Box, Button, Card, Flex, Inline, Text, useMediaIndex} from '@sanity/ui'
33
import {memo} from 'react'
44

5+
import {force0LineHeight, forceMinWidth250} from '#styles'
6+
57
import {useWorkshop} from '../useWorkshop'
68
import {NavbarBreadcrumbs} from './NavbarBreadcrumbs'
79
import {OpenCanvasButton} from './OpenCanvasButton'
@@ -21,7 +23,7 @@ export const WorkshopNavbar = memo(function WorkshopNavbar(props: {
2123
const {story, title} = useWorkshop()
2224

2325
return (
24-
<Card borderBottom flex="none" padding={2} style={{lineHeight: 0}}>
26+
<Card className={force0LineHeight} borderBottom flex="none" padding={2}>
2527
<Flex gap={1}>
2628
<Box display={['block', 'block', 'none']} flex="none">
2729
<Button
@@ -36,11 +38,11 @@ export const WorkshopNavbar = memo(function WorkshopNavbar(props: {
3638
</Box>
3739

3840
<Flex
41+
className={forceMinWidth250}
3942
flex={1}
4043
justify={['center', 'center', 'flex-start']}
4144
padding={2}
4245
sizing="border"
43-
style={{minWidth: 250}}
4446
>
4547
{mediaIndex < 2 && <Text weight="bold">{story?.title || title}</Text>}
4648
{mediaIndex >= 2 && <NavbarBreadcrumbs />}

src/core/navigator/WorkshopNavigator.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {Display, ResponsiveProp} from '@sanity/ui/css'
44
import {FontTextSize} from '@sanity/ui/theme'
55
import {memo, useCallback, useMemo, useState} from 'react'
66

7-
import {workshopNavigator} from '#styles'
7+
import {force0LineHeight, workshopNavigator} from '#styles'
88

99
import {WorkshopScope, WorkshopStory} from '../config'
1010
import {EMPTY_ARRAY} from '../constants'
@@ -14,8 +14,6 @@ import {SearchResults} from './SearchResults'
1414
import {StoryTree} from './StoryTree'
1515
import {MenuCollection, MenuList, MenuScope} from './types'
1616

17-
const flexNoneStyle: React.CSSProperties = {flex: 'none'}
18-
const lineHeightNoneStyle: React.CSSProperties = {lineHeight: 0}
1917
const textInputFontSize: ResponsiveProp<FontTextSize> = [2, 2, 1]
2018

2119
/** @internal */
@@ -107,8 +105,8 @@ const NavigatorView = memo(function NavigatorView(props: {
107105
overflow={['hidden', 'hidden', 'auto']}
108106
>
109107
<Flex direction="column" height="fill">
110-
<Layer style={flexNoneStyle}>
111-
<Card padding={2} shadow={1} style={lineHeightNoneStyle}>
108+
<Layer flex="none">
109+
<Card className={force0LineHeight} padding={2} shadow={1}>
112110
<TextInput
113111
border={false}
114112
clearButton={Boolean(query)}

src/core/plugins/props/components/booleanProp.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {Box, Checkbox, Flex, Text} from '@sanity/ui'
22
import {memo} from 'react'
33

4+
import {force0LineHeight} from '#styles'
5+
46
import {BooleanPropSchema} from '../types'
57
import {useProps} from '../useProps'
68

@@ -14,7 +16,7 @@ export const BooleanProp = memo(function BooleanProp(props: {
1416

1517
return (
1618
<Flex as="label" padding={3}>
17-
<Box marginRight={2} style={{lineHeight: 0}}>
19+
<Box className={force0LineHeight} marginRight={2}>
1820
<Checkbox
1921
checked={value || false}
2022
onChange={(event) => setPropValue(schema.name, event.currentTarget.checked)}

src/core/styles.css.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {vars} from '@sanity/ui/css'
2-
import {createViewTransition, globalStyle, style} from '@vanilla-extract/css'
2+
import {createVar, createViewTransition, globalStyle, style} from '@vanilla-extract/css'
3+
import {calc} from '@vanilla-extract/css-utils'
34

45
globalStyle('html', {
56
WebkitTextSizeAdjust: '100%',
@@ -18,21 +19,45 @@ globalStyle('body', {
1819
overflow: 'hidden',
1920
})
2021

22+
export const forceMinWidth250 = style({
23+
minWidth: '250px !important',
24+
})
2125
export const forceMinWidth320 = style({
2226
minWidth: '320px !important',
2327
})
28+
export const force0LineHeight = style({
29+
lineHeight: '0 !important',
30+
})
31+
export const forceColorInherit = style({
32+
color: 'inherit !important',
33+
})
2434

2535
export const canvasViewTransition = createViewTransition('canvas')
26-
36+
export const zoom = createVar(
37+
{
38+
syntax: '<number>',
39+
inherits: true,
40+
initialValue: '1',
41+
},
42+
'zoom',
43+
)
2744
export const iframe = style({
2845
display: 'block',
2946
border: 0,
30-
height: '100%',
31-
width: '100%',
47+
transform: `scale(${zoom})`,
3248
transformOrigin: '0 0',
49+
height: calc.divide('100%', zoom),
50+
width: calc.divide('100%', zoom),
3351
viewTransitionName: canvasViewTransition,
3452
})
3553

54+
export const viewportMaxWidth = createVar('viewport-max-width')
55+
export const viewportMaxHeight = createVar('viewport-max-height')
56+
export const iframeContainer = style({
57+
maxWidth: calc.multiply(viewportMaxWidth, zoom),
58+
maxHeight: calc.multiply(viewportMaxHeight, zoom),
59+
})
60+
3661
export const workshopInspector = style({
3762
'@media': {
3863
'screen and (min-width: 600px)': {
@@ -52,3 +77,7 @@ export const workshopNavigator = style({
5277
},
5378
},
5479
})
80+
81+
export const inspectorHeader = style({
82+
top: 0,
83+
})

src/plugin-perf/PerfInspector.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {PlayIcon, TrashIcon} from '@sanity/icons'
22
import {Box, Button, Card, Flex, Stack, Text} from '@sanity/ui'
33
import {memo} from 'react'
44

5+
import {force0LineHeight} from '#styles'
6+
57
import {usePerf} from './hooks'
68

79
/** @internal */
@@ -26,7 +28,7 @@ export const PerfInspector = memo(function PerfInspector(): React.ReactNode {
2628
const testResults = results.filter((r) => r.name === detail.name)
2729

2830
return (
29-
<Card border key={detail.name} overflow="hidden" radius={2} style={{lineHeight: 0}}>
31+
<Card className={force0LineHeight} border key={detail.name} overflow="hidden" radius={2}>
3032
<Flex>
3133
<Stack flex={1} padding={2} gap={2}>
3234
<Text size={1} weight="semibold">

0 commit comments

Comments
 (0)