File tree Expand file tree Collapse file tree 4 files changed +15
-3
lines changed Expand file tree Collapse file tree 4 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1010
1111- Font-family variables that can be used to customise the sans-serif and monospace fonts used in the editor (#1264 )
1212- Material symbols font to web component preview page since the Design System depends on this (#1261 )
13+ - Ability for plugins to add buttons to the SidebarPanel header (#1270 , #1271 , #1274 )
1314
1415### Changed
1516
Original file line number Diff line number Diff line change @@ -87,7 +87,10 @@ const Sidebar = ({ options = [], plugins = [] }) => {
8787 title : plugin . title ,
8888 position : plugin . position || "top" ,
8989 panel : ( ) => (
90- < SidebarPanel heading = { plugin . heading } buttons = { plugin . buttons || [ ] } >
90+ < SidebarPanel
91+ heading = { plugin . heading }
92+ buttons = { plugin . buttons ? plugin . buttons ( ) : [ ] }
93+ >
9194 { plugin . panel ( ) }
9295 </ SidebarPanel >
9396 ) ,
Original file line number Diff line number Diff line change @@ -336,6 +336,7 @@ describe("When plugins are provided", () => {
336336 heading : "My amazing plugin" ,
337337 title : "my amazing plugin" ,
338338 panel : ( ) => < p > My amazing content</ p > ,
339+ buttons : ( ) => [ < button > My amazing button</ button > ] ,
339340 } ;
340341
341342 describe ( "when plugin has autoOpen true" , ( ) => {
@@ -366,6 +367,10 @@ describe("When plugins are provided", () => {
366367 test ( "Renders the plugin content" , ( ) => {
367368 expect ( screen . queryByText ( "My amazing content" ) ) . toBeInTheDocument ( ) ;
368369 } ) ;
370+
371+ test ( "Renders the plugin buttons" , ( ) => {
372+ expect ( screen . queryByText ( "My amazing button" ) ) . toBeInTheDocument ( ) ;
373+ } ) ;
369374 } ) ;
370375
371376 describe ( "when plugin has autoOpen false" , ( ) => {
Original file line number Diff line number Diff line change @@ -11,16 +11,19 @@ const SidebarPanel = (props) => {
1111 heading,
1212 Footer,
1313 className,
14- buttons = [ ] ,
14+ buttons,
1515 defaultWidth = "320px" ,
1616 } = props ;
1717 const isMobile = useMediaQuery ( { query : MOBILE_MEDIA_QUERY } ) ;
1818
19+ const buttonsIsEmptyArray =
20+ buttons && Array . isArray ( buttons ) && buttons . length === 0 ;
21+
1922 const panelContent = (
2023 < >
2124 < div className = "sidebar__panel-header" >
2225 < h2 className = "sidebar__panel-heading" > { heading } </ h2 >
23- { buttons ?. length > 0 && (
26+ { buttons && ! buttonsIsEmptyArray && (
2427 < div className = "sidebar__panel-buttons" > { buttons } </ div >
2528 ) }
2629 </ div >
You can’t perform that action at this time.
0 commit comments