From dbb19521fcaafa918c1218578de1272748006170 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Thu, 2 Sep 2021 18:22:01 +1000
Subject: [PATCH 01/14] Separate default and optional controls in menu
Default and optional controls will now be displayed via separate menu groups and behave slightly differently. Default controls will always be shown and display a checkmark when empty or a minus icon when customized.
---
.../tools-panel-header/component.js | 73 +++++++++++++------
.../tools-panel/tools-panel-header/hook.js | 3 +-
.../src/tools-panel/tools-panel-item/hook.js | 22 +++++-
.../src/tools-panel/tools-panel/hook.js | 39 ++++++++--
4 files changed, 107 insertions(+), 30 deletions(-)
diff --git a/packages/components/src/tools-panel/tools-panel-header/component.js b/packages/components/src/tools-panel/tools-panel-header/component.js
index 09331069378493..d31a50242b0665 100644
--- a/packages/components/src/tools-panel/tools-panel-header/component.js
+++ b/packages/components/src/tools-panel/tools-panel-header/component.js
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
-import { check, moreVertical } from '@wordpress/icons';
+import { check, minus, moreVertical } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
/**
@@ -27,6 +27,9 @@ const ToolsPanelHeader = ( props, forwardedRef ) => {
return null;
}
+ const defaultItems = Object.entries( menuItems?.default || {} );
+ const optionalItems = Object.entries( menuItems?.optional || {} );
+
return (
{ labelText }
@@ -34,26 +37,54 @@ const ToolsPanelHeader = ( props, forwardedRef ) => {
{ ( { onClose } ) => (
<>
-
- { Object.entries( menuItems ).map(
- ( [ label, isSelected ] ) => {
- return (
-
- );
- }
- ) }
-
+ { !! defaultItems?.length && (
+
+ { defaultItems.map(
+ ( [ label, hasValue ] ) => {
+ const icon = hasValue
+ ? minus
+ : check;
+ return (
+
+ );
+ }
+ ) }
+
+ ) }
+ { !! optionalItems?.length && (
+
+ { optionalItems.map(
+ ( [ label, isSelected ] ) => {
+ return (
+
+ );
+ }
+ ) }
+
+ ) }