Skip to content

Commit d9a1ec5

Browse files
committed
feat: added ui-workshop preset
1 parent c43e6aa commit d9a1ec5

File tree

13 files changed

+1090
-241
lines changed

13 files changed

+1090
-241
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ babel
99
*.js
1010
v2-incompatible.js.template
1111
*.json
12+
assets/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ The inject command can do more work by adding presets. Consult the individual pr
198198

199199
* [semver-workflow](./docs/semver-workflow.md) - Add an opinionated Github workflow to automate NPM releases
200200
* [renovatebot](./docs/renovatebot.md) - Add opinionated Renovatebot config to make dependency management a breeze
201+
* [ui-workshop](./docs/ui-workshop.md) - Add [@sanity/ui-workshop](https://github.com/sanity-io/ui-workshop) to make component testing a breeze
201202

202203
## Testing a plugin in Sanity Studio
203204

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Box, Stack, Text} from '@sanity/ui'
2+
import React, {ReactNode} from 'react'
3+
4+
export function CustomField(props: {children?: ReactNode; title?: ReactNode}) {
5+
const {children, title} = props
6+
7+
return (
8+
<Stack space={3}>
9+
<Text size={1} weight="semibold">
10+
{title}
11+
</Text>
12+
<Box>{children}</Box>
13+
</Stack>
14+
)
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {defineScope} from '@sanity/ui-workshop'
2+
import {lazy} from 'react'
3+
4+
export default defineScope({
5+
name: 'custom',
6+
title: 'Custom (example)',
7+
stories: [
8+
{
9+
name: 'props',
10+
title: 'Props',
11+
component: lazy(() => import('./props')),
12+
},
13+
],
14+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Box, Card, Container, Text} from '@sanity/ui'
2+
import {useString} from '@sanity/ui-workshop'
3+
import {CustomField} from '../CustomField'
4+
import React from 'react'
5+
6+
export default function PropsStory() {
7+
const title = useString('Title', 'My custom field')
8+
9+
return (
10+
<Container width={1}>
11+
<Box paddingX={4} paddingY={[5, 6, 7]}>
12+
<CustomField title={title}>
13+
<Card border padding={3}>
14+
<Text>This is just an example</Text>
15+
</Card>
16+
</CustomField>
17+
</Box>
18+
</Container>
19+
)
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {defineConfig} from '@sanity/ui-workshop'
2+
3+
export default defineConfig({
4+
title: 'Workshop Starter',
5+
})

docs/ui-workshop.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Preset: ui-workshop
2+
3+
## Usage
4+
5+
### Inject into existing package
6+
`npx @sanity/plugin-kit inject --preset-only --preset ui-workshop`
7+
8+
### Use to init plugin
9+
`npx @sanity/plugin-kit init --preset ui-workshop <new-plugin-name>`
10+
11+
## What does it do?
12+
13+
Sets up your package with [@sanity/ui-workshop](https://github.com/sanity-io/ui-workshop),
14+
to make component testing a breeze.
15+
16+
- Adds [@sanity/ui-workshop](https://github.com/sanity-io/ui-workshop) dev dependency.
17+
- Adds a example files for testing components using @sanity/ui-workshop
18+
- Adds .workshop to .gitignore
19+
-
20+
## Manual steps after inject
21+
22+
* Run `npm i` to install dependencies.
23+
* Start the workshop with `workshop dev`.
24+
* Put your plugin/package components into workshop to test them.
25+
* Refer to @sanity/ui-workshop [README](https://github.com/sanity-io/ui-workshop#basic-usage) for more.
26+

0 commit comments

Comments
 (0)