From fc8ec18bd88b40627f639f5184adc6c921204540 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 30 Jul 2020 11:55:40 -0700 Subject: [PATCH] feat: add page layout context --- src/components/PageLayout/Context.js | 5 +++++ src/components/PageLayout/PageLayout.js | 4 +++- src/hooks/usePageLayout.js | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/components/PageLayout/Context.js create mode 100644 src/hooks/usePageLayout.js diff --git a/src/components/PageLayout/Context.js b/src/components/PageLayout/Context.js new file mode 100644 index 000000000..e3049cf1c --- /dev/null +++ b/src/components/PageLayout/Context.js @@ -0,0 +1,5 @@ +import { createContext } from 'react'; + +const PageLayoutContext = createContext(); + +export default PageLayoutContext; diff --git a/src/components/PageLayout/PageLayout.js b/src/components/PageLayout/PageLayout.js index 8eeecada0..6750aceac 100644 --- a/src/components/PageLayout/PageLayout.js +++ b/src/components/PageLayout/PageLayout.js @@ -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', @@ -57,7 +58,7 @@ const PageLayout = ({ children, type }) => { ${LAYOUTS[type]}; `} > - {children} + {children} ); }; @@ -70,6 +71,7 @@ PageLayout.propTypes = { PageLayout.TYPE = TYPES; PageLayout.Content = Content; +PageLayout.Context = Context; PageLayout.Header = Header; PageLayout.MarkdownContent = MarkdownContent; PageLayout.RelatedContent = RelatedContent; diff --git a/src/hooks/usePageLayout.js b/src/hooks/usePageLayout.js new file mode 100644 index 000000000..6143f068a --- /dev/null +++ b/src/hooks/usePageLayout.js @@ -0,0 +1,6 @@ +import { useContext } from 'react'; +import PageLayout from '../components/PageLayout'; + +const usePageLayout = () => useContext(PageLayout.Context); + +export default usePageLayout;