storybook/docs/snippets/common/storybook-addons-api-useglobal.js.mdx
2023-04-04 20:09:52 +01:00

24 lines
612 B
Plaintext

```js
// my-addon/manager.js|ts
import React from 'react';
import { AddonPanel, Button } from '@storybook/components';
import { useGlobals } from '@storybook/manager-api';
export const Panel = () => {
const [globals, updateGlobals] = useGlobals();
const isActive = globals['my-param-key'] || false; // 👈 Sets visibility based on the global value.
return (
<AddonPanel key="custom-panel" active={isActive}>
<Button onClick={() => updateGlobals({ ['my-param-key']: !isActive })}>
{isActive ? 'Hide the addon panel' : 'Show the panel'}
</Button>
</AddonPanel>
);
};
```