1
1
import { CloseIcon , LeaveIcon } from '@sanity/icons'
2
2
import { Box , Card , Flex , Layer , Stack , Text } from '@sanity/ui'
3
3
import { AnimatePresence , motion , type Transition , type Variants } from 'framer-motion'
4
- import { type KeyboardEvent , memo , useCallback } from 'react'
4
+ import { type KeyboardEvent , memo , useCallback , useMemo } from 'react'
5
5
import TrapFocus from 'react-focus-lock'
6
6
import styled from 'styled-components'
7
7
8
8
import { Button } from '../../../../../ui-components'
9
9
import { UserAvatar } from '../../../../components'
10
- import { type Tool } from '../../../../config'
10
+ import { type NavbarAction , type Tool } from '../../../../config'
11
11
import { useTranslation } from '../../../../i18n'
12
12
import { useColorSchemeSetValue } from '../../../colorScheme'
13
13
import { useToolMenuComponent } from '../../../studio-components-hooks'
@@ -73,14 +73,15 @@ const InnerCardMotion = styled(motion(Card))`
73
73
`
74
74
75
75
interface NavDrawerProps {
76
+ __internal_actions ?: NavbarAction [ ]
76
77
activeToolName ?: string
77
78
isOpen : boolean
78
79
onClose : ( ) => void
79
80
tools : Tool [ ]
80
81
}
81
82
82
83
export const NavDrawer = memo ( function NavDrawer ( props : NavDrawerProps ) {
83
- const { activeToolName, isOpen, onClose, tools} = props
84
+ const { __internal_actions : actions , activeToolName, isOpen, onClose, tools} = props
84
85
85
86
const setScheme = useColorSchemeSetValue ( )
86
87
const { auth, currentUser} = useWorkspace ( )
@@ -98,6 +99,35 @@ export const NavDrawer = memo(function NavDrawer(props: NavDrawerProps) {
98
99
[ onClose ] ,
99
100
)
100
101
102
+ const handleActionClick = useCallback (
103
+ ( action : ( ) => void ) => {
104
+ action ?.( )
105
+ onClose ( )
106
+ } ,
107
+ [ onClose ] ,
108
+ )
109
+
110
+ const actionNodes = useMemo ( ( ) => {
111
+ return actions
112
+ ?. filter ( ( v ) => v . location === 'sidebar' )
113
+ ?. map ( ( action ) => {
114
+ return (
115
+ < Button
116
+ icon = { action ?. icon }
117
+ justify = "flex-start"
118
+ key = { action . name }
119
+ mode = "bleed"
120
+ // eslint-disable-next-line react/jsx-no-bind
121
+ onClick = { ( ) => handleActionClick ( action . onAction ) }
122
+ selected = { action . selected }
123
+ size = "large"
124
+ text = { action . title }
125
+ width = "fill"
126
+ />
127
+ )
128
+ } )
129
+ } , [ actions , handleActionClick ] )
130
+
101
131
return (
102
132
< AnimatePresence >
103
133
{ isOpen && (
@@ -172,6 +202,12 @@ export const NavDrawer = memo(function NavDrawer(props: NavDrawerProps) {
172
202
</ Card >
173
203
174
204
< Flex direction = "column" >
205
+ { actionNodes && (
206
+ < Card flex = "none" padding = { 2 } >
207
+ < Stack space = { 1 } > { actionNodes } </ Stack >
208
+ </ Card >
209
+ ) }
210
+
175
211
{ setScheme && < AppearanceMenu setScheme = { setScheme } /> }
176
212
< LocaleMenu />
177
213
< ManageMenu />
0 commit comments