How to implement a "hidden" side panel?
It is possible to implement a side panel that will not be visible in the list of panels. But still, you can open it based on some user actions.
Polotno itself has several such panels that are visible only on specific button click, for example "clip image".
To implement hidden panel you can do this:
const CustomSection = {
name: 'custom-text',
Tab: () => null,
Panel: observer(({ store }) => {
const text = store.selectedElements[0]?.text;
return (
<div>
<InputGroup
value={text}
onChange={() => {
store.selectedElements[0].set({ text: e.target.value });
}}
/>
</div>
);
}),
};
const sections = [...DEFAULT_SECTIONS, CustomSection];
reaction(
() => {
const textSelected = store.selectedElements[0]?.type === 'text';
return textSelected;
},
(textSelected) => {
if (textSelected) {
store.openSidePanel('custom-text');
}
}
);
export const App = () => {
return (
<PolotnoContainer className="polotno-app-container">
<SidePanelWrap>
<SidePanel store={store} sections={sections} />
</SidePanelWrap>
<WorkspaceWrap>
<Toolbar store={store} downloadButtonEnabled />
<Workspace store={store} />
<ZoomButtons store={store} />
</WorkspaceWrap>
</PolotnoContainer>
);
};
For the demo, try to create a text element. As soon as it is selected, you will see a new side panel opened.