Skip to content

Commit

Permalink
dev(sanity): update workshop stories with components API
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Oct 6, 2022
1 parent 6f41653 commit 287b20d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ export default function GeneralPreviewStory() {
return false
}, [layout, mediaKey])

const previewProps: Omit<PreviewProps, 'renderDefault' | 'schemaType'> = useMemo(
() => ({
description,
isPlaceholder,
media,
progress,
status: status && (
<Text muted size={1}>
<EditIcon />
</Text>
),
title,
subtitle,
}),
[description, isPlaceholder, media, progress, status, subtitle, title]
)

const component = layout && previewComponents[layout]

if (!component) {
Expand All @@ -84,19 +101,10 @@ export default function GeneralPreviewStory() {
selected={interactive ? selected : undefined}
style={{lineHeight: 0}}
>
{createElement(component as React.ComponentType<PreviewProps>, {
description,
isPlaceholder,
media,
progress,
status: status && (
<Text muted size={1}>
<EditIcon />
</Text>
),
title,
subtitle,
})}
{createElement(
component as React.ComponentType<PreviewProps>,
previewProps as PreviewProps
)}
</Card>
</Container>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ export default function PortableTextPreviewStory() {
return false
}, [layout, mediaKey])

const previewProps: Omit<PreviewProps, 'renderDefault'> = useMemo(
() => ({
actions: withActions && (
<Button fontSize={1} icon={EllipsisVerticalIcon} mode="bleed" paddingX={2} />
),
isPlaceholder,
media,
status: status && (
<Text muted size={1}>
<EditIcon />
</Text>
),
title,
subtitle,
}),
[isPlaceholder, media, status, subtitle, title, withActions]
)

const component = layout && previewComponents[layout]

if (!component) {
Expand All @@ -82,20 +100,7 @@ export default function PortableTextPreviewStory() {
<Flex align="center" height="fill" justify="center" padding={4} sizing="border">
<Container width={1}>
<Card border padding={padding[layout]} radius={1} style={{lineHeight: 0}}>
{createElement(component as ComponentType<PreviewProps>, {
actions: withActions && (
<Button fontSize={1} icon={EllipsisVerticalIcon} mode="bleed" paddingX={2} />
),
isPlaceholder,
media,
status: status && (
<Text muted size={1}>
<EditIcon />
</Text>
),
title,
subtitle,
})}
{createElement(component as ComponentType<PreviewProps>, previewProps as PreviewProps)}
</Card>
</Container>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {FormCallbacksProvider} from '../../../studio/contexts/FormCallbacks'
import {createSchema} from '../../../../schema'
import {render} from './test-utils'

const noopRenderDefault = () => <></>

const defs = {
basic: defineType({
title: 'very basic object',
Expand Down Expand Up @@ -76,7 +78,7 @@ function returnNull(...args: any[]): null {
return null
}

const noopProps: Omit<ObjectInputProps, 'schemaType'> = {
const noopProps: Omit<ObjectInputProps, 'schemaType' | 'renderDefault'> = {
groups: [],
onChange: noop,
onCollapseField: noop,
Expand Down Expand Up @@ -105,7 +107,13 @@ const noopProps: Omit<ObjectInputProps, 'schemaType'> = {

describe('basic examples', () => {
it('renders as empty if given no members', () => {
const {container} = render(<ObjectInput {...noopProps} schemaType={getTestSchema('basic')} />)
const {container} = render(
<ObjectInput
{...noopProps}
renderDefault={noopRenderDefault}
schemaType={getTestSchema('basic')}
/>
)
expect(container).toBeEmptyDOMElement()
})
it('calls renderField and renderInput for each member', () => {
Expand Down Expand Up @@ -157,6 +165,7 @@ describe('basic examples', () => {
schemaType={schemaType}
renderInput={renderInput}
renderField={renderField}
renderDefault={noopRenderDefault}
/>
</FormCallbacksProvider>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import styled from 'styled-components'
import {createConfig, Tool} from '../../../../config'
import {isNonNullable} from '../../../../util/isNonNullable'
import {isTruthy} from '../../../../util/isTruthy'
import {useNavbarComponent} from '../../../studio-components-hooks'
import {StudioProvider} from '../../../StudioProvider'
import {useWorkspace} from '../../../workspace'

const SearchFullscreenPortalCard = styled(Card)`
display: flex;
Expand All @@ -40,7 +40,7 @@ export const NavbarContext = createContext<NavbarContextValue>({
export default function NavbarStory() {
const projectName = useString('Project name', undefined)
const [portalEl, setPortalEl] = useState<HTMLDivElement | null>(null)
const {Navbar} = useWorkspace().studio.components
const Navbar = useNavbarComponent()

// Create configuration
const tools = useTools()
Expand Down

0 comments on commit 287b20d

Please sign in to comment.