-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2175621
commit 468fb7f
Showing
4 changed files
with
82 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import { addons } from "@storybook/manager-api"; | ||
import { addons, types } from "@storybook/manager-api"; | ||
import { sbTheme } from "./theme"; | ||
|
||
import { ExperimentalDsToggle } from "../stories/addons/ExperimentalDsToggle"; | ||
addons.setConfig({ | ||
theme: sbTheme | ||
}); | ||
|
||
// Register the addon | ||
addons.register("EXPERIMENTAL_DS_ADDON", () => { | ||
// Register the tool | ||
addons.add("EXPERIMENTAL_DS_ADDON_ID", { | ||
type: types.TOOL, | ||
title: "Experimental DS Addon", | ||
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)), | ||
render: ExperimentalDsToggle | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { memo, useCallback, useEffect } from "react"; | ||
|
||
import { useGlobals, useStorybookApi } from "@storybook/manager-api"; | ||
import { Icons, IconButton } from "@storybook/components"; | ||
|
||
export const EXPERIMENTAL_DS_PARAM_KEY = "experimentalDs"; | ||
|
||
export const ExperimentalDsToggle = memo(function ExperimentalDS() { | ||
const [globals, updateGlobals] = useGlobals(); | ||
const api = useStorybookApi(); | ||
|
||
const isActive = [true, "true"].includes(globals[EXPERIMENTAL_DS_PARAM_KEY]); | ||
|
||
const toggleMyTool = useCallback(() => { | ||
updateGlobals({ | ||
[EXPERIMENTAL_DS_PARAM_KEY]: !isActive | ||
}); | ||
}, [isActive, updateGlobals]); | ||
|
||
useEffect(() => { | ||
void api.setAddonShortcut("EXPERIMENTAL_DS_ADDON", { | ||
label: "Toggle Addon [8]", | ||
defaultShortcut: ["8"], | ||
actionName: "ExperimentalDS", | ||
showInMenu: false, | ||
action: toggleMyTool | ||
}); | ||
}, [toggleMyTool, api]); | ||
|
||
return ( | ||
<IconButton | ||
key={"EXPERIMENTAL_DS_ADDO_ID"} | ||
active={isActive} | ||
title="Apply the experimental DS" | ||
onClick={toggleMyTool} | ||
> | ||
<Icons icon="lightning" /> | ||
</IconButton> | ||
); | ||
}); |
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