File tree 1 file changed +42
-2
lines changed
src/React/Basic/DOM/Simplified
1 file changed +42
-2
lines changed Original file line number Diff line number Diff line change 1
1
module React.Basic.DOM.Simplified.ToJSX
2
2
( class ToJSX
3
+ , el
3
4
, toJSX
4
- ) where
5
+ )
6
+ where
5
7
6
8
import Prelude
7
9
8
10
import Data.Array (singleton )
9
11
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 (..))
11
17
import Unsafe.Coerce (unsafeCoerce )
12
18
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
+
13
53
class ToJSX jsx where
14
54
toJSX :: jsx -> Array JSX
15
55
You can’t perform that action at this time.
0 commit comments