Skip to content

Commit

Permalink
feat: add page layout context
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jul 30, 2020
1 parent 9d049e6 commit fc8ec18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/PageLayout/Context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from 'react';

const PageLayoutContext = createContext();

export default PageLayoutContext;
4 changes: 3 additions & 1 deletion src/components/PageLayout/PageLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Content from './Content';
import Header from './Header';
import MarkdownContent from './MarkdownContent';
import RelatedContent from './RelatedContent';
import Context from './Context';

const TYPES = {
SINGLE_COLUMN: 'SINGLE_COLUMN',
Expand Down Expand Up @@ -57,7 +58,7 @@ const PageLayout = ({ children, type }) => {
${LAYOUTS[type]};
`}
>
{children}
<Context.Provider value={type}>{children}</Context.Provider>
</div>
);
};
Expand All @@ -70,6 +71,7 @@ PageLayout.propTypes = {
PageLayout.TYPE = TYPES;

PageLayout.Content = Content;
PageLayout.Context = Context;
PageLayout.Header = Header;
PageLayout.MarkdownContent = MarkdownContent;
PageLayout.RelatedContent = RelatedContent;
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/usePageLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useContext } from 'react';
import PageLayout from '../components/PageLayout';

const usePageLayout = () => useContext(PageLayout.Context);

export default usePageLayout;

0 comments on commit fc8ec18

Please sign in to comment.