Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14419 from storybookjs/chore_docs_addons_force_re…
…_render_update Chore: (Docs) Essentials and addons api (snippets and content) updated
- Loading branch information
Showing
16 changed files
with
126 additions
and
13 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
41 changes: 41 additions & 0 deletions
41
docs/snippets/common/addon-consume-and-update-globaltype.js.mdx
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,41 @@ | ||
```js | ||
// your-addon-register-file.js | ||
|
||
import React, { useCallback } from 'react'; | ||
|
||
import { FORCE_RE_RENDER } from '@storybook/core-events'; | ||
import { useGlobals } from '@storybook/api'; | ||
|
||
import { IconButton, Icons } from '@storybook/components'; | ||
|
||
import { addons } from '@storybook/addons'; | ||
|
||
const ExampleToolbar = () => { | ||
const [globals, updateGlobals] = useGlobals(); | ||
|
||
const isActive = globals['my-param-key'] || false; | ||
|
||
// Function that will update the global value and trigger a UI refresh. | ||
const refreshAndUpdateGlobal = () => { | ||
// Updates Storybook global value | ||
updateGlobals({ | ||
['my-param-key']: !isActive, | ||
}), | ||
// Invokes Storybook's addon API method (with the FORCE_RE_RENDER) event to trigger a UI refresh | ||
addons.getChannel().emit(FORCE_RE_RENDER); | ||
}; | ||
|
||
const toggleOutline = useCallback(() => refreshAndUpdateGlobal(), [isActive]); | ||
|
||
return ( | ||
<IconButton | ||
key="Example" | ||
active={isActive} | ||
title="Show a Storybook toolbar" | ||
onClick={toggleOutline} | ||
> | ||
<Icons icon="outline" /> | ||
</IconButton> | ||
); | ||
}; | ||
``` |
2 changes: 1 addition & 1 deletion
2
docs/snippets/common/storybook-addons-api-disablequeryparams.js.mdx
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
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
2 changes: 1 addition & 1 deletion
2
docs/snippets/common/storybook-addons-api-selectincurrentkind.js.mdx
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
2 changes: 1 addition & 1 deletion
2
docs/snippets/common/storybook-addons-api-setqueryparams.js.mdx
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
5 changes: 4 additions & 1 deletion
5
docs/snippets/common/storybook-addons-api-useaddonstate.js.mdx
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
19 changes: 19 additions & 0 deletions
19
docs/snippets/common/storybook-addons-api-useglobal.js.mdx
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,19 @@ | ||
```js | ||
// /my-addon/register.js | ||
|
||
import React from 'react'; | ||
|
||
import { useGlobals } from '@storybook/api'; | ||
|
||
export const Panel = () => { | ||
const [globals, updateGlobals] = useGlobals(); | ||
|
||
const isActive = globals['my-param-key'] || false; | ||
|
||
return ( | ||
<button onClick={() => updateGlobals({ ['my-param-key']: !isActive })}> | ||
{isActive ? 'Hide me!' : 'Show me!'} | ||
</button> | ||
); | ||
}; | ||
``` |
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
6 changes: 5 additions & 1 deletion
6
docs/snippets/common/storybook-addons-api-usestorybookstate.js.mdx
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