Skip to content

Commit

Permalink
feat(hooks): add hypostyle and theme hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Apr 26, 2021
1 parent 884a2ee commit 12bf03f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.js
Expand Up @@ -2,6 +2,15 @@ const React = require('react')

const context = React.createContext({})

function useHypostyle () {
return React.useContext(context)
}

function useTheme () {
const { theme } = useHypostyle()
return theme
}

function Hypo ({ hypostyle, children }) {
return React.createElement(context.Provider, {
value: hypostyle,
Expand All @@ -11,7 +20,7 @@ function Hypo ({ hypostyle, children }) {

const Box = React.forwardRef(
({ as = 'div', className = '', cx, ...props }, ref) => {
const hypostyle = React.useContext(context)
const hypostyle = useHypostyle()
const cleaned = hypostyle.pick(props)

return React.createElement(as, {
Expand All @@ -33,7 +42,7 @@ const Box = React.forwardRef(

function compose (as, styles) {
return React.forwardRef((props, ref) => {
const hypostyle = React.useContext(context)
const hypostyle = useHypostyle()
const cleaned = hypostyle.pick(props)

const p = {
Expand All @@ -54,6 +63,8 @@ function compose (as, styles) {
}

module.exports = {
useHypostyle,
useTheme,
Hypo,
Box,
compose
Expand Down

0 comments on commit 12bf03f

Please sign in to comment.