File tree Expand file tree Collapse file tree 1 file changed +42
-2
lines changed
src/React/Basic/DOM/Simplified Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Original file line number Diff line number Diff line change 11module React.Basic.DOM.Simplified.ToJSX
22 ( class ToJSX
3+ , el
34 , toJSX
4- ) where
5+ )
6+ where
57
68import Prelude
79
810import Data.Array (singleton )
911import 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 (..))
1117import 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+
1353class ToJSX jsx where
1454 toJSX :: jsx -> Array JSX
1555
You can’t perform that action at this time.
0 commit comments