github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/examples/sites/examplesshowcase/app.go (about) 1 package main 2 3 import ( 4 "myitcv.io/react" 5 "myitcv.io/react/examples" 6 ) 7 8 type tab uint32 9 10 const ( 11 tabShowcase tab = iota 12 tabImmutable 13 tabGlobalState 14 ) 15 16 type AppDef struct { 17 react.ComponentDef 18 } 19 20 type AppState struct { 21 tab 22 } 23 24 func App() *AppElem { 25 return buildAppElem() 26 } 27 28 func (a AppDef) Render() react.Element { 29 var view react.Element 30 31 switch a.State().tab { 32 case tabShowcase: 33 view = examples.Examples() 34 case tabImmutable: 35 view = examples.ImmExamples() 36 case tabGlobalState: 37 view = examples.GlobalStateExamples() 38 } 39 40 return react.Fragment( 41 react.Nav(&react.NavProps{ClassName: "navbar navbar-inverse navbar-fixed-top"}, 42 react.Div(&react.DivProps{ClassName: "container"}, 43 react.Div(&react.DivProps{ClassName: "navbar-header"}, 44 react.A(&react.AProps{ClassName: "navbar-brand", Href: "#"}, 45 react.S("GopherJS React Examples"), 46 ), 47 ), 48 react.Div(&react.DivProps{ClassName: "collapse navbar-collapse", ID: "navbar"}, 49 react.Ul(&react.UlProps{ClassName: "nav navbar-nav"}, 50 a.buildLink("Simple", tabShowcase, tabChange{a, tabShowcase}), 51 a.buildLink("Immutable", tabImmutable, tabChange{a, tabImmutable}), 52 a.buildLink("Global State", tabGlobalState, tabChange{a, tabGlobalState}), 53 ), 54 ), 55 ), 56 ), 57 react.Div(&react.DivProps{ClassName: "container"}, 58 react.Div(&react.DivProps{ClassName: "starter-template"}, 59 view, 60 ), 61 ), 62 ) 63 } 64 65 type tabChange struct { 66 a AppDef 67 t tab 68 } 69 70 func (tc tabChange) OnClick(e *react.SyntheticMouseEvent) { 71 tc.a.SetState(AppState{tc.t}) 72 e.PreventDefault() 73 } 74 75 func (a AppDef) buildLink(n string, t tab, tc tabChange) *react.LiElem { 76 var lip *react.LiProps 77 78 if a.State().tab == t { 79 lip = &react.LiProps{ClassName: "active"} 80 } 81 82 return react.Li(lip, 83 react.A(&react.AProps{Href: "#", OnClick: tc}, react.S(n)), 84 ) 85 }