-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Refactor preferences modal to the interface package #34195
Conversation
Size Change: +2.69 kB (0%) Total Size: 1.04 MB
ℹ️ View Unchanged
|
37872a6
to
b227687
Compare
|
||
return ( | ||
<PreferencesModal onRequestClose={ closeModal }> | ||
<PreferencesModalTabs tabs={ tabs } /> |
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.
I would personally prefer to see several nested PreferencesModalTab
components here rather than the array passed as a prop.
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.
I agree with that. It's a side effect of building on the TabPanel component, which works this way:
https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/tab-panel/README.md
I suppose that component could be reworked, deprecated and replaced, or the modal could use its own very similar system.
Weighing the effort vs reward, I'm not sure the array API is bad enough to warrant such a refactor.
feature, | ||
...props | ||
} ) { | ||
const isChecked = useSelect( |
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.
The difference between PreferencesModalFeatureToggle
and PreferencesModalToggle
is very subtle. Is it worth exposing both components as part of the public API?
export { default as ActionItem } from './action-item'; | ||
export { default as PinnedItems } from './pinned-items'; | ||
export { default as PreferencesModal } from './preferences-modal'; | ||
export { default as PreferencesModalTabs } from './preferences-modal/tabs'; |
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.
Are tabs, sections, and toggles specific to the modal, or can they be used in any place?
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.
They're specific to the modal, there's quite a bit of CSS to make it appear the way it does.
<PreferencesModalFeatureToggle | ||
scope="core/edit-post" | ||
feature="focusMode" | ||
help={ __( | ||
'Highlights the current block and fades other content.' | ||
) } | ||
label={ __( 'Spotlight mode' ) } | ||
/> |
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.
It's very similar to:
It makes me wonder whether we should compose those components differently. What about we build a general-purpose feature toggle button and we use as
prop to render it differently depending on the context:
<EditorFeatureToggle
as={ PreferencesModalToggle }
scope="core/edit-post"
feature="focusMode"
help={ __(
'Highlights the current block and fades other content.'
) }
label={ __( 'Spotlight mode' ) }
/>
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.
Hmm, yep, or a hook:
const props = useFeaturePreference( 'core/edit-post', 'topToolbar' );
return (
<PreferencesModalToggle
label={ __( 'Top toolbar' ) }
{ ...props }
/>
);
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.
I had a look into it. I'm not sure it'd result in much gain, there would still be three components exported (EditorFeatureToggle
, MoreMenuToggle
and PreferencesModalToggle
), which is more consistent, but I think it makes the API more complicated than a straightforward component that the implementer can import.
The problem with as
is that it requires a component passed to it to have a particular interface (supporting props like value
and onChange
), so as implementers we end up writing adapter components to map those props to the underlying MenuItem
(isSelected
/ onClick
) and ToggleControl
(checked
/ onChange
) components.
A hook at least allows rewiring the props, but that can be verbose if there are lots of preferences (which is generally the case).
So I'm not sure it's worth reworking this.
bf8686b
to
d2c6da4
Compare
Description
Partly addresses #31965. Built on top of #34154.
Refactors the editor preferences modal to the interface package so that it can be implemented more easily in other editors.
How has this been tested?
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.js
files for terms that need renaming or removal).