Skip to content

Commit aa86363

Browse files
committed
fix: test ui without styled-components
1 parent 42d30d4 commit aa86363

36 files changed

+177
-237
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/icons @sanity/ui react react-dom styled-components
10+
npm install @sanity/icons @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.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"format": "prettier --write --cache --ignore-unknown .",
7373
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
7474
"prepare": "husky install",
75-
"prepublishOnly": "pnpm run build",
75+
"prepack": "pnpm run build",
7676
"release": "semantic-release",
7777
"test": "vitest",
7878
"watch": "pkg watch --strict",
@@ -128,7 +128,7 @@
128128
"@sanity/pkg-utils": "^7.11.0",
129129
"@sanity/prettier-config": "^1.0.6",
130130
"@sanity/semantic-release-preset": "^4.1.8",
131-
"@sanity/ui": "^3.0.5",
131+
"@sanity/ui": "4.0.0-static.16",
132132
"@types/cpx": "^1.5.5",
133133
"@types/express": "^5.0.3",
134134
"@types/lodash": "^4.17.20",
@@ -165,7 +165,7 @@
165165
"vitest": "^3.2.4"
166166
},
167167
"peerDependencies": {
168-
"@sanity/ui": "^3",
168+
"@sanity/ui": "^4.0.0-0",
169169
"react": "^19",
170170
"react-dom": "^19",
171171
"styled-components": "^6.1"

pnpm-lock.yaml

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

src/__workshop__/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ function TestStory() {
3636

3737
return (
3838
<Flex align="center" height="fill" justify="center">
39-
<Stack space={[3, 4, 5, 6]}>
40-
<Heading size={[2, 3, 4, 5]}>This is my first story.</Heading>
41-
<Text size={[2, 3, 4, 5]}>Some text: {text}</Text>
42-
<Text size={[2, 3, 4, 5]}>A boolean: {boolean ? 'true' : 'false'}</Text>
43-
<Text size={[2, 3, 4, 5]}>A number: {number}</Text>
44-
<Text size={[2, 3, 4, 5]}>A string: {string}</Text>
45-
<Text size={[2, 3, 4, 5]}>An option: {option}</Text>
39+
<Stack gap={[3, 4, 5]}>
40+
<Heading size={[2, 3, 4]}>This is my first story.</Heading>
41+
<Text size={[2, 3, 4]}>Some text: {text}</Text>
42+
<Text size={[2, 3, 4]}>A boolean: {boolean ? 'true' : 'false'}</Text>
43+
<Text size={[2, 3, 4]}>A number: {number}</Text>
44+
<Text size={[2, 3, 4]}>A string: {string}</Text>
45+
<Text size={[2, 3, 4]}>An option: {option}</Text>
4646
</Stack>
4747
</Flex>
4848
)

src/core/GlobalStyle.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,5 @@ export const GlobalStyle = createGlobalStyle`
8686
src: url("https://studio-static.sanity.io/Inter-BlackItalic.woff2") format("woff2");
8787
}
8888
89-
body {
90-
background-color: ${({theme}) => theme.sanity.color.base.bg};
91-
}
89+
9290
`

src/core/Workshop.tsx

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import {
2-
BoundaryElementProvider,
3-
Flex,
4-
PortalProvider,
5-
ThemeColorSchemeKey,
6-
ToastProvider,
7-
useMediaIndex,
8-
} from '@sanity/ui'
1+
import {Flex, useMediaIndex} from '@sanity/ui'
2+
import type {ColorScheme} from '@sanity/ui/theme'
93
import {debounce} from 'lodash'
104
import {isEqual} from 'lodash'
115
import {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'
@@ -27,13 +21,13 @@ import {workshopReducer} from './workshopReducer'
2721
export interface WorkshopProps {
2822
config: WorkshopConfig
2923
locationStore: WorkshopLocationStore
30-
onSchemeChange: (nextScheme: ThemeColorSchemeKey) => void
31-
scheme?: ThemeColorSchemeKey
24+
onSchemeChange: (nextScheme: ColorScheme) => void
25+
scheme?: ColorScheme
3226
}
3327

3428
function getStateFromLocation(
3529
loc: Omit<WorkshopLocation, 'type'>,
36-
schemeProp?: ThemeColorSchemeKey,
30+
schemeProp?: ColorScheme,
3731
frameReady?: boolean,
3832
): WorkshopState {
3933
const path = loc.path
@@ -44,7 +38,7 @@ function getStateFromLocation(
4438
frameReady: frameReady || false,
4539
path,
4640
payload,
47-
scheme: schemeProp || (typeof scheme === 'string' ? (scheme as ThemeColorSchemeKey) : 'light'),
41+
scheme: schemeProp || (typeof scheme === 'string' ? (scheme as ColorScheme) : 'light'),
4842
viewport: typeof viewport === 'string' ? viewport : 'auto',
4943
zoom: typeof zoom === 'number' ? zoom : 1,
5044
}
@@ -86,8 +80,6 @@ export const Workshop = memo(function Workshop(props: WorkshopProps): React.Reac
8680
const withNavbar = config.features?.navbar ?? true
8781
const channel = useMemo(() => createPubsub<WorkshopMsg>(), [])
8882
const frame = useMemo(() => createWorkshopFrameController(), [])
89-
const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
90-
const [portalElement, setPortalElement] = useState<HTMLDivElement | null>(null)
9183
const [{frameReady, path, payload, scheme, viewport, zoom}, setState] = useState<WorkshopState>(
9284
() => getStateFromLocation(locationStore.get(), schemeProp),
9385
)
@@ -243,39 +235,25 @@ export const Workshop = memo(function Workshop(props: WorkshopProps): React.Reac
243235
viewport={viewport}
244236
zoom={zoom}
245237
>
246-
<ToastProvider>
247-
<BoundaryElementProvider element={boundaryElement}>
248-
<PortalProvider element={portalElement}>
249-
<Flex
250-
data-boundary=""
251-
direction="column"
252-
height="fill"
253-
ref={setBoundaryElement}
254-
style={{minWidth: 320}}
255-
>
256-
{withNavbar && (
257-
<WorkshopNavbar
258-
inspectorExpanded={inspectorExpanded}
259-
navigatorExpanded={navigatorExpanded}
260-
onInspectorToggle={handleInspectorToggle}
261-
onNavigatorToggle={handleNavigatorToggle}
262-
/>
263-
)}
264-
265-
<Flex flex={1}>
266-
<WorkshopNavigator collections={config.collections} expanded={navigatorExpanded} />
267-
<WorkshopCanvas
268-
frameRef={frame.setElement}
269-
hidden={navigatorExpanded || inspectorExpanded}
270-
/>
271-
<WorkshopInspector expanded={inspectorExpanded} />
272-
</Flex>
273-
274-
<div data-portal="" ref={setPortalElement} />
275-
</Flex>
276-
</PortalProvider>
277-
</BoundaryElementProvider>
278-
</ToastProvider>
238+
<Flex data-boundary="" direction="column" height="fill" style={{minWidth: 320}}>
239+
{withNavbar && (
240+
<WorkshopNavbar
241+
inspectorExpanded={inspectorExpanded}
242+
navigatorExpanded={navigatorExpanded}
243+
onInspectorToggle={handleInspectorToggle}
244+
onNavigatorToggle={handleNavigatorToggle}
245+
/>
246+
)}
247+
248+
<Flex flex={1}>
249+
<WorkshopNavigator collections={config.collections} expanded={navigatorExpanded} />
250+
<WorkshopCanvas
251+
frameRef={frame.setElement}
252+
hidden={navigatorExpanded || inspectorExpanded}
253+
/>
254+
<WorkshopInspector expanded={inspectorExpanded} />
255+
</Flex>
256+
</Flex>
279257
</WorkshopProvider>
280258
)
281259
})

src/core/WorkshopCanvas.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {BoxDisplay, Card, Container, Flex, Heading, Spinner, Stack, Text} from '@sanity/ui'
1+
import {Card, Container, Flex, Heading, Spinner, Stack, Text} from '@sanity/ui'
2+
import type {Display} from '@sanity/ui/css'
23
import {memo, useMemo, useState} from 'react'
34
import {styled} from 'styled-components'
45

@@ -37,7 +38,7 @@ export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
3738
[viewportW, viewportH, zoom],
3839
)
3940

40-
const display: BoxDisplay = useMemo(() => (hidden ? 'none' : 'block'), [hidden])
41+
const display = useMemo<Display>(() => (hidden ? 'none' : 'block'), [hidden])
4142

4243
const frameStyle = useMemo(
4344
() => ({
@@ -54,7 +55,7 @@ export const WorkshopCanvas = memo(function WorkshopCanvas(props: {
5455
<Flex align="center" height="fill" justify="center" sizing="border">
5556
{path === '/' && (
5657
<Container width={0}>
57-
<Stack padding={4} space={4}>
58+
<Stack padding={4} gap={4}>
5859
<Heading align="center">{title}</Heading>
5960
<Text align="center" muted>
6061
Browse workshop stories in the navigator to the left.

src/core/WorkshopContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ThemeColorSchemeKey} from '@sanity/ui'
1+
import type {ColorScheme} from '@sanity/ui/theme'
22
import {createContext} from 'react'
33

44
import {WorkshopCollection, WorkshopPlugin, WorkshopScope, WorkshopStory} from './config'
@@ -16,7 +16,7 @@ export interface WorkshopContextValue<CustomMsg = never> {
1616
origin: 'frame' | 'main'
1717
path: string
1818
payload: Record<string, unknown>
19-
scheme: ThemeColorSchemeKey
19+
scheme: ColorScheme
2020
scope: WorkshopScope | null
2121
scopes: WorkshopScope[]
2222
story: WorkshopStory | null

src/core/WorkshopProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ThemeColorSchemeKey} from '@sanity/ui'
1+
import type {ColorScheme} from '@sanity/ui/theme'
22
import {memo, useMemo} from 'react'
33

44
import {WorkshopConfig, WorkshopPlugin} from './config'
@@ -19,7 +19,7 @@ export interface WorkshopProviderProps {
1919
origin: 'frame' | 'main'
2020
path: string
2121
payload: Record<string, unknown>
22-
scheme: ThemeColorSchemeKey
22+
scheme: ColorScheme
2323
viewport?: string
2424
zoom?: number
2525
}

src/core/config/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import {RootTheme} from '@sanity/ui'
2+
33
import {ElementType, ReactNode} from 'react'
44

55
/** @public */
@@ -32,7 +32,6 @@ export interface WorkshopConfig {
3232
frameUrl?: string
3333
plugins?: WorkshopPlugin<any>[]
3434
scopes: WorkshopScope[]
35-
theme?: RootTheme
3635
title?: string
3736
}
3837

0 commit comments

Comments
 (0)