Skip to content

Commit

Permalink
fix(desk-tool): hide custom pane content if the pane is collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner authored and hermanwikner committed Oct 19, 2021
1 parent 4fbdb53 commit 1a53747
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {usePaneRouter} from '../../contexts/paneRouter'
import {BaseDeskToolPaneProps} from '../types'
import {DeskToolPaneActionHandler} from '../../types'
import {UserComponentPaneHeader} from './UserComponentPaneHeader'
import {UserComponentPaneContent} from './UserComponentPaneContent'

type UserComponentPaneProps = BaseDeskToolPaneProps<'component'>

Expand Down Expand Up @@ -36,22 +37,23 @@ export function UserComponentPane(props: UserComponentPaneProps) {
menuItemGroups={menuItemGroups}
title={title}
/>
<UserComponentPaneContent>
{isValidElementType(component) &&
createElement(component, {
// this forces a re-render when the router panes change. note: in
// theory, this shouldn't be necessary and the downstream user
// component could internally handle these updates, but this was done
// to preserve older desk tool behavior
key: `${restProps.itemId}-${restProps.childItemId}`,
...restProps,
...restPane,
ref: userComponent,
// NOTE: this is for backwards compatibility (<= 2.20.0)
urlParams: params,
})}

{isValidElementType(component) &&
createElement(component, {
// this forces a re-render when the router panes change. note: in
// theory, this shouldn't be necessary and the downstream user
// component could internally handle these updates, but this was done
// to preserve older desk tool behavior
key: `${restProps.itemId}-${restProps.childItemId}`,
...restProps,
...restPane,
ref: userComponent,
// NOTE: this is for backwards compatibility (<= 2.20.0)
urlParams: params,
})}

{isValidElement(component) && component}
{isValidElement(component) && component}
</UserComponentPaneContent>
</Pane>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Box} from '@sanity/ui'
import React from 'react'
import styled from 'styled-components'
import {usePane} from '../../components'

interface UserComponentPaneContentProps {
children: React.ReactNode
}

const Root = styled(Box)`
position: relative;
`

export function UserComponentPaneContent(props: UserComponentPaneContentProps) {
const {children} = props
const {collapsed} = usePane()

return (
<Root hidden={collapsed} height="fill" overflow="auto">
{children}
</Root>
)
}

3 comments on commit 1a53747

@vercel
Copy link

@vercel vercel bot commented on 1a53747 Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

studio-workshop – ./dev/workshop

studio-workshop.sanity.build
studio-workshop-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 1a53747 Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 1a53747 Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

perf-studio – ./

perf-studio.sanity.build
perf-studio-git-next.sanity.build

Please sign in to comment.