Skip to content
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

Sidebar: Add list view tab for Navigation block et al. #45483

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import { TabPanel } from '@wordpress/components';
/**
* Internal dependencies
*/
import { TAB_SETTINGS, TAB_APPEARANCE } from './utils';
import { TAB_SETTINGS, TAB_APPEARANCE, TAB_LIST_VIEW } from './utils';
draganescu marked this conversation as resolved.
Show resolved Hide resolved
import AppearanceTab from './appearance-tab';
import SettingsTab from './settings-tab';
import { default as ListViewTab, useIsListViewDisabled } from './list-view-tab';

const tabs = [ TAB_APPEARANCE, TAB_SETTINGS ];
const defaultTabs = [ TAB_APPEARANCE, TAB_SETTINGS ];
const tabsWithListView = [ TAB_LIST_VIEW, TAB_APPEARANCE, TAB_SETTINGS ];

export default function InspectorControlsTabs( {
blockName,
clientId,
hasBlockStyles,
} ) {
const tabs = useIsListViewDisabled( blockName )
? defaultTabs
: tabsWithListView;

return (
<TabPanel className="block-editor-block-inspector__tabs" tabs={ tabs }>
{ ( tab ) => {
Expand All @@ -36,6 +42,15 @@ export default function InspectorControlsTabs( {
/>
);
}

if ( tab.name === TAB_LIST_VIEW.name ) {
return (
<ListViewTab
blockName={ blockName }
hasSingleBlockSelection={ !! blockName }
/>
);
}
} }
</TabPanel>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* WordPress dependencies
*/
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import InspectorControls from '../inspector-controls';
import InspectorControlsGroups from '../inspector-controls/groups';

// This tab restricts the blocks that may render to it via the allowlist below.
const allowlist = [ 'core/navigation' ];

export const useIsListViewDisabled = ( blockName ) => {
return ! allowlist.includes( blockName );
};

const ListViewTab = ( { blockName, hasSingleBlockSelection } ) => {
const { list } = InspectorControlsGroups;
const fills = useSlotFills( list.Slot.__unstableName ) || [];

// Unlike other tabs the List View is much more niche. As such it will be
// omitted if the current block isn't in the allowlist.
if ( useIsListViewDisabled( blockName ) ) {
return;
}

return (
<>
{ ! fills.length && (
<span className="block-editor-block-inspector__no-block-tools">
{ hasSingleBlockSelection
? __( 'This block has no list options.' )
: __( 'The selected blocks have no list options.' ) }
Comment on lines +35 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not real clear on which blocks will be rendering what controls to this tab so the wording here is pretty poor. Any suggestions?

</span>
) }
<InspectorControls.Slot __experimentalGroup="list" />
</>
);
};

export default ListViewTab;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { cog, styles } from '@wordpress/icons';
import { cog, styles, listView } from '@wordpress/icons';

export const TAB_SETTINGS = {
name: 'settings',
Expand All @@ -18,3 +18,11 @@ export const TAB_APPEARANCE = {
icon: styles,
className: 'block-editor-block-inspector__tab-item',
};

export const TAB_LIST_VIEW = {
name: 'list',
title: 'List View',
value: 'list-view',
icon: listView,
className: 'block-editor-block-inspector__tab-item',
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const InspectorControlsDimensions = createSlotFill(
const InspectorControlsTypography = createSlotFill(
'InspectorControlsTypography'
);
const InspectorControlsListView = createSlotFill( 'InspectorControlsListView' );

const groups = {
default: InspectorControlsDefault,
advanced: InspectorControlsAdvanced,
border: InspectorControlsBorder,
color: InspectorControlsColor,
dimensions: InspectorControlsDimensions,
list: InspectorControlsListView,
typography: InspectorControlsTypography,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ const MenuInspectorControls = ( {
} ) => {
const isOffCanvasNavigationEditorEnabled =
window?.__experimentalEnableOffCanvasNavigationEditor === true;
const menuControlsSlot = window?.__experimentalEnableBlockInspectorTabs
? 'list'
: undefined;

return (
<InspectorControls>
<InspectorControls __experimentalGroup={ menuControlsSlot }>
<PanelBody
title={
isOffCanvasNavigationEditorEnabled ? null : __( 'Menu' )
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Enhancements

- `ColorPalette`, `BorderBox`, `BorderBoxControl`: polish and DRY prop types, add default values ([#45463](https://github.com/WordPress/gutenberg/pull/45463)).
- `TabPanel`: Add ability to set icon only tab buttons ([#45005](https://github.com/WordPress/gutenberg/pull/45005)).

### Bug Fix

Expand Down