Skip to content

Commit

Permalink
fix: preserve component name as string
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 7, 2020
1 parent 892416d commit c284170
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
13 changes: 11 additions & 2 deletions core/loader/src/replaceSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ ${stories
`;
const storeConst = `const store = ${hashKey};\n`;
let loadStories = `
const assignProps = (obj, props) => {
//preserve component and subcomponents as strings
const componentName = obj.component;
const subcomponentsName = obj.subcomponents;
Object.assign(obj, props);
obj.component = componentName;
obj.subcomponents = subcomponentsName;
}
for (let i = 0; i < store.stores.length; i+= 1) {
const s = store.stores[i];
const doc = s.doc;
Expand All @@ -29,13 +38,13 @@ ${stories
const exported = exports[key];
if (key === 'default') {
const { storySource, ...rest } = exported;
Object.assign(doc, rest);
assignProps(doc, rest);
} else {
const story = s.stories[key];
if (story) {
story.renderFn = exported;
if (exported.story) {
Object.assign(story, exported.story);
assignProps(story, exported.story);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions core/store/src/serialization/load-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ export const loadStoryStore = (
const storeStories = s.stories;
if (storeDoc && storeStories && s.stories) {
const doc = storeDoc;
const {
title,
stories,
source,
component,
fileName,
repository,
components,
excludeStories,
includeStories,
package: docPackage,
...otherDocProps
} = doc;
globalStore.docs[doc.title] = doc;
Object.keys(storeStories).forEach((storyName: string) => {
const story: Story = storeStories[storyName];
const {
title,
stories,
source,
component,
fileName,
repository,
components,
excludeStories,
includeStories,
package: docPackage,
...rest
} = doc;
Object.assign(story, deepMerge(rest, story));
Object.assign(story, deepMerge(otherDocProps, story));
const smartControls = addSmartControls(
story,
doc,
Expand Down
8 changes: 6 additions & 2 deletions examples/stories/src/stories/home-page.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ menu: false
---

import { jsx, Flex, Heading, Text, Button } from 'theme-ui';
import { SyntaxHighlighter } from '@component-controls/components';
import { DocsLink, StoryLink, DocLink } from '@component-controls/app';

<Flex sx={{ minHeight: '300px', width: '100%', alignItems: 'center', backgroundColor: 'primary', color: 'white' }}>
Expand All @@ -18,8 +19,11 @@ import { DocsLink, StoryLink, DocLink } from '@component-controls/app';
</Flex>
</Flex>

<StoryLink id='introduction-controls--random-number'>Go to Random Number story</StoryLink>

<SyntaxHighlighter dark={true} language="bash">
yarn add gatsby-theme-stories
</SyntaxHighlighter>
<br/>
<StoryLink sx={{ my: 2 }} id='introduction-controls--random-number'>Go to Random Number story</StoryLink>
<br/>

<DocLink id='Introduction/MDX'>Go to MDX doc page</DocLink>
6 changes: 4 additions & 2 deletions ui/blocks/src/context/components/ComponentsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import { useEffect, useState, useContext } from 'react';
import {
Story,
StoriesDoc,
Expand Down Expand Up @@ -36,10 +36,12 @@ export const useComponentsContext = ({
getComponents,
addObserver,
removeObserver,
} = React.useContext(BlockDataContext);
} = useContext(BlockDataContext);

const [{ story, doc, component, componentPackage }, setStoryData] = useState(
getStoryData(storyId, docId),
);

useEffect(() => {
setStoryData(getStoryData(storyId, docId));
const onChange = () => {
Expand Down
6 changes: 2 additions & 4 deletions ui/components/src/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsx jsx */
import { FunctionComponent } from 'react';
import { FC } from 'react';
import { transparentize } from 'polished';
import { Theme, Box, Flex, Button, jsx, useThemeUI } from 'theme-ui';
import { getSortedActions, ActionItems } from './utils';
Expand Down Expand Up @@ -44,9 +44,7 @@ const ActionColors = ({
* actions can accept an order prop, and can also be superimposed
*
*/
export const ActionBar: FunctionComponent<ActionBarProps> = ({
actions = [],
}) => {
export const ActionBar: FC<ActionBarProps> = ({ actions = [] }) => {
const { theme } = useThemeUI();
const sortedItems = getSortedActions(actions);
const items = sortedItems.map(
Expand Down

0 comments on commit c284170

Please sign in to comment.