22module Client.View
33
44
5+ open Fable.Import
6+ open Fable.Core
7+ open Fable.Core .JsInterop
58open Fable.Helpers .React
9+ open Fable.Helpers .Isomorphic
610open Fable.Helpers .React .Props
711open Client.Types
812open Shared
913
14+ type [<Pojo>] JsCompProps = {
15+ text: string
16+ }
17+
18+ #if FABLE_ COMPILER
19+ let JsComp : React.ComponentClass < JsCompProps > = importDefault " ./jsComp"
20+ #else
21+ let JsComp = Unchecked.defaultof< React.ComponentClass< JsCompProps>>
22+ #endif
23+
1024let show = function
1125| Some x -> string x
1226| None -> " Loading..."
@@ -32,6 +46,28 @@ let safeComponents =
3246 str " powered by: "
3347 components ]
3448
49+ let jsComp ( props : JsCompProps ) =
50+ ofImport " default" " ./jsComp" props []
51+
52+ let jsCompServer ( props : JsCompProps ) =
53+ div [] [ str " loading" ]
54+
55+ type [<Pojo>] MyProp = {
56+ text: string
57+ }
58+ type [<Pojo>] MyState = {
59+ text: string
60+ }
61+
62+ type MyReactComp ( initProps : MyProp ) as self =
63+ inherit React.Component< MyProp, MyState>( initProps) with
64+ do self.setInitState { text= " my state" }
65+
66+ override x.render () =
67+ div [] [ str ( sprintf " prop: %s state: %s " x.props.text x.state.text) ]
68+
69+
70+
3571let view ( model : Model ) ( dispatch ) =
3672 div []
3773 [ h1 [] [ str " SAFE Template" ]
@@ -65,28 +101,50 @@ let view (model: Model) (dispatch) =
65101 span [] [ str " Test checkbox:" ]
66102 input [ Type " checkbox" ; DefaultChecked true ]
67103 input [ Type " checkbox" ; DefaultChecked false ]
68- input [ Type " checkbox" ; Checked true ]
69- input [ Type " checkbox" ; Checked false ]
70- input [ Type " checkbox" ; Checked true ; DefaultChecked false ]
71- input [ Type " checkbox" ; DefaultChecked true ; Checked false ]
104+ input [ Type " checkbox" ; Checked true ; OnChange ignore ]
105+ input [ Type " checkbox" ; Checked false ; OnChange ignore ]
72106 ]
73107 div [] [
74108 span [] [ str " Test value:" ]
75109 input [ Type " text" ; DefaultValue " true" ]
76110 input [ Type " text" ; DefaultValue " false" ]
77- input [ Type " text" ; Value " true" ]
78- input [ Type " text" ; Value " false" ]
79- input [ Type " text" ; Value " true" ; DefaultValue " false" ]
80- input [ Type " text" ; DefaultValue " true" ; Value " false" ]
111+ input [ Type " text" ; Value " true" ; OnChange ignore ]
112+ input [ Type " text" ; Value " false" ; OnChange ignore ]
81113 ]
82114
83115 div [] [
84116 span [] [ str " Test textarea:" ]
85117 textarea [ DefaultValue " true" ] []
86118 textarea [ DefaultValue " false" ] []
87- textarea [ Value " true" ] []
88- textarea [ Value " false" ] []
89- textarea [ Value " true" ; DefaultValue " false" ] []
90- textarea [ DefaultValue " true" ; Value " false" ] []
119+ textarea [ Value " true" ; OnChange ignore] []
120+ textarea [ Value " false" ; OnChange ignore] []
91121 ]
122+
123+ div [] [
124+ span [] [ str " Test React.Fragment:" ]
125+ fragment []
126+ [ span [] [ str " child 1" ]
127+ span [] [ str " child 2" ]
128+ span [] [ str " child 3" ]
129+ span [] [ str " child 4" ]
130+ ]
131+ ]
132+
133+ div [] [
134+ span [] [ str " Test escape:" ]
135+ fragment []
136+ [ span
137+ [ Data ( " value" , " <div>\"\' &</div>" );
138+ Style [ Display " <div>\"\' &</div>" ]
139+ ]
140+ [ str " <div>\"\' &</div>" ]
141+ ]
142+ ]
143+
144+ div [] [
145+ span [] [ str " Test js component:" ]
146+ hybridView jsComp jsCompServer { text= " I'm rendered by a js Component!" }
147+ ]
148+
149+ ofType< MyReactComp, _, _> { text= " my prop" } []
92150 ]
0 commit comments