Skip to content

Commit 1a5c247

Browse files
authored
feat: support vanilla extract (#187)
1 parent bb31f84 commit 1a5c247

File tree

10 files changed

+145
-11
lines changed

10 files changed

+145
-11
lines changed

README.md

Lines changed: 80 additions & 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/icons @sanity/ui react react-dom styled-components
10+
npm install @sanity/ui react react-dom styled-components
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)
@@ -88,6 +88,85 @@ function TestStory() {
8888
}
8989
```
9090

91+
## Styling
92+
93+
In addition to the [CSS features that `vite` supports](https://vite.dev/guide/features.html#css), you can also use [Vanilla Extract](https://vanilla-extract.style/) for styling.
94+
95+
First install the `@vanilla-extract/css` package:
96+
97+
```sh
98+
npm install @vanilla-extract/css
99+
```
100+
101+
Then, add a `style.css.ts` file for your workshop:
102+
103+
```ts
104+
// src/__workshop__/style.css.ts
105+
106+
import {style} from '@vanilla-extract/css'
107+
108+
export const container = style({
109+
display: 'grid',
110+
alignItems: 'center',
111+
justifyContent: 'center',
112+
height: '100%',
113+
width: '100%',
114+
})
115+
```
116+
117+
And finally, import the `container` className and use it in your workshop:
118+
119+
```diff
120+
import {
121+
defineScope,
122+
useBoolean,
123+
useNumber,
124+
useSelect,
125+
useString,
126+
useText,
127+
} from '@sanity/ui-workshop'
128+
+import {container} from './style.css'
129+
130+
export default defineScope({
131+
name: 'test',
132+
title: 'Test',
133+
stories: [
134+
{
135+
name: 'test',
136+
title: 'Test',
137+
component: TestStory,
138+
},
139+
],
140+
})
141+
142+
const options = {
143+
None: '',
144+
Small: 'sm',
145+
Medium: 'md',
146+
Large: 'lg',
147+
}
148+
149+
function TestStory() {
150+
const text = useText('Text', 'Hello, world')
151+
const boolean = useBoolean('Boolean', true)
152+
const number = useNumber('Number', 1234)
153+
const string = useString('String', '...')
154+
const option = useSelect('Select option', options)
155+
156+
return (
157+
- <div>
158+
+ <div className={container}>
159+
<h1>This is my first story.</h1>
160+
<p>Some text: {text}</p>
161+
<p>A boolean: {boolean ? 'true' : 'false'}</p>
162+
<p>A number: {number}</p>
163+
<p>A string: {string}</p>
164+
<p>An option: {option}</p>
165+
</div>
166+
)
167+
}
168+
```
169+
91170
## License
92171

93172
[MIT](LICENSE)

package.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export default defineConfig({
1717
babel: {reactCompiler: true, styledComponents: true},
1818
reactCompilerOptions: {target: '19'},
1919
dts: 'rolldown',
20+
strictOptions: {noImplicitSideEffects: 'off'},
2021
})

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sanity/ui-workshop",
3-
"version": "3.1.2",
3+
"version": "3.1.3-canary.0",
44
"keywords": [
55
"sanity",
66
"ui",
@@ -20,7 +20,6 @@
2020
},
2121
"license": "MIT",
2222
"author": "Sanity.io <hello@sanity.io>",
23-
"sideEffects": false,
2423
"type": "module",
2524
"exports": {
2625
".": {
@@ -73,7 +72,7 @@
7372
"format": "prettier --write --cache --ignore-unknown .",
7473
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
7574
"prepare": "husky install",
76-
"prepublishOnly": "pnpm run build",
75+
"prepack": "pnpm run build",
7776
"release": "semantic-release",
7877
"test": "vitest",
7978
"watch": "pkg watch --strict",
@@ -106,6 +105,7 @@
106105
},
107106
"dependencies": {
108107
"@sanity/icons": "^3.7.4",
108+
"@vanilla-extract/vite-plugin": "^5.1.1",
109109
"@vitejs/plugin-react": "^4.7.0",
110110
"axe-core": "^4.10.3",
111111
"cac": "^6.7.14",

pnpm-lock.yaml

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

src/core/frame/formatStack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const ROOT_PATH = (() => {
22
// Wrap in try/catch to avoid throwing exception in environments that don’t have `process.env`.
33
try {
44
return process.env.ROOT_PATH
5-
} catch (_) {
5+
} catch {
66
return undefined
77
}
88
})()

src/core/plugins/props/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function encodeValue(val: Record<string, unknown>): string {
1010
export function decodeValue(val: string): Record<string, unknown> {
1111
try {
1212
return JSON.parse(decode(val))
13-
} catch (_) {
13+
} catch {
1414
return EMPTY_RECORD
1515
}
1616
}

src/runtime/config/_loadConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {createRequire} from 'node:module'
22

3-
import {WorkshopConfigOptions} from '@sanity/ui-workshop'
4-
import {TransformOptions} from 'esbuild'
3+
import type {WorkshopConfigOptions} from '@sanity/ui-workshop'
4+
import type {TransformOptions} from 'esbuild'
55

66
import {_findConfigFile} from './_findConfigFile'
77

src/runtime/config/_loadRuntime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {createRequire} from 'node:module'
22

3-
import {WorkshopRuntimeOptions} from '@sanity/ui-workshop'
4-
import {TransformOptions} from 'esbuild'
3+
import type {WorkshopRuntimeOptions} from '@sanity/ui-workshop'
4+
import type {TransformOptions} from 'esbuild'
55

66
import {_findRuntimeFile} from './_findRuntimeFile'
77

src/runtime/lib/_fileExists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function _fileExists(file: string): boolean {
66
accessSync(file)
77

88
return true
9-
} catch (_) {
9+
} catch {
1010
return false
1111
}
1212
}

src/runtime/viteConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {vanillaExtractPlugin} from '@vanilla-extract/vite-plugin'
12
import react from '@vitejs/plugin-react'
23
import path from 'path'
34
import {UserConfig} from 'vite'
@@ -26,6 +27,7 @@ export function createViteConfig(options: {
2627
},
2728
},
2829
plugins: [
30+
vanillaExtractPlugin(),
2931
react({
3032
babel: {plugins: [['babel-plugin-react-compiler', {target: '19'}]]},
3133
}),

0 commit comments

Comments
 (0)