1
1
import { ArrowLeftIcon , CloseIcon , SplitVerticalIcon } from '@sanity/icons'
2
2
import { Flex } from '@sanity/ui'
3
3
import type * as React from 'react'
4
- import { createElement , forwardRef , memo , useMemo } from 'react'
4
+ import { createElement , forwardRef , memo , useMemo , useState } from 'react'
5
5
import { useFieldActions , useTimelineSelector , useTranslation } from 'sanity'
6
6
7
7
import { Button , TooltipDelayGroupProvider } from '../../../../../ui-components'
8
8
import {
9
9
PaneContextMenuButton ,
10
10
PaneHeader ,
11
11
PaneHeaderActionButton ,
12
+ RenderActionCollectionState ,
12
13
usePane ,
13
14
usePaneRouter ,
14
15
} from '../../../../components'
15
16
import { structureLocaleNamespace } from '../../../../i18n'
16
17
import { isMenuNodeButton , isNotMenuNodeButton , resolveMenuNodes } from '../../../../menuNodes'
17
18
import { type PaneMenuItem } from '../../../../types'
18
19
import { useStructureTool } from '../../../../useStructureTool'
20
+ import { ActionDialogWrapper , ActionMenuListItem } from '../../statusBar/ActionMenuButton'
19
21
import { TimelineMenu } from '../../timeline'
20
22
import { useDocumentPane } from '../../useDocumentPane'
21
23
import { DocumentHeaderTabs } from './DocumentHeaderTabs'
@@ -33,6 +35,8 @@ export const DocumentPanelHeader = memo(
33
35
) {
34
36
const { menuItems} = _props
35
37
const {
38
+ actions,
39
+ editState,
36
40
onMenuAction,
37
41
onPaneClose,
38
42
onPaneSplit,
@@ -46,6 +50,7 @@ export const DocumentPanelHeader = memo(
46
50
const { features} = useStructureTool ( )
47
51
const { index, BackLink, hasGroupSiblings} = usePaneRouter ( )
48
52
const { actions : fieldActions } = useFieldActions ( )
53
+ const [ referenceElement , setReferenceElement ] = useState < HTMLElement | null > ( null )
49
54
50
55
const menuNodes = useMemo (
51
56
( ) =>
@@ -129,8 +134,35 @@ export const DocumentPanelHeader = memo(
129
134
{ menuButtonNodes . map ( ( item ) => (
130
135
< PaneHeaderActionButton key = { item . key } node = { item } />
131
136
) ) }
132
-
133
- < PaneContextMenuButton nodes = { contextMenuNodes } key = "context-menu" />
137
+ { editState && (
138
+ < RenderActionCollectionState
139
+ actions = { actions || [ ] }
140
+ actionProps = { editState }
141
+ group = "paneActions"
142
+ >
143
+ { ( { states} ) => (
144
+ < ActionDialogWrapper actionStates = { states } referenceElement = { referenceElement } >
145
+ { ( { handleAction} ) => (
146
+ < div ref = { setReferenceElement } >
147
+ < PaneContextMenuButton
148
+ nodes = { contextMenuNodes }
149
+ key = "context-menu"
150
+ actionsNodes = { states ?. map ( ( actionState , actionIndex ) => (
151
+ < ActionMenuListItem
152
+ key = { actionState . label }
153
+ actionState = { actionState }
154
+ disabled = { Boolean ( actionState . disabled ) }
155
+ index = { actionIndex }
156
+ onAction = { handleAction }
157
+ />
158
+ ) ) }
159
+ />
160
+ </ div >
161
+ ) }
162
+ </ ActionDialogWrapper >
163
+ ) }
164
+ </ RenderActionCollectionState >
165
+ ) }
134
166
135
167
{ showSplitPaneButton && (
136
168
< Button
0 commit comments