Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ An environment for designing, reviewing, and quality-testing React components.
npm install @sanity/ui-workshop -D

# Install peer dependencies
npm install @sanity/icons @sanity/ui react react-dom styled-components
npm install @sanity/ui react react-dom styled-components
```

[![npm version](https://img.shields.io/npm/v/@sanity/ui-workshop.svg?style=flat-square)](https://www.npmjs.com/package/@sanity/ui-workshop)
Expand Down Expand Up @@ -88,6 +88,85 @@ function TestStory() {
}
```

## Styling

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.

First install the `@vanilla-extract/css` package:

```sh
npm install @vanilla-extract/css
```

Then, add a `style.css.ts` file for your workshop:

```ts
// src/__workshop__/style.css.ts

import {style} from '@vanilla-extract/css'

export const container = style({
display: 'grid',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
width: '100%',
})
```

And finally, import the `container` className and use it in your workshop:

```diff
import {
defineScope,
useBoolean,
useNumber,
useSelect,
useString,
useText,
} from '@sanity/ui-workshop'
+import {container} from './style.css'

export default defineScope({
name: 'test',
title: 'Test',
stories: [
{
name: 'test',
title: 'Test',
component: TestStory,
},
],
})

const options = {
None: '',
Small: 'sm',
Medium: 'md',
Large: 'lg',
}

function TestStory() {
const text = useText('Text', 'Hello, world')
const boolean = useBoolean('Boolean', true)
const number = useNumber('Number', 1234)
const string = useString('String', '...')
const option = useSelect('Select option', options)

return (
- <div>
+ <div className={container}>
<h1>This is my first story.</h1>
<p>Some text: {text}</p>
<p>A boolean: {boolean ? 'true' : 'false'}</p>
<p>A number: {number}</p>
<p>A string: {string}</p>
<p>An option: {option}</p>
</div>
)
}
```

## License

[MIT](LICENSE)
1 change: 1 addition & 0 deletions package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default defineConfig({
babel: {reactCompiler: true, styledComponents: true},
reactCompilerOptions: {target: '19'},
dts: 'rolldown',
strictOptions: {noImplicitSideEffects: 'off'},
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sanity/ui-workshop",
"version": "3.1.2",
"version": "3.1.3-canary.0",
"keywords": [
"sanity",
"ui",
Expand All @@ -20,7 +20,6 @@
},
"license": "MIT",
"author": "Sanity.io <hello@sanity.io>",
"sideEffects": false,
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -73,7 +72,7 @@
"format": "prettier --write --cache --ignore-unknown .",
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
"prepare": "husky install",
"prepublishOnly": "pnpm run build",
"prepack": "pnpm run build",
"release": "semantic-release",
"test": "vitest",
"watch": "pkg watch --strict",
Expand Down Expand Up @@ -106,6 +105,7 @@
},
"dependencies": {
"@sanity/icons": "^3.7.4",
"@vanilla-extract/vite-plugin": "^5.1.1",
"@vitejs/plugin-react": "^4.7.0",
"axe-core": "^4.10.3",
"cac": "^6.7.14",
Expand Down
52 changes: 52 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/frame/formatStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const ROOT_PATH = (() => {
// Wrap in try/catch to avoid throwing exception in environments that don’t have `process.env`.
try {
return process.env.ROOT_PATH
} catch (_) {
} catch {
return undefined
}
})()
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/props/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function encodeValue(val: Record<string, unknown>): string {
export function decodeValue(val: string): Record<string, unknown> {
try {
return JSON.parse(decode(val))
} catch (_) {
} catch {
return EMPTY_RECORD
}
}
4 changes: 2 additions & 2 deletions src/runtime/config/_loadConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createRequire} from 'node:module'

import {WorkshopConfigOptions} from '@sanity/ui-workshop'
import {TransformOptions} from 'esbuild'
import type {WorkshopConfigOptions} from '@sanity/ui-workshop'
import type {TransformOptions} from 'esbuild'

import {_findConfigFile} from './_findConfigFile'

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/config/_loadRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createRequire} from 'node:module'

import {WorkshopRuntimeOptions} from '@sanity/ui-workshop'
import {TransformOptions} from 'esbuild'
import type {WorkshopRuntimeOptions} from '@sanity/ui-workshop'
import type {TransformOptions} from 'esbuild'

import {_findRuntimeFile} from './_findRuntimeFile'

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/lib/_fileExists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function _fileExists(file: string): boolean {
accessSync(file)

return true
} catch (_) {
} catch {
return false
}
}
2 changes: 2 additions & 0 deletions src/runtime/viteConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {vanillaExtractPlugin} from '@vanilla-extract/vite-plugin'
import react from '@vitejs/plugin-react'
import path from 'path'
import {UserConfig} from 'vite'
Expand Down Expand Up @@ -26,6 +27,7 @@ export function createViteConfig(options: {
},
},
plugins: [
vanillaExtractPlugin(),
react({
babel: {plugins: [['babel-plugin-react-compiler', {target: '19'}]]},
}),
Expand Down
Loading