Skip to content

Commit

Permalink
Merge pull request #7 from storybookjs/rerun-tool
Browse files Browse the repository at this point in the history
"Rerun story" tool
  • Loading branch information
ghengeveld authored Sep 8, 2021
2 parents 1857670 + d0207ba commit c7610a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
21 changes: 6 additions & 15 deletions addons/interactions/src/Tool.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import React, { useCallback } from 'react';
import { useGlobals } from '@storybook/api';
import React from 'react';
import { useChannel } from '@storybook/api';
import { Icons, IconButton } from '@storybook/components';
import { TOOL_ID } from './constants';
import { EVENTS, TOOL_ID } from './constants';

export const Tool = () => {
const [{ myAddon }, updateGlobals] = useGlobals();

const toggleMyTool = useCallback(
() =>
updateGlobals({
myAddon: myAddon ? undefined : true,
}),
[myAddon]
);

const emit = useChannel({});
return (
<IconButton key={TOOL_ID} title="Play" onClick={toggleMyTool}>
<Icons icon="play" />
<IconButton key={TOOL_ID} title="Rerun story" onClick={() => emit(EVENTS.RELOAD)}>
<Icons icon="sync" />
</IconButton>
);
};
3 changes: 0 additions & 3 deletions addons/interactions/src/preset/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import { ADDON_ID, TOOL_ID, PANEL_ID } from "../constants";
import { Tool } from "../Tool";
import { Panel } from "../Panel";

// Register the addon
addons.register(ADDON_ID, () => {
// Register the tool
addons.add(TOOL_ID, {
type: types.TOOL,
title: "Interactions",
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
render: Tool,
});

// Register the panel
addons.add(PANEL_ID, {
type: types.PANEL,
title: "Interactions",
Expand Down

0 comments on commit c7610a7

Please sign in to comment.