diff --git a/.storybook/addons.js b/.storybook/addons.js deleted file mode 100644 index 7ab2a22..0000000 --- a/.storybook/addons.js +++ /dev/null @@ -1 +0,0 @@ -import '../dist/src/register'; diff --git a/.storybook/addons.ts b/.storybook/addons.ts new file mode 100644 index 0000000..5b0471f --- /dev/null +++ b/.storybook/addons.ts @@ -0,0 +1 @@ +import "../src/register"; diff --git a/.storybook/config.js b/.storybook/config.ts similarity index 68% rename from .storybook/config.js rename to .storybook/config.ts index 44a8e98..5306be6 100644 --- a/.storybook/config.js +++ b/.storybook/config.ts @@ -1,10 +1,9 @@ -import {addDecorator, configure} from '@storybook/react'; -import * as React from "react"; -import {withThemesProvider} from "../dist/src/index"; +import {addDecorator, configure} from "@storybook/react"; +import {withThemesProvider} from "../src"; const defaultTheme = { name: "DEFAULT", - backgroundColor: 'azure', + backgroundColor: "azure", textColor: "dimgrey", borderRadius: "30px", }; @@ -23,7 +22,8 @@ export const getAllThemes = () => { addDecorator(withThemesProvider(getAllThemes())); // automatically import all files ending in *.stories.js -const req = require.context('../', true, /.stories.tsx/); +// @ts-ignore +const req = require.context("../", true, /.stories.tsx/); function loadStories() { req.keys().forEach((filename) => req(filename)); } diff --git a/package.json b/package.json index 82800ee..6ed51c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storybook-addon-styled-component-theme", - "version": "1.1.0", + "version": "1.1.1", "description": "storybook addon with styled-components theme", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/Themes.tsx b/src/Themes.tsx index 73448a9..242a5a1 100644 --- a/src/Themes.tsx +++ b/src/Themes.tsx @@ -36,15 +36,17 @@ export const Themes = compose( withState("theme", "setTheme", null), withState("themes", "setThemes", List()), withHandlers({ - onSelectTheme: ({channel, setTheme}) => (theme) => { + onSelectTheme: ({channel, setTheme, api}) => (theme) => { setTheme(theme); + api.setQueryParams({theme: theme.name}); channel.emit("selectTheme", theme); }, - onReceiveThemes: ({setTheme, setThemes, channel}) => (newThemes: Theme[]) => { + onReceiveThemes: ({setTheme, setThemes, channel, api}) => (newThemes: Theme[]) => { const themes = List(newThemes); + const themeName = api.getQueryParam("theme"); setThemes(List(themes)); if (themes.count() > 0) { - const theme = themes.first(); + const theme = themes.find((t) => t.name === themeName) || themes.first(); setTheme(theme); channel.emit("selectTheme", theme); }