diff --git a/core/core/src/document.ts b/core/core/src/document.ts index 1d537d4f1..2f72bb46b 100644 --- a/core/core/src/document.ts +++ b/core/core/src/document.ts @@ -168,11 +168,7 @@ export type Story = { dynamicId?: string; } & StoryProps; -export type DynamicExamples = { - name: string; - source?: string; - renderFn: () => JSX.Element; -}[]; +export type DynamicExamples = Story[]; /** * es named export function, excapsulates a contained example code. */ diff --git a/core/store/src/state/context/story.tsx b/core/store/src/state/context/story.tsx index 8d769e8c8..cecc41920 100644 --- a/core/store/src/state/context/story.tsx +++ b/core/store/src/state/context/story.tsx @@ -34,6 +34,9 @@ export const StoryContextProvider: FC<{ const [, setStory] = useState( storyId ? store.stories[storyId] : undefined, ); + //workaround gatsby ssr not updating classnames on active item + const [client, setClient] = useState('ssr'); + useEffect(() => { const onObserver = (updatedStory?: Story) => { if (updatedStory?.id === storyId) { @@ -41,6 +44,12 @@ export const StoryContextProvider: FC<{ } }; store.addObserver(onObserver); + const story: Story | undefined = storyId + ? store.stories[storyId] + : undefined; + if (story?.dynamicId) { + setClient('client'); + } return () => store.removeObserver(onObserver); }, [store, storyId]); useEffect(() => { @@ -57,6 +66,7 @@ export const StoryContextProvider: FC<{ }, [values, storyId, store]); return ( { diff --git a/core/store/src/state/recoil/StateRoot.tsx b/core/store/src/state/recoil/StateRoot.tsx index c609190b1..62ffda33a 100644 --- a/core/store/src/state/recoil/StateRoot.tsx +++ b/core/store/src/state/recoil/StateRoot.tsx @@ -4,7 +4,7 @@ import { Store } from '@component-controls/core'; import { storeState, activeTabState, optionsState } from './store'; import { documentIdState } from './document'; import { storyIdState } from './story'; -import { controlsValuesState } from './controls'; +import { currentControlsState } from './controls'; export interface StateRootProps { /** @@ -52,7 +52,7 @@ export const StateRoot: FC = ({ set(storyIdState, storyId); set(activeTabState, activeTab); set(optionsState, options || {}); - set(controlsValuesState, values); + set(currentControlsState, values); }} > {children} diff --git a/core/store/src/state/recoil/controls.tsx b/core/store/src/state/recoil/controls.tsx index 230bb0e12..0eb8dd325 100644 --- a/core/store/src/state/recoil/controls.tsx +++ b/core/store/src/state/recoil/controls.tsx @@ -15,7 +15,7 @@ import { import { currentStoryState } from './story'; import { storeState } from './store'; -const currentControlsState = selector({ +export const currentControlsState = selector({ key: 'current_controls', get: ({ get }) => { const story = get(currentStoryState); diff --git a/examples/stories/src/stories_native/dynamic-stories.stories.tsx b/examples/stories/src/stories_native/dynamic-stories.stories.tsx index a5e65d963..1685e4da3 100644 --- a/examples/stories/src/stories_native/dynamic-stories.stories.tsx +++ b/examples/stories/src/stories_native/dynamic-stories.stories.tsx @@ -8,7 +8,7 @@ export default { title: 'Introduction/Dynamic stories', author: 'atanasster', description: - "ESM story file to demostrate creating 'dynamic' stories at run-time. Creates a story iterating through each theme color", + "You can create 'dynamic' stories - below are created separate stories for each theme color.", }; export const buttonColors = (): Example => { @@ -17,14 +17,14 @@ export const buttonColors = (): Example => { .map(color => { return { name: color, - source: ``, + description: `theme.colors.${color}: **${theme.colors[color]}**`, + source: ``, renderFn: () => ( - + ), }; - }); + }) + .slice(0, 1); }; buttonColors.dynamic = true; diff --git a/ui/components/src/Navmenu/Navmenu.tsx b/ui/components/src/Navmenu/Navmenu.tsx index 287bac4b2..d8607bd04 100644 --- a/ui/components/src/Navmenu/Navmenu.tsx +++ b/ui/components/src/Navmenu/Navmenu.tsx @@ -224,13 +224,6 @@ export const Navmenu: FC = ({ }), ); }, [items, expandAll, activeItem, search]); - //workaround gatsby ssr not updating classnames on active item - const [isClient, setClient] = useState(false); - - useEffect(() => { - setClient(true); - }, []); - const onMenuChange = (item: MenuItem, expanded: boolean) => { const { expandedItems, filteredItems } = state; @@ -352,7 +345,7 @@ export const Navmenu: FC = ({ const { filteredItems } = state; return ( - + {filteredItems && filteredItems.map(item => renderItem(item, 1))} );