API to render and manipulate extensions of type Panel.
1 2type LifecycleCallback = (container: HTMLElement) => void; interface PanelApi { onMount: (callback: LifecycleCallback) => PanelApi; onUnmount: (callback: LifecycleCallback) => PanelApi; }
Provides a container to render custom content in it.
Name | Type | Description |
---|---|---|
container | HTMLElement | HTML element to be used as a container to render custom content. |
1 2import { PanelExtension } from '@atlassian/clientside-extensions'; /** * @clientside-extension * @extension-point reff.plugins-example-location */ export default PanelExtension.factory(() => { function getPanelContent() { return ` <h4>Cool panel</h4> <p>This is some cool content generated with JS</p> `; } return { onAction: (panelApi) => { panelApi.onMount((container) => { container.innerHTML = getPanelContent(); }); }, }; });
Allows to set a cleanup callback to be called when the provided container is about to be deleted.
Name | Type | Description |
---|---|---|
container | HTMLElement | HTML element that was provided to render custom content in it. It's important to unmount any React component you've mounted in there to avoid keeping the component alive when the container is destroyed. |
1 2import { PanelExtension } from '@atlassian/clientside-extensions'; /** * @clientside-extension * @extension-point reff.plugins-example-location */ export default PanelExtension.factory(() => { const onClick = () => { alert('You clicked a button'); }; return { label: 'JS Panel', onAction: (panelApi) => { let button; panelApi .onMount((container) => { button = document.createElement('button'); button.innerText = 'Click me!'; button.addEventListener('click', onClick); container.appendChild(button); }) .onUnmount((container) => { // use to cleanup any event listener, subscription, or unmount components button.removeEventListener('click', onClick); }); }, }; });
Rate this page: