-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Edit Post: Refactor More (Ellipsis) Menu #5161
Changes from all commits
92a52de
01ecb21
705d783
e3df2c9
02fe29b
235ef3a
3a1701f
98c64c5
462482d
28e3031
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import MenuItemsToggle from './menu-items-toggle'; | ||
|
||
export default function MenuItemsChoice( { | ||
choices = [], | ||
onSelect, | ||
value, | ||
} ) { | ||
return choices.map( ( item ) => { | ||
const isSelected = value === item.value; | ||
return ( | ||
<MenuItemsToggle | ||
key={ item.value } | ||
label={ item.label } | ||
isSelected={ isSelected } | ||
shortcut={ item.shortcut } | ||
onClick={ () => { | ||
if ( ! isSelected ) { | ||
onSelect( item.value ); | ||
} | ||
} } | ||
/> | ||
); | ||
} ); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MenuItemsGroup should match snapshot 1`] = ` | ||
<div | ||
className="components-menu-items-group" | ||
> | ||
<div | ||
className="components-menu-items-group__label" | ||
id="components-menu-items-group-label-1" | ||
> | ||
My group | ||
</div> | ||
<NavigableMenu | ||
aria-labelledby="components-menu-items-group-label-1" | ||
orientation="vertical" | ||
> | ||
<p | ||
key=".0" | ||
> | ||
My item | ||
</p> | ||
</NavigableMenu> | ||
</div> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { MenuItemsGroup } from '../menu-items-group'; | ||
|
||
describe( 'MenuItemsGroup', () => { | ||
test( 'should render null when no children provided', () => { | ||
const wrapper = shallow( <MenuItemsGroup /> ); | ||
|
||
expect( wrapper.html() ).toBe( null ); | ||
} ); | ||
|
||
test( 'should match snapshot', () => { | ||
const wrapper = shallow( | ||
<MenuItemsGroup | ||
label="My group" | ||
instanceId="1" | ||
> | ||
<p>My item</p> | ||
</MenuItemsGroup> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
} ); |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,19 +2,18 @@ | |||||||||||
* WordPress dependencies | ||||||||||||
*/ | ||||||||||||
import { __ } from '@wordpress/i18n'; | ||||||||||||
import { IconButton, Dropdown } from '@wordpress/components'; | ||||||||||||
import { IconButton, Dropdown, MenuItemsGroup } from '@wordpress/components'; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Internal dependencies | ||||||||||||
*/ | ||||||||||||
import './style.scss'; | ||||||||||||
import ModeSwitcher from '../mode-switcher'; | ||||||||||||
import FixedToolbarToggle from '../fixed-toolbar-toggle'; | ||||||||||||
import EditorActions from '../editor-actions'; | ||||||||||||
|
||||||||||||
const element = ( | ||||||||||||
const MoreMenu = () => ( | ||||||||||||
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. Did this need to be changed to a function? See also an explanation of this type of optimization: https://babeljs.io/docs/plugins/transform-react-constant-elements/ 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. That's interesting. I haven't seen it before in the React docs.
Can we enable the transform instead and leave all the low-level optimizations to Babel? |
||||||||||||
<Dropdown | ||||||||||||
className="edit-post-ellipsis-menu" | ||||||||||||
className="edit-post-more-menu" | ||||||||||||
position="bottom left" | ||||||||||||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||||||||||||
<IconButton | ||||||||||||
|
@@ -25,19 +24,16 @@ const element = ( | |||||||||||
/> | ||||||||||||
) } | ||||||||||||
renderContent={ ( { onClose } ) => ( | ||||||||||||
<div> | ||||||||||||
<div className="edit-post-more-menu__content"> | ||||||||||||
<ModeSwitcher onSelect={ onClose } /> | ||||||||||||
<div className="edit-post-ellipsis-menu__separator" /> | ||||||||||||
<FixedToolbarToggle onToggle={ onClose } /> | ||||||||||||
<div className="edit-post-ellipsis-menu__separator" /> | ||||||||||||
<EditorActions /> | ||||||||||||
<MenuItemsGroup | ||||||||||||
label={ __( 'Tools' ) } | ||||||||||||
filterName="editPost.MoreMenu.tools" | ||||||||||||
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. Conceptually-speaking, why do we need two things - plugin slots and filterable menus - to express the same idea of "add to this menu" ? As of current master, we have both in this menu, and it's not clear why I would use one or the other, or why one can't be satisfied by the other. 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. gutenberg/edit-post/components/header/more-menu/index.js Lines 36 to 40 in f175813
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. My guess is filterable menus were some of the earlier experiments, partly motivated by the emergence of 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. cc @gziolo I think he was talking about removing those at some point? 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. Yes, we should remove those filters and replace the only occurrence of hook based extension with slot and fill. As @mcsf already pointed out, this was an early exploration which turned out to be suboptimal from developer’s standpoint. I had it planned to refactor on my todos list but it was never a priority. I will take care of it this week to avoid confusion. |
||||||||||||
/> | ||||||||||||
</div> | ||||||||||||
) } | ||||||||||||
/> | ||||||||||||
); | ||||||||||||
|
||||||||||||
function EllipsisMenu() { | ||||||||||||
return element; | ||||||||||||
} | ||||||||||||
|
||||||||||||
export default EllipsisMenu; | ||||||||||||
export default MoreMenu; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.edit-post-more-menu { | ||
// the padding and margin of the more menu is intentionally non-standard | ||
@include break-small() { | ||
margin-left: 4px; | ||
} | ||
|
||
.components-icon-button { | ||
padding: 8px 4px; | ||
width: auto; | ||
} | ||
|
||
.components-button svg { | ||
transform: rotate(90deg); | ||
} | ||
} | ||
|
||
.edit-post-more-menu__content { | ||
.components-menu-items-group:not(:last-child) { | ||
border-bottom: 1px solid $light-gray-500; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import './copy-content'; | ||
import './more-menu'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
.components-menu-items__group
https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#css
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #5218 to address it.