-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Refactor the preferences modal to use the new Navigator components #35142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3a86d0f
d0fedfc
7e2de0d
66d7117
5b274e1
d885b07
ea3aceb
e0bd5e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,21 @@ import { get } from 'lodash'; | |
| * WordPress dependencies | ||
| */ | ||
| import { | ||
| __experimentalNavigation as Navigation, | ||
| __experimentalNavigationMenu as NavigationMenu, | ||
| __experimentalNavigationItem as NavigationItem, | ||
| __experimentalNavigatorProvider as NavigatorProvider, | ||
| __experimentalNavigatorScreen as NavigatorScreen, | ||
| __experimentalUseNavigator as useNavigator, | ||
| __experimentalItemGroup as ItemGroup, | ||
| __experimentalItem as Item, | ||
| __experimentalHStack as HStack, | ||
| __experimentalTruncate as Truncate, | ||
| FlexItem, | ||
| Modal, | ||
| TabPanel, | ||
| Button, | ||
| Card, | ||
| CardBody, | ||
| } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { isRTL, __ } from '@wordpress/i18n'; | ||
| import { useViewportMatch } from '@wordpress/compose'; | ||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||
| import { useMemo, useCallback, useState } from '@wordpress/element'; | ||
|
|
@@ -26,6 +34,7 @@ import { | |
| store as editorStore, | ||
| } from '@wordpress/editor'; | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
| import { chevronLeft, chevronRight, Icon } from '@wordpress/icons'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
|
|
@@ -44,6 +53,21 @@ import BlockManager from '../block-manager'; | |
| const MODAL_NAME = 'edit-post/preferences'; | ||
| const PREFERENCES_MENU = 'preferences-menu'; | ||
|
|
||
| function NavigationButton( { | ||
| as: Tag = Button, | ||
| path, | ||
| isBack = false, | ||
| ...props | ||
| } ) { | ||
| const navigator = useNavigator(); | ||
| return ( | ||
| <Tag | ||
| onClick={ () => navigator.push( path, { isBack } ) } | ||
| { ...props } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default function PreferencesModal() { | ||
| const isLargeViewport = useViewportMatch( 'medium' ); | ||
| const { closeModal } = useDispatch( editPostStore ); | ||
|
|
@@ -301,34 +325,63 @@ export default function PreferencesModal() { | |
| ); | ||
| } else { | ||
| modalContent = ( | ||
| <Navigation | ||
| activeMenu={ activeMenu } | ||
| onActivateMenu={ setActiveMenu } | ||
| > | ||
| <NavigationMenu menu={ PREFERENCES_MENU }> | ||
| { tabs.map( ( tab ) => { | ||
| return ( | ||
| <NavigationItem | ||
| key={ tab.name } | ||
| title={ tab.title } | ||
| navigateToMenu={ tab.name } | ||
| /> | ||
| ); | ||
| } ) } | ||
| </NavigationMenu> | ||
| { sections.map( ( section ) => { | ||
| return ( | ||
| <NavigationMenu | ||
| key={ `${ section.name }-menu` } | ||
| menu={ section.name } | ||
| title={ section.tabLabel } | ||
| parentMenu={ PREFERENCES_MENU } | ||
| > | ||
| <NavigationItem>{ section.content }</NavigationItem> | ||
| </NavigationMenu> | ||
| ); | ||
| } ) } | ||
| </Navigation> | ||
| <Card isBorderless> | ||
| <CardBody> | ||
| <NavigatorProvider initialPath="/"> | ||
| <NavigatorScreen path="/"> | ||
| <ItemGroup> | ||
| { tabs.map( ( tab ) => { | ||
| return ( | ||
| <NavigationButton | ||
| key={ tab.name } | ||
| path={ tab.name } | ||
| as={ Item } | ||
| isAction | ||
| > | ||
| <HStack justify="space-between"> | ||
youknowriad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <FlexItem> | ||
| <Truncate> | ||
| { tab.title } | ||
| </Truncate> | ||
| </FlexItem> | ||
| <FlexItem> | ||
| <Icon | ||
| icon={ | ||
| isRTL() | ||
| ? chevronLeft | ||
| : chevronRight | ||
| } | ||
| /> | ||
| </FlexItem> | ||
| </HStack> | ||
| </NavigationButton> | ||
| ); | ||
| } ) } | ||
| </ItemGroup> | ||
| </NavigatorScreen> | ||
| { sections.map( ( section ) => { | ||
| return ( | ||
| <NavigatorScreen | ||
| key={ `${ section.name }-menu` } | ||
| path={ section.name } | ||
| > | ||
| <NavigationButton | ||
| path="/" | ||
| icon={ | ||
| isRTL() ? chevronRight : chevronLeft | ||
| } | ||
| isBack | ||
| > | ||
| { __( 'Back' ) } | ||
| </NavigationButton> | ||
| <h2>{ section.tabLabel }</h2> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we add a css class here and style better as in trunk? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally don't feel like the styles in trunk (the ones inherited from the menus UI) work well here. I prefer the default h2 styles, that said, I'm happy to update if y'all feel otherwise. |
||
| { section.content } | ||
| </NavigatorScreen> | ||
| ); | ||
| } ) } | ||
| </NavigatorProvider> | ||
| </CardBody> | ||
| </Card> | ||
| ); | ||
| } | ||
| return ( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.