-
Notifications
You must be signed in to change notification settings - Fork 4
[#135] Stop using parametric PropModifiers for styles and fix direction of style composition #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
63f72fc
Add StyleModifier
arthurxavierx f9ab17f
Rename styleModifier combinators
arthurxavierx 64d9040
Fix direction of composition of style modifiers
arthurxavierx a2f11a1
Add combinators for using an array of styles as a prop modifier
arthurxavierx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 +1,41 @@ | ||
module Lumi.Styles | ||
( styleModifier | ||
, styleModifier_ | ||
( StyleModifier | ||
, style | ||
, style_ | ||
, toCSS | ||
, module Emotion | ||
) where | ||
|
||
import Prelude | ||
import Lumi.Components (PropsModifier, LumiProps, propsModifier) | ||
|
||
import Data.Foldable (fold) | ||
import Lumi.Components (PropsModifier, propsModifier) | ||
import Lumi.Styles.Theme (LumiTheme) | ||
import React.Basic.Emotion hiding (element) as Emotion | ||
|
||
-- | Lift a themed set of styles into a `PropsModifier` for composition with other modifiers. | ||
-- | | ||
-- | Note: A style modifier should generally leave the `props` type unconstrained and take | ||
-- | configuration as regular arguments instead. Adding constraints to `props` makes it | ||
-- | difficult to compose style and prop modifiers together across different components, | ||
-- | where the same field name could mean different things. | ||
styleModifier :: forall props. (LumiTheme -> Emotion.Style) -> PropsModifier props | ||
styleModifier f = propsModifier \props -> props { css = f <> props.css } | ||
|
||
-- | Lift a static set of styles into a `PropsModifier` for composition with other modifiers. | ||
-- | | ||
-- | Note: A style modifier should generally leave the `props` type unconstrained and take | ||
-- | configuration as regular arguments instead. Adding constraints to `props` makes it | ||
-- | difficult to compose style and prop modifiers together across different components, | ||
-- | where the same field name could mean different things. | ||
styleModifier_ :: forall props. Emotion.Style -> PropsModifier props | ||
styleModifier_ = styleModifier <<< const | ||
import React.Basic.Emotion hiding (element,style) as Emotion | ||
|
||
type StyleModifier = forall props. PropsModifier props | ||
|
||
-- | Lift a themed set of styles into a `StyleModifier` for composition with other modifiers. | ||
style :: (LumiTheme -> Emotion.Style) -> StyleModifier | ||
style f = propsModifier \props -> props { css = props.css <> f } | ||
|
||
-- | Lift a static set of styles into a `StyleModifier` for composition with other modifiers. | ||
style_ :: Emotion.Style -> StyleModifier | ||
style_ = style <<< const | ||
|
||
-- | Lift an array of themed styles into a `StyleModifier` for composition with other modifiers. | ||
styles :: Array (LumiTheme -> Emotion.Style) -> StyleModifier | ||
styles = style <<< fold | ||
|
||
-- | Lift an array of static styles into a `StyleModifier` for composition with other modifiers. | ||
styles_ :: Array Emotion.Style -> StyleModifier | ||
styles_ = style_ <<< fold | ||
|
||
-- | Flatten a `PropsModifier` and extract the Emotion styles for use with `React.Basic.Emotion.element`. | ||
-- | This function is mainly used inside component implementations where the `LumiComponent` boundary | ||
-- | gives way to DOM components or other `ReactComponent`s. | ||
toCSS :: | ||
forall props. | ||
PropsModifier () -> | ||
LumiTheme -> | ||
LumiProps props -> | ||
PropsModifier props -> | ||
Emotion.Style | ||
toCSS theme props m = (m identity props).css theme | ||
toCSS m = (m identity { className: "", css: mempty }).css |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@spicydonuts Since we're forcing the monomorphization of
StyleModifier
here we don't get any escaped skolem errors anymore :)