Skip to content

Commit f5f73e4

Browse files
authored
Site Editor: update the edit button (#48584)
1 parent 257a2e8 commit f5f73e4

File tree

11 files changed

+73
-59
lines changed

11 files changed

+73
-59
lines changed

packages/components/src/dropdown-menu/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ function DropdownMenu( dropdownMenuProps ) {
9191
onToggle();
9292
}
9393
};
94+
const { as: Toggle = Button, ...restToggleProps } =
95+
toggleProps ?? {};
96+
9497
const mergedToggleProps = mergeProps(
9598
{
9699
className: classnames(
@@ -100,11 +103,11 @@ function DropdownMenu( dropdownMenuProps ) {
100103
}
101104
),
102105
},
103-
toggleProps
106+
restToggleProps
104107
);
105108

106109
return (
107-
<Button
110+
<Toggle
108111
{ ...mergedToggleProps }
109112
icon={ icon }
110113
onClick={ ( event ) => {
@@ -126,7 +129,7 @@ function DropdownMenu( dropdownMenuProps ) {
126129
showTooltip={ toggleProps?.showTooltip ?? true }
127130
>
128131
{ mergedToggleProps.children }
129-
</Button>
132+
</Toggle>
130133
);
131134
} }
132135
renderContent={ ( props ) => {

packages/edit-site/src/components/add-new-template/new-template-part.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,20 @@ export default function NewTemplatePart( {
8686
setIsModalOpen( false );
8787
}
8888
}
89+
const { as: Toggle = Button, ...restToggleProps } = toggleProps ?? {};
8990

9091
return (
9192
<>
92-
<Button
93-
{ ...toggleProps }
93+
<Toggle
94+
{ ...restToggleProps }
9495
onClick={ () => {
9596
setIsModalOpen( true );
9697
} }
9798
icon={ showIcon ? plus : null }
9899
label={ postType.labels.add_new }
99100
>
100101
{ showIcon ? null : postType.labels.add_new }
101-
</Button>
102+
</Toggle>
102103
{ isModalOpen && (
103104
<CreateTemplatePartModal
104105
closeModal={ () => setIsModalOpen( false ) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import classnames from 'classnames';
5+
6+
/**
7+
* WordPress dependencies
8+
*/
9+
import { Button } from '@wordpress/components';
10+
11+
export default function SidebarButton( props ) {
12+
return (
13+
<Button
14+
{ ...props }
15+
className={ classnames(
16+
'edit-site-sidebar-button',
17+
props.className
18+
) }
19+
/>
20+
);
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.edit-site-sidebar-button {
2+
color: $gray-200;
3+
flex-shrink: 0;
4+
5+
// Focus (resets default button focus and use focus-visible).
6+
&:focus:not(:disabled) {
7+
box-shadow: none;
8+
outline: none;
9+
}
10+
&:focus-visible:not(:disabled) {
11+
box-shadow:
12+
0 0 0 var(--wp-admin-border-width-focus)
13+
var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
14+
outline: 3px solid transparent;
15+
}
16+
17+
&:hover,
18+
&:focus-visible,
19+
&:focus,
20+
&:not([aria-disabled="true"]):active {
21+
color: $white;
22+
}
23+
}

packages/edit-site/src/components/sidebar-navigation-screen-navigation-item/index.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import { useDispatch, useSelect } from '@wordpress/data';
6-
import {
7-
Button,
8-
__experimentalUseNavigator as useNavigator,
9-
} from '@wordpress/components';
6+
import { __experimentalUseNavigator as useNavigator } from '@wordpress/components';
107
import { store as coreStore } from '@wordpress/core-data';
118
import { decodeEntities } from '@wordpress/html-entities';
9+
import { pencil } from '@wordpress/icons';
1210

1311
/**
1412
* Internal dependencies
1513
*/
1614
import SidebarNavigationScreen from '../sidebar-navigation-screen';
1715
import { unlock } from '../../private-apis';
1816
import { store as editSiteStore } from '../../store';
17+
import SidebarButton from '../sidebar-button';
1918

2019
export default function SidebarNavigationScreenNavigationItem() {
2120
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
@@ -43,13 +42,11 @@ export default function SidebarNavigationScreenNavigationItem() {
4342
<SidebarNavigationScreen
4443
title={ post ? decodeEntities( post?.title?.rendered ) : null }
4544
actions={
46-
<Button
47-
variant="primary"
48-
className="edit-site-sidebar-navigation-screen__edit"
45+
<SidebarButton
4946
onClick={ () => setCanvasMode( 'edit' ) }
50-
>
51-
{ __( 'Edit' ) }
52-
</Button>
47+
label={ __( 'Edit' ) }
48+
icon={ pencil }
49+
/>
5350
}
5451
content={
5552
post ? decodeEntities( post?.description?.rendered ) : null

packages/edit-site/src/components/sidebar-navigation-screen-template/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import { useDispatch } from '@wordpress/data';
6-
import { Button } from '@wordpress/components';
6+
import { pencil } from '@wordpress/icons';
77

88
/**
99
* Internal dependencies
@@ -12,6 +12,7 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
1212
import useEditedEntityRecord from '../use-edited-entity-record';
1313
import { unlock } from '../../private-apis';
1414
import { store as editSiteStore } from '../../store';
15+
import SidebarButton from '../sidebar-button';
1516

1617
export default function SidebarNavigationScreenTemplate() {
1718
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
@@ -27,13 +28,11 @@ export default function SidebarNavigationScreenTemplate() {
2728
<SidebarNavigationScreen
2829
title={ getTitle() }
2930
actions={
30-
<Button
31-
variant="primary"
32-
className="edit-site-sidebar-navigation-screen__edit"
31+
<SidebarButton
3332
onClick={ () => setCanvasMode( 'edit' ) }
34-
>
35-
{ __( 'Edit' ) }
36-
</Button>
33+
label={ __( 'Edit' ) }
34+
icon={ pencil }
35+
/>
3736
}
3837
content={ description ? <p>{ description }</p> : undefined }
3938
/>

packages/edit-site/src/components/sidebar-navigation-screen-templates/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useLink } from '../routes/link';
2020
import SidebarNavigationItem from '../sidebar-navigation-item';
2121
import AddNewTemplate from '../add-new-template';
2222
import { store as editSiteStore } from '../../store';
23+
import SidebarButton from '../sidebar-button';
2324

2425
const config = {
2526
wp_template: {
@@ -84,8 +85,7 @@ export default function SidebarNavigationScreenTemplates() {
8485
<AddNewTemplate
8586
templateType={ postType }
8687
toggleProps={ {
87-
className:
88-
'edit-site-sidebar-navigation-screen-templates__add-button',
88+
as: SidebarButton,
8989
} }
9090
/>
9191
)

packages/edit-site/src/components/sidebar-navigation-screen-templates/style.scss

-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@
22
/* Overrides the margin that comes from the Item component */
33
margin-top: $grid-unit-20 !important;
44
}
5-
6-
.edit-site-sidebar-navigation-screen-templates__add-button {
7-
/* Overrides the color for all states of the button */
8-
color: inherit !important;
9-
}

packages/edit-site/src/components/sidebar-navigation-screen/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
__experimentalHStack as HStack,
66
__experimentalVStack as VStack,
77
__experimentalNavigatorToParentButton as NavigatorToParentButton,
8-
Button,
98
} from '@wordpress/components';
109
import { isRTL, __ } from '@wordpress/i18n';
1110
import { chevronRight, chevronLeft } from '@wordpress/icons';
@@ -16,6 +15,7 @@ import { useSelect } from '@wordpress/data';
1615
*/
1716
import { store as editSiteStore } from '../../store';
1817
import { unlock } from '../../private-apis';
18+
import SidebarButton from '../sidebar-button';
1919

2020
export default function SidebarNavigationScreen( {
2121
isRoot,
@@ -39,13 +39,12 @@ export default function SidebarNavigationScreen( {
3939
>
4040
{ ! isRoot ? (
4141
<NavigatorToParentButton
42-
className="edit-site-sidebar-navigation-screen__back"
42+
as={ SidebarButton }
4343
icon={ isRTL() ? chevronRight : chevronLeft }
4444
aria-label={ __( 'Back' ) }
4545
/>
4646
) : (
47-
<Button
48-
className="edit-site-sidebar-navigation-screen__back"
47+
<SidebarButton
4948
icon={ isRTL() ? chevronRight : chevronLeft }
5049
aria-label={ __( 'Navigate to the Dashboard' ) }
5150
href={ dashboardLink || 'index.php' }

packages/edit-site/src/components/sidebar-navigation-screen/style.scss

-25
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,3 @@
2929
color: $white;
3030
margin: 0;
3131
}
32-
33-
.edit-site-sidebar-navigation-screen__edit {
34-
flex-shrink: 0;
35-
}
36-
37-
.edit-site-sidebar-navigation-screen__back {
38-
color: $gray-200;
39-
40-
// Focus (resets default button focus and use focus-visible).
41-
&:focus:not(:disabled) {
42-
box-shadow: none;
43-
outline: none;
44-
}
45-
&:focus-visible:not(:disabled) {
46-
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
47-
outline: 3px solid transparent;
48-
}
49-
50-
&:hover,
51-
&:focus-visible,
52-
&:focus,
53-
&:not([aria-disabled="true"]):active {
54-
color: $white;
55-
}
56-
}

packages/edit-site/src/style.scss

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@import "./components/layout/style.scss";
2323
@import "./components/save-panel/style.scss";
2424
@import "./components/sidebar/style.scss";
25+
@import "./components/sidebar-button/style.scss";
2526
@import "./components/sidebar-navigation-item/style.scss";
2627
@import "./components/sidebar-navigation-screen/style.scss";
2728
@import "./components/sidebar-navigation-screen-templates/style.scss";

0 commit comments

Comments
 (0)