-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add navbar actions (
@internal
) (#5968)
* feat(core): add navbar actions (`@internal`) * refactor(tasks): use navbar actions
- Loading branch information
1 parent
463d1b6
commit 5c9fb85
Showing
7 changed files
with
132 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,53 @@ | ||
import {PanelRightIcon, TaskIcon} from '@sanity/icons' | ||
import {useCallback, useMemo} from 'react' | ||
import {type NavbarProps} from 'sanity' | ||
|
||
import {TasksNavbarButton, useTasksEnabled} from '../src' | ||
import {useTasks, useTasksEnabled} from '../src' | ||
|
||
export function TasksStudioNavbar(props: NavbarProps) { | ||
const {enabled} = useTasksEnabled() | ||
const EMPTY_ARRAY: [] = [] | ||
|
||
function TasksStudioNavbarInner(props: NavbarProps) { | ||
const {toggleOpen, isOpen} = useTasks() | ||
|
||
const handleAction = useCallback(() => { | ||
toggleOpen() | ||
}, [toggleOpen]) | ||
|
||
const actions = useMemo((): NavbarProps['__internal_actions'] => { | ||
return [ | ||
...(props?.__internal_actions || EMPTY_ARRAY), | ||
{ | ||
icon: PanelRightIcon, | ||
location: 'topbar', | ||
name: 'tasks-topbar', | ||
onAction: handleAction, | ||
selected: isOpen, | ||
title: 'Tasks', | ||
}, | ||
{ | ||
icon: TaskIcon, | ||
location: 'sidebar', | ||
name: 'tasks-sidebar', | ||
onAction: handleAction, | ||
selected: isOpen, | ||
title: 'Tasks', | ||
}, | ||
] | ||
}, [handleAction, isOpen, props?.__internal_actions]) | ||
|
||
if (!enabled) return props.renderDefault(props) | ||
return props.renderDefault({ | ||
...props, | ||
// eslint-disable-next-line camelcase | ||
__internal_rightSectionNode: <TasksNavbarButton />, | ||
__internal_actions: actions, | ||
}) | ||
} | ||
|
||
export function TasksStudioNavbar(props: NavbarProps) { | ||
const {enabled} = useTasksEnabled() | ||
|
||
if (!enabled) { | ||
return props.renderDefault(props) | ||
} | ||
|
||
return <TasksStudioNavbarInner {...props} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './form' | ||
export * from './navbar' | ||
export * from './sidebar' |
27 changes: 0 additions & 27 deletions
27
packages/sanity/src/tasks/src/tasks/components/navbar/TasksNavbarButton.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.