-
Notifications
You must be signed in to change notification settings - Fork 8
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
096ebf9
commit 5422dd4
Showing
6 changed files
with
66 additions
and
35 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
33 changes: 6 additions & 27 deletions
33
integrations/gatsby-theme-stories/src/components/Layout.tsx
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,40 +1,19 @@ | ||
/** @jsx jsx */ | ||
import { FC, useMemo } from 'react'; | ||
import { FC } from 'react'; | ||
import { jsx } from 'theme-ui'; | ||
import { ThemeProvider } from '@component-controls/components'; | ||
import { App } from '@component-controls/app'; | ||
import { | ||
SidebarContextProvider, | ||
LinkContextProvider, | ||
} from '@component-controls/app-components'; | ||
import { BlockContextProvider } from '@component-controls/blocks'; | ||
import { loadStoryStore, Store } from '@component-controls/store'; | ||
import { AppContext } from '@component-controls/app'; | ||
const bundle = require('@component-controls/webpack-compile/bundle'); | ||
|
||
import { GatsbyLink } from './GatsbyLink'; | ||
|
||
interface LayoutProps { | ||
docId?: string; | ||
} | ||
|
||
export const Layout: FC<LayoutProps> = ({ docId, children }) => { | ||
const storyStore = useMemo( | ||
() => | ||
new Store({ | ||
store: loadStoryStore(bundle), | ||
updateLocalStorage: false, | ||
}), | ||
[], | ||
); | ||
|
||
return ( | ||
<ThemeProvider> | ||
<BlockContextProvider docId={docId} store={storyStore}> | ||
<SidebarContextProvider> | ||
<LinkContextProvider linkClass={GatsbyLink}> | ||
<App title={docId}>{children}</App> | ||
</LinkContextProvider> | ||
</SidebarContextProvider> | ||
</BlockContextProvider> | ||
</ThemeProvider> | ||
<AppContext docId={docId} store={bundle} linkClass={GatsbyLink}> | ||
{children} | ||
</AppContext> | ||
); | ||
}; |
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,52 @@ | ||
/** @jsx jsx */ | ||
import { FC, useMemo } from 'react'; | ||
import { jsx } from 'theme-ui'; | ||
import { | ||
ThemeProvider, | ||
ThemeProviderProps, | ||
} from '@component-controls/components'; | ||
import { | ||
SidebarContextProvider, | ||
LinkContextProvider, | ||
LinkContextProviderProps, | ||
} from '@component-controls/app-components'; | ||
import { BlockContextProvider } from '@component-controls/blocks'; | ||
import { LoadingStore } from '@component-controls/loader'; | ||
import { loadStoryStore, Store } from '@component-controls/store'; | ||
import { App } from '../App'; | ||
|
||
export type AppContextProps = { | ||
docId?: string; | ||
store?: LoadingStore; | ||
linkClass: LinkContextProviderProps['linkClass']; | ||
} & ThemeProviderProps; | ||
|
||
export const AppContext: FC<AppContextProps> = ({ | ||
docId, | ||
children, | ||
store, | ||
linkClass, | ||
components, | ||
...themeProps | ||
}) => { | ||
const storyStore = useMemo( | ||
() => | ||
new Store({ | ||
store: loadStoryStore(store), | ||
updateLocalStorage: false, | ||
}), | ||
[store], | ||
); | ||
|
||
return ( | ||
<ThemeProvider components={components} {...themeProps}> | ||
<BlockContextProvider docId={docId} store={storyStore}> | ||
<SidebarContextProvider> | ||
<LinkContextProvider linkClass={linkClass}> | ||
<App title={docId}>{children}</App> | ||
</LinkContextProvider> | ||
</SidebarContextProvider> | ||
</BlockContextProvider> | ||
</ThemeProvider> | ||
); | ||
}; |
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 @@ | ||
export * from './AppContext'; |
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