-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove flow fix me * copy docs * clean docs * add staticStyle to useFela for theme-aware styles * update docs
- Loading branch information
1 parent
2e19a19
commit f9468b6
Showing
8 changed files
with
105 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { combineRules } from 'fela' | ||
|
||
function getPropsWithTheme(props, theme) { | ||
if (props) { | ||
return { | ||
...props, | ||
theme, | ||
} | ||
} | ||
|
||
return { | ||
theme, | ||
} | ||
} | ||
|
||
export default function useFelaFactory( | ||
RendererContext, | ||
ThemeContext, | ||
useContext | ||
) { | ||
return function useFela(props) { | ||
const renderer = useContext(RendererContext) | ||
const theme = useContext(ThemeContext) || {} | ||
|
||
if (!renderer) { | ||
throw new Error( | ||
'The "useFela" hook can only be used inside a "RendererProvider"' | ||
) | ||
} | ||
|
||
// we add the theme to props so that it can be used within styles | ||
const propsWithTheme = getPropsWithTheme(props, theme) | ||
|
||
function css(...rules) { | ||
return renderer.renderRule(combineRules(...rules), propsWithTheme) | ||
} | ||
|
||
function staticStyle(style, selector) { | ||
return renderer.renderStatic(style, selector, propsWithTheme) | ||
} | ||
|
||
return { | ||
renderer, | ||
theme, | ||
css, | ||
staticStyle, | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,6 @@ | ||
// $FlowFixMe | ||
import { useContext } from 'preact/hooks' | ||
import { combineRules } from 'fela' | ||
import { useFelaFactory } from 'fela-bindings' | ||
|
||
import { RendererContext, ThemeContext } from './context' | ||
import { ThemeContext, RendererContext } from './context' | ||
|
||
export default function useFela(props = {}) { | ||
const renderer = useContext(RendererContext) | ||
const theme = useContext(ThemeContext) || {} | ||
|
||
if (!renderer) { | ||
throw new Error( | ||
'The "useFela" hook can only be used inside a "RendererProvider"' | ||
) | ||
} | ||
|
||
const propsWithTheme = { | ||
...props, | ||
theme, | ||
} | ||
|
||
function css(...rules) { | ||
return renderer.renderRule(combineRules(...rules), propsWithTheme) | ||
} | ||
|
||
return { | ||
renderer, | ||
theme, | ||
css, | ||
} | ||
} | ||
export default useFelaFactory(RendererContext, ThemeContext, useContext) |
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,41 +1,6 @@ | ||
import { useContext } from 'react' | ||
import { combineRules } from 'fela' | ||
import { useFelaFactory } from 'fela-bindings' | ||
|
||
import { RendererContext, ThemeContext } from './context' | ||
import { ThemeContext, RendererContext } from './context' | ||
|
||
function getPropsWithTheme(props, theme) { | ||
if (props) { | ||
return { | ||
...props, | ||
theme, | ||
} | ||
} | ||
|
||
return { | ||
theme, | ||
} | ||
} | ||
|
||
export default function useFela(props) { | ||
const renderer = useContext(RendererContext) | ||
const theme = useContext(ThemeContext) || {} | ||
|
||
if (!renderer) { | ||
throw new Error( | ||
'The "useFela" hook can only be used inside a "RendererProvider"' | ||
) | ||
} | ||
|
||
// we add the theme to props so that it can be used within styles | ||
const propsWithTheme = getPropsWithTheme(props, theme) | ||
|
||
function css(...rules) { | ||
return renderer.renderRule(combineRules(...rules), propsWithTheme) | ||
} | ||
|
||
return { | ||
renderer, | ||
theme, | ||
css, | ||
} | ||
} | ||
export default useFelaFactory(RendererContext, ThemeContext, useContext) |
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
f9468b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: