-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add progressive disclosure panel item component
This utilises a new context for the panel's menu items. The menu in the panel title is generated from this and the individual items control their display based of if the item is selected in that menu item context.
- Loading branch information
1 parent
1fde44b
commit 39473a5
Showing
5 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/components/src/progressive-disclosure-panel/item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { usePanelContext } from './'; | ||
|
||
// This wraps controls to be conditionally displayed within a progressive | ||
// disclosure panel. It helps prevent props being applied to HTML elements that | ||
// would otherwise be invalid. | ||
const ProgressiveDisclosurePanelItem = ( props ) => { | ||
const { children, isShownByDefault, label } = props; | ||
const menuItems = usePanelContext(); | ||
|
||
// Do not show if menu item not selected and not shown by default. | ||
// If the item has a value that will be reflected in the menu item's | ||
// selected status provided by context. | ||
if ( ! menuItems[ label ] && ! isShownByDefault ) { | ||
return null; | ||
} | ||
|
||
return children; | ||
}; | ||
|
||
export default ProgressiveDisclosurePanelItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters