Skip to content

Commit a24da38

Browse files
Add withContent alias and use it in Box examples (#139)
1 parent c563dd5 commit a24da38

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

docs/Examples2/Box.example.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Lumi.Components2.Examples.Box where
22

33
import Prelude
44
import Color.Scheme.MaterialDesign (blue, green, red)
5-
import Lumi.Components (lumiElement)
5+
import Lumi.Components (lumiElement, ($$$))
66
import Lumi.Components.Example (example)
77
import Lumi.Components.Spacing (Space(..), vspace)
88
import Lumi.Components.Text (h2_, p_)
@@ -40,22 +40,22 @@ docs =
4040
, vspace S24
4141
, h2_ "Defaults"
4242
, example $ lumiElement box
43-
$ _ { content = exampleContent }
43+
$$$ exampleContent
4444
, h2_ "Row"
4545
, example $ lumiElement box
4646
$ _row
47-
$ _ { content = exampleContent }
47+
$$$ exampleContent
4848
, h2_ "Align/justify"
4949
, example $ lumiElement box
5050
$ _row
5151
$ _alignSelf Stretch -- only necessary because `example` isn't a Box
5252
$ _justify End
53-
$ _ { content = exampleContent }
53+
$$$ exampleContent
5454
, h2_ "Space evenly"
5555
, example $ lumiElement box
5656
$ _row
5757
$ _alignSelf Stretch -- only necessary because `example` isn't a Box
5858
$ _justify SpaceEvenly
59-
$ _ { content = exampleContent }
59+
$$$ exampleContent
6060
]
6161
}

src/Lumi/Components.purs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Lumi.Components
66
, lumiComponent
77
, lumiComponentFromHook
88
, lumiElement
9+
, withContent, ($$$)
910
) where
1011

1112
import Prelude
@@ -76,6 +77,19 @@ lumiComponentFromHook name defaults propsToHook = do
7677
, className: lumiComponentClassName name
7778
}
7879

80+
-- | A convenient alias for setting the `content` property of a Lumi component
81+
-- | if it exists.
82+
infixr 0 withContent as $$$
83+
84+
withContent ::
85+
forall props content r.
86+
((LumiProps (content :: content | props) -> LumiProps (content :: content | props)) -> r) ->
87+
content ->
88+
r
89+
withContent m content = m _{ content = content }
90+
91+
-- # Internal
92+
7993
lumiComponentClassName :: String -> String
8094
lumiComponentClassName name = "lumi-component lumi-" <> toLower name
8195

0 commit comments

Comments
 (0)