From e5021187e96b78b53203bd95d08d6818aea47d17 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 14 Jul 2021 15:10:31 +0200 Subject: New Ignite 7.0.6 app --- storybook/toggle-storybook.web.tsx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 storybook/toggle-storybook.web.tsx (limited to 'storybook/toggle-storybook.web.tsx') diff --git a/storybook/toggle-storybook.web.tsx b/storybook/toggle-storybook.web.tsx new file mode 100644 index 0000000..f1bd034 --- /dev/null +++ b/storybook/toggle-storybook.web.tsx @@ -0,0 +1,30 @@ +import React, { useState, useEffect } from "react" +import * as QueryString from "query-string" + +interface StorybookQueryParams { + storybook?: boolean +} + +export const ToggleStorybook = (props) => { + const [StorybookUIRoot, setStorybookUIRoot] = useState(null) + const [queryParams, setQueryParams] = useState({}) + + useEffect(() => { + if (__DEV__) { + // Load the storybook UI once + setStorybookUIRoot(() => require("./storybook").StorybookUIRoot) + } + }, []) + + useEffect(() => { + if (__DEV__) { + setQueryParams(QueryString.parse(window.location.search)) + } + }, [window.location.search]) + + if (queryParams?.storybook) { + return StorybookUIRoot ? : null + } else { + return props.children + } +} -- cgit v1.2.3