Skip to content

Commit a598a32

Browse files
authored
Add el helper (#47)
* Add el helper * Fix comment
1 parent 249ce47 commit a598a32

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

Diff for: src/React/Basic/DOM/Simplified/ToJSX.purs

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
module React.Basic.DOM.Simplified.ToJSX
22
( class ToJSX
3+
, el
34
, toJSX
4-
) where
5+
)
6+
where
57

68
import Prelude
79

810
import Data.Array (singleton)
911
import Data.Maybe (Maybe(..))
10-
import React.Basic (JSX)
12+
import Prim.Row (class Lacks)
13+
import React.Basic (JSX, ReactComponent)
14+
import React.Basic as React
15+
import Record as Record
16+
import Type.Proxy (Proxy(..))
1117
import Unsafe.Coerce (unsafeCoerce)
1218

19+
-- | Helper function to easily use any `ReactComponent` and compose it with the simplified html tags.
20+
-- | E.g. using NextUI:
21+
-- | ```purescript
22+
-- | -- Import the simplified elements
23+
-- | import React.Basic.DOM.Simplified.Generated as R
24+
-- |
25+
-- | ...
26+
-- |
27+
-- | -- Import your react components
28+
-- | foreign import container :: forall props. ReactComponent { | props }
29+
-- | foreign import row :: forall props. ReactComponent { | props }
30+
-- | foreign import col :: forall props. ReactComponent { | props }
31+
-- |
32+
-- | ...
33+
-- |
34+
-- | -- Build your jsx
35+
-- | el container {} $
36+
-- | el row {} $
37+
-- | el col {} $
38+
-- | R.div {} "Some text"
39+
-- | ```
40+
el
41+
props jsx
42+
. Lacks "children" props
43+
=> ToJSX jsx
44+
ReactComponent { children Array JSX | props }
45+
Record props
46+
jsx
47+
JSX
48+
el cmp props children =
49+
(React.element)
50+
cmp
51+
(Record.insert (Proxy Proxy "children") (toJSX children) props)
52+
1353
class ToJSX jsx where
1454
toJSX :: jsx -> Array JSX
1555

0 commit comments

Comments
 (0)