-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ThemeProvider with BasisProvider
- Loading branch information
Showing
15 changed files
with
160 additions
and
45 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
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
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
24 changes: 20 additions & 4 deletions
24
src/providers/ThemeProvider.js → src/providers/BasisProvider.js
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,24 +1,40 @@ | ||
import React, { useMemo } from "react"; | ||
import PropTypes from "prop-types"; | ||
import BreakpointProvider from "./BreakpointProvider"; | ||
import LinkProvider from "./LinkProvider"; | ||
import { enhanceTheme } from "../utils/theme"; | ||
|
||
export const ThemeContext = React.createContext(); | ||
|
||
function ThemeProvider({ theme, window, children }) { | ||
function BasisProvider({ | ||
theme, | ||
window, | ||
InternalLink, | ||
isLinkInternal, | ||
children | ||
}) { | ||
const enhancedTheme = useMemo(() => enhanceTheme(theme), [theme]); | ||
|
||
return ( | ||
<ThemeContext.Provider value={enhancedTheme}> | ||
<BreakpointProvider window={window}>{children}</BreakpointProvider> | ||
<BreakpointProvider window={window}> | ||
<LinkProvider | ||
InternalLink={InternalLink} | ||
isLinkInternal={isLinkInternal} | ||
> | ||
{children} | ||
</LinkProvider> | ||
</BreakpointProvider> | ||
</ThemeContext.Provider> | ||
); | ||
} | ||
|
||
ThemeProvider.propTypes = { | ||
BasisProvider.propTypes = { | ||
theme: PropTypes.object.isRequired, | ||
window: PropTypes.object, | ||
InternalLink: PropTypes.elementType, | ||
isLinkInternal: PropTypes.func, | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
export default ThemeProvider; | ||
export default BasisProvider; |
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,29 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
export const LinkContext = React.createContext(); | ||
|
||
// See: https://www.gatsbyjs.org/docs/gatsby-link/#reminder-use-link-only-for-internal-links | ||
function defaultIsLinkInternal(href) { | ||
return /^\/(?!\/)/.test(href); | ||
} | ||
|
||
function LinkProvider({ | ||
InternalLink, | ||
isLinkInternal = defaultIsLinkInternal, | ||
children | ||
}) { | ||
return ( | ||
<LinkContext.Provider value={{ InternalLink, isLinkInternal }}> | ||
{children} | ||
</LinkContext.Provider> | ||
); | ||
} | ||
|
||
LinkProvider.propTypes = { | ||
InternalLink: PropTypes.elementType, | ||
isLinkInternal: PropTypes.func, | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
export default LinkProvider; |
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
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
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
Oops, something went wrong.