Skip to content

Commit 5b426f9

Browse files
authored
feat: remove styled-components dependency (#181)
1 parent a211c58 commit 5b426f9

File tree

15 files changed

+283
-257
lines changed

15 files changed

+283
-257
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ An environment for designing, reviewing, and quality-testing React components.
77
npm install @sanity/ui-workshop -D
88

99
# Install peer dependencies
10-
npm install @sanity/ui react react-dom styled-components
10+
npm install @sanity/ui react react-dom
1111
```
1212

1313
[![npm version](https://img.shields.io/npm/v/@sanity/ui-workshop.svg?style=flat-square)](https://www.npmjs.com/package/@sanity/ui-workshop)

package.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@ export default defineConfig({
1414
},
1515
},
1616
tsconfig: 'tsconfig.dist.json',
17-
babel: {reactCompiler: true, styledComponents: true},
17+
babel: {reactCompiler: true},
1818
reactCompilerOptions: {target: '19'},
19+
rollup: {
20+
output: {
21+
intro: (chunkInfo) => {
22+
if (chunkInfo.isEntry === true && chunkInfo.name === 'index') {
23+
return `import './bundle.css'`
24+
}
25+
return ''
26+
},
27+
},
28+
vanillaExtract: true,
29+
},
1930
dts: 'rolldown',
2031
strictOptions: {noImplicitSideEffects: 'off'},
2132
})

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"license": "MIT",
2222
"author": "Sanity.io <hello@sanity.io>",
2323
"type": "module",
24+
"imports": {
25+
"#styles": "./src/core/styles.css.ts"
26+
},
2427
"exports": {
2528
".": {
2629
"source": "./exports/index.ts",
@@ -105,6 +108,9 @@
105108
},
106109
"dependencies": {
107110
"@sanity/icons": "^3.7.4",
111+
"@vanilla-extract/css": "^1.17.4",
112+
"@vanilla-extract/css-utils": "^0.1.6",
113+
"@vanilla-extract/dynamic": "^2.1.5",
108114
"@vanilla-extract/vite-plugin": "^5.1.1",
109115
"@vitejs/plugin-react": "^4.7.0",
110116
"axe-core": "^4.10.3",
@@ -140,7 +146,6 @@
140146
"@typescript-eslint/eslint-plugin": "^7.18.0",
141147
"@typescript-eslint/parser": "^7.18.0",
142148
"babel-plugin-react-compiler": "19.1.0-rc.2",
143-
"babel-plugin-styled-components": "^2.1.4",
144149
"commitizen": "^4.3.1",
145150
"commitlint": "^19.8.1",
146151
"eslint": "^8.57.1",
@@ -160,16 +165,14 @@
160165
"react-dom": "^19.1.1",
161166
"react-is": "^19.1.1",
162167
"semantic-release": "^23.1.1",
163-
"styled-components": "^6.1.19",
164168
"tsconfig-paths": "^4.2.0",
165169
"typescript": "5.9.2",
166170
"vitest": "^3.2.4"
167171
},
168172
"peerDependencies": {
169173
"@sanity/ui": "^3",
170174
"react": "^19",
171-
"react-dom": "^19",
172-
"styled-components": "^6.1"
175+
"react-dom": "^19"
173176
},
174177
"packageManager": "pnpm@9.15.9",
175178
"publishConfig": {

pnpm-lock.yaml

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

src/core/GlobalStyle.ts

Lines changed: 16 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,18 @@
1-
import {createGlobalStyle} from 'styled-components'
1+
import {useRootTheme} from '@sanity/ui'
2+
import {setElementVars} from '@vanilla-extract/dynamic'
3+
import {useInsertionEffect} from 'react'
24

3-
export const GlobalStyle = createGlobalStyle`
4-
@font-face {
5-
font-family: Inter;
6-
font-style: normal;
7-
font-weight: 400;
8-
font-display: swap;
9-
src: url("https://studio-static.sanity.io/Inter-Regular.woff2") format("woff2");
10-
}
11-
@font-face {
12-
font-family: Inter;
13-
font-style: italic;
14-
font-weight: 400;
15-
font-display: swap;
16-
src: url("https://studio-static.sanity.io/Inter-Italic.woff2") format("woff2");
17-
}
18-
@font-face {
19-
font-family: Inter;
20-
font-style: normal;
21-
font-weight: 500;
22-
font-display: swap;
23-
src: url("https://studio-static.sanity.io/Inter-Medium.woff2") format("woff2");
24-
}
25-
@font-face {
26-
font-family: Inter;
27-
font-style: italic;
28-
font-weight: 500;
29-
font-display: swap;
30-
src: url("https://studio-static.sanity.io/Inter-MediumItalic.woff2") format("woff2");
31-
}
32-
@font-face {
33-
font-family: Inter;
34-
font-style: normal;
35-
font-weight: 600;
36-
font-display: swap;
37-
src: url("https://studio-static.sanity.io/Inter-SemiBold.woff2") format("woff2");
38-
}
39-
@font-face {
40-
font-family: Inter;
41-
font-style: italic;
42-
font-weight: 600;
43-
font-display: swap;
44-
src: url("https://studio-static.sanity.io/Inter-SemiBoldItalic.woff2") format("woff2");
45-
}
46-
@font-face {
47-
font-family: Inter;
48-
font-style: normal;
49-
font-weight: 700;
50-
font-display: swap;
51-
src: url("https://studio-static.sanity.io/Inter-Bold.woff2") format("woff2");
52-
}
53-
@font-face {
54-
font-family: Inter;
55-
font-style: italic;
56-
font-weight: 700;
57-
font-display: swap;
58-
src: url("https://studio-static.sanity.io/Inter-BoldItalic.woff2") format("woff2");
59-
}
60-
@font-face {
61-
font-family: Inter;
62-
font-style: normal;
63-
font-weight: 800;
64-
font-display: swap;
65-
src: url("https://studio-static.sanity.io/Inter-ExtraBold.woff2") format("woff2");
66-
}
67-
@font-face {
68-
font-family: Inter;
69-
font-style: italic;
70-
font-weight: 800;
71-
font-display: swap;
72-
src: url("https://studio-static.sanity.io/Inter-ExtraBoldItalic.woff2") format("woff2");
73-
}
74-
@font-face {
75-
font-family: Inter;
76-
font-style: normal;
77-
font-weight: 900;
78-
font-display: swap;
79-
src: url("https://studio-static.sanity.io/Inter-Black.woff2") format("woff2");
80-
}
81-
@font-face {
82-
font-family: Inter;
83-
font-style: italic;
84-
font-weight: 900;
85-
font-display: swap;
86-
src: url("https://studio-static.sanity.io/Inter-BlackItalic.woff2") format("woff2");
87-
}
5+
import {bodyBackgroundColor} from '#styles'
886

89-
body {
90-
background-color: ${({theme}) => theme.sanity.color.base.bg};
91-
}
92-
`
7+
export function GlobalStyle(): null {
8+
const {scheme, theme} = useRootTheme()
9+
const bg = theme.v2!.color[scheme].default.bg!
10+
11+
useInsertionEffect(() => {
12+
setElementVars(document.body, {
13+
[bodyBackgroundColor]: bg,
14+
})
15+
}, [bg])
16+
17+
return null
18+
}

src/core/WorkshopCanvas.tsx

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import {BoxDisplay, Card, Container, Flex, Heading, Spinner, Stack, Text} from '@sanity/ui'
2-
import {memo, useMemo, useState} from 'react'
3-
import {styled} from 'styled-components'
1+
import {Card, Container, Flex, Heading, Spinner, Stack, Text} from '@sanity/ui'
2+
import {assignInlineVars} from '@vanilla-extract/dynamic'
3+
import {memo, useState} from 'react'
4+
5+
import {
6+
iframe,
7+
iframeContainer,
8+
viewportMaxHeight,
9+
viewportMaxWidth,
10+
zoom as zoomVar,
11+
} from '#styles'
412

513
import {VIEWPORT_OPTIONS} from './constants'
614
import {buildFrameUrl} from './helpers'
715
import {useWorkshop} from './useWorkshop'
816

9-
const Frame = styled.iframe`
10-
display: block;
11-
border: 0;
12-
height: 100%;
13-
width: 100%;
14-
view-transition-name: canvas;
15-
`
16-
1717
/** @internal */
1818
export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
1919
frameRef: React.Ref<HTMLIFrameElement>
@@ -29,28 +29,8 @@ export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
2929
buildFrameUrl({baseUrl: frameUrl, path, payload, scheme, viewport, zoom}),
3030
)
3131

32-
const containerStyle = useMemo(
33-
() => ({
34-
maxWidth: viewportW === 'auto' ? undefined : `${(viewportW || 1) * zoom}px`,
35-
maxHeight: viewportH ? `${(viewportH || 1) * zoom}px` : undefined,
36-
}),
37-
[viewportW, viewportH, zoom],
38-
)
39-
40-
const display: BoxDisplay = useMemo(() => (hidden ? 'none' : 'block'), [hidden])
41-
42-
const frameStyle = useMemo(
43-
() => ({
44-
transform: `scale(${zoom})`,
45-
transformOrigin: '0 0',
46-
width: `${100 / zoom}%`,
47-
height: `${100 / zoom}%`,
48-
}),
49-
[zoom],
50-
)
51-
5232
return (
53-
<Card display={display} flex={1} overflow="hidden" tone="transparent">
33+
<Card display={hidden ? 'none' : 'block'} flex={1} overflow="hidden" tone="transparent">
5434
<Flex align="center" height="fill" justify="center" sizing="border">
5535
{path === '/' && (
5636
<Container width={0}>
@@ -66,13 +46,18 @@ export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
6646
{!frameReady && path !== '/' && <Spinner muted />}
6747

6848
<Container
49+
className={iframeContainer}
6950
height="fill"
7051
hidden={!frameReady || path === '/'}
71-
style={containerStyle}
52+
style={assignInlineVars({
53+
[viewportMaxWidth]: viewportW === 'auto' ? undefined : `${viewportW}px`,
54+
[viewportMaxHeight]: viewportH ? `${viewportH}px` : undefined,
55+
[zoomVar]: `${zoom}`,
56+
})}
7257
width="auto"
7358
>
7459
<Card height="fill" shadow={1}>
75-
<Frame ref={frameRef} src={initialFrameUrl} style={frameStyle} />
60+
<iframe className={iframe} ref={frameRef} src={initialFrameUrl} />
7661
</Card>
7762
</Container>
7863
</Flex>

0 commit comments

Comments
 (0)