Skip to content

Commit

Permalink
Global Styles Sidebar: Rename NavigationButton so semantics are cle…
Browse files Browse the repository at this point in the history
…arer (#40590)

* PR 📌 Rename NavigationButton so semantics are clearer

* Bandaid fix semantics in header back button
  • Loading branch information
mirka authored Apr 26, 2022
1 parent 1e830c2 commit 1abe799
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 42 deletions.
14 changes: 7 additions & 7 deletions packages/edit-site/src/components/global-styles/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useHasBorderPanel } from './border-panel';
import { useHasColorPanel } from './color-utils';
import { useHasDimensionsPanel } from './dimensions-panel';
import { useHasTypographyPanel } from './typography-panel';
import { NavigationButton } from './navigation-button';
import { NavigationButtonAsItem } from './navigation-button';

function ContextMenu( { name, parentMenu = '' } ) {
const hasTypographyPanel = useHasTypographyPanel( name );
Expand All @@ -24,28 +24,28 @@ function ContextMenu( { name, parentMenu = '' } ) {
return (
<ItemGroup>
{ hasTypographyPanel && (
<NavigationButton
<NavigationButtonAsItem
icon={ typography }
path={ parentMenu + '/typography' }
>
{ __( 'Typography' ) }
</NavigationButton>
</NavigationButtonAsItem>
) }
{ hasColorPanel && (
<NavigationButton
<NavigationButtonAsItem
icon={ color }
path={ parentMenu + '/colors' }
>
{ __( 'Colors' ) }
</NavigationButton>
</NavigationButtonAsItem>
) }
{ hasLayoutPanel && (
<NavigationButton
<NavigationButtonAsItem
icon={ layout }
path={ parentMenu + '/layout' }
>
{ __( 'Layout' ) }
</NavigationButton>
</NavigationButtonAsItem>
) }
</ItemGroup>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/edit-site/src/components/global-styles/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { chevronRight, chevronLeft } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { NavigationBackButton } from './navigation-button';
import { NavigationBackButtonAsItem } from './navigation-button';

function ScreenHeader( { title, description } ) {
return (
<VStack spacing={ 2 }>
<HStack spacing={ 2 }>
<View>
<NavigationBackButton
<View role="list">
<NavigationBackButtonAsItem
icon={ isRTL() ? chevronRight : chevronLeft }
size="small"
aria-label={ __( 'Navigate to the previous view' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ function GenericNavigationButton( { icon, children, ...props } ) {
);
}

function NavigationButton( props ) {
function NavigationButtonAsItem( props ) {
return <NavigatorButton as={ GenericNavigationButton } { ...props } />;
}

function NavigationBackButton( props ) {
function NavigationBackButtonAsItem( props ) {
return <NavigatorBackButton as={ GenericNavigationButton } { ...props } />;
}

export { NavigationButton, NavigationBackButton };
export { NavigationButtonAsItem, NavigationBackButtonAsItem };
6 changes: 3 additions & 3 deletions packages/edit-site/src/components/global-styles/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useMemo } from '@wordpress/element';
* Internal dependencies
*/
import Subtitle from './subtitle';
import { NavigationButton } from './navigation-button';
import { NavigationButtonAsItem } from './navigation-button';
import { useSetting } from './hooks';
import ColorIndicatorWrapper from './color-indicator-wrapper';

Expand Down Expand Up @@ -58,7 +58,7 @@ function Palette( { name } ) {
<VStack spacing={ 3 }>
<Subtitle>{ __( 'Palette' ) }</Subtitle>
<ItemGroup isBordered isSeparated>
<NavigationButton path={ screenPath }>
<NavigationButtonAsItem path={ screenPath }>
<HStack
direction={
colors.length === 0 ? 'row-reverse' : 'row'
Expand All @@ -73,7 +73,7 @@ function Palette( { name } ) {
</ZStack>
<FlexItem>{ paletteButtonText }</FlexItem>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
</ItemGroup>
</VStack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useHasColorPanel } from './color-utils';
import { useHasDimensionsPanel } from './dimensions-panel';
import { useHasTypographyPanel } from './typography-panel';
import ScreenHeader from './header';
import { NavigationButton } from './navigation-button';
import { NavigationButtonAsItem } from './navigation-button';

function useSortedBlockTypes() {
const blockItems = useSelect(
Expand Down Expand Up @@ -61,12 +61,12 @@ function BlockMenuItem( { block } ) {
}

return (
<NavigationButton path={ '/blocks/' + block.name }>
<NavigationButtonAsItem path={ '/blocks/' + block.name }>
<HStack justify="flex-start">
<BlockIcon icon={ block.icon } />
<FlexItem>{ block.title }</FlexItem>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/edit-site/src/components/global-styles/screen-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
*/
import ScreenHeader from './header';
import Palette from './palette';
import { NavigationButton } from './navigation-button';
import { NavigationButtonAsItem } from './navigation-button';
import { getSupportedGlobalStylesPanels, useStyle } from './hooks';
import Subtitle from './subtitle';
import ColorIndicatorWrapper from './color-indicator-wrapper';
Expand All @@ -33,7 +33,7 @@ function BackgroundColorItem( { name, parentMenu } ) {
}

return (
<NavigationButton path={ parentMenu + '/colors/background' }>
<NavigationButtonAsItem path={ parentMenu + '/colors/background' }>
<HStack justify="flex-start">
<ColorIndicatorWrapper expanded={ false }>
<ColorIndicator
Expand All @@ -42,7 +42,7 @@ function BackgroundColorItem( { name, parentMenu } ) {
</ColorIndicatorWrapper>
<FlexItem>{ __( 'Background' ) }</FlexItem>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
);
}

Expand All @@ -56,14 +56,14 @@ function TextColorItem( { name, parentMenu } ) {
}

return (
<NavigationButton path={ parentMenu + '/colors/text' }>
<NavigationButtonAsItem path={ parentMenu + '/colors/text' }>
<HStack justify="flex-start">
<ColorIndicatorWrapper expanded={ false }>
<ColorIndicator colorValue={ color } />
</ColorIndicatorWrapper>
<FlexItem>{ __( 'Text' ) }</FlexItem>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
);
}

Expand All @@ -77,14 +77,14 @@ function LinkColorItem( { name, parentMenu } ) {
}

return (
<NavigationButton path={ parentMenu + '/colors/link' }>
<NavigationButtonAsItem path={ parentMenu + '/colors/link' }>
<HStack justify="flex-start">
<ColorIndicatorWrapper expanded={ false }>
<ColorIndicator colorValue={ color } />
</ColorIndicatorWrapper>
<FlexItem>{ __( 'Links' ) }</FlexItem>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
);
}

Expand Down
30 changes: 17 additions & 13 deletions packages/edit-site/src/components/global-styles/screen-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { store as coreStore } from '@wordpress/core-data';
* Internal dependencies
*/
import { IconWithCurrentColor } from './icon-with-current-color';
import { NavigationButton } from './navigation-button';
import { NavigationButtonAsItem } from './navigation-button';
import ContextMenu from './context-menu';
import StylesPreview from './preview';

Expand All @@ -44,16 +44,20 @@ function ScreenRoot() {
</CardMedia>
</Card>
{ !! variations?.length && (
<NavigationButton path="/variations">
<HStack justify="space-between">
<FlexItem>{ __( 'Browse styles' ) }</FlexItem>
<IconWithCurrentColor
icon={
isRTL() ? chevronLeft : chevronRight
}
/>
</HStack>
</NavigationButton>
<ItemGroup>
<NavigationButtonAsItem path="/variations">
<HStack justify="space-between">
<FlexItem>
{ __( 'Browse styles' ) }
</FlexItem>
<IconWithCurrentColor
icon={
isRTL() ? chevronLeft : chevronRight
}
/>
</HStack>
</NavigationButtonAsItem>
</ItemGroup>
) }
<ContextMenu />
</VStack>
Expand All @@ -77,14 +81,14 @@ function ScreenRoot() {
) }
</Spacer>
<ItemGroup>
<NavigationButton path="/blocks">
<NavigationButtonAsItem path="/blocks">
<HStack justify="space-between">
<FlexItem>{ __( 'Blocks' ) }</FlexItem>
<IconWithCurrentColor
icon={ isRTL() ? chevronLeft : chevronRight }
/>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
</ItemGroup>
</CardBody>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
* Internal dependencies
*/
import ScreenHeader from './header';
import { NavigationButton } from './navigation-button';
import { NavigationButtonAsItem } from './navigation-button';
import { useStyle } from './hooks';
import Subtitle from './subtitle';
import TypographyPanel from './typography-panel';
Expand Down Expand Up @@ -44,7 +44,7 @@ function Item( { name, parentMenu, element, label } ) {
}

return (
<NavigationButton path={ parentMenu + '/typography/' + element }>
<NavigationButtonAsItem path={ parentMenu + '/typography/' + element }>
<HStack justify="flex-start">
<FlexItem
className="edit-site-global-styles-screen-typography__indicator"
Expand All @@ -62,7 +62,7 @@ function Item( { name, parentMenu, element, label } ) {
</FlexItem>
<FlexItem>{ label }</FlexItem>
</HStack>
</NavigationButton>
</NavigationButtonAsItem>
);
}

Expand Down

0 comments on commit 1abe799

Please sign in to comment.