2020-03-23 11:15:33 +05:00
|
|
|
// BulpherJS - bulma for GopherJS.
|
|
|
|
// Copyright (c) 2020 by Stanislav Nikitin <pztrn@pztrn.name>
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
// a copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
// the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be
|
|
|
|
// included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2020-03-21 13:04:54 +05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gopherjs/gopherjs/js"
|
|
|
|
|
2020-05-17 19:37:58 +05:00
|
|
|
"go.dev.pztrn.name/bulpherjs"
|
2020-03-21 13:04:54 +05:00
|
|
|
"go.dev.pztrn.name/bulpherjs/common"
|
|
|
|
"go.dev.pztrn.name/bulpherjs/elements"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-05-17 19:37:58 +05:00
|
|
|
app := bulpherjs.NewApplication(&bulpherjs.ApplicationOptions{
|
|
|
|
Bulma: &bulpherjs.BulmaOptions{
|
|
|
|
Version: "0.8.0",
|
|
|
|
},
|
|
|
|
Name: "BulpherJS example application a.k.a. Hello World!",
|
2020-03-21 13:04:54 +05:00
|
|
|
})
|
2020-05-17 19:37:58 +05:00
|
|
|
|
|
|
|
app.SetStartFunction(start)
|
|
|
|
app.Start()
|
|
|
|
app.SetTitle("Hello world!")
|
2020-03-21 13:04:54 +05:00
|
|
|
}
|
|
|
|
|
2020-05-17 19:37:58 +05:00
|
|
|
func start(a *bulpherjs.Application) {
|
2022-01-07 10:53:39 +05:00
|
|
|
nb := elements.NewNavBar(&elements.NavBarOptions{
|
2020-05-17 21:57:45 +05:00
|
|
|
IsDark: true,
|
|
|
|
Title: "Example application",
|
|
|
|
})
|
|
|
|
a.HTML.Body.AddChild(nb)
|
|
|
|
|
2020-03-21 22:16:30 +05:00
|
|
|
mainSection := elements.NewSection(nil)
|
2020-03-21 13:04:54 +05:00
|
|
|
|
|
|
|
mainDiv := elements.NewDiv(&elements.DivOptions{
|
|
|
|
Class: "container",
|
|
|
|
ID: "mainContainer",
|
|
|
|
})
|
|
|
|
mainSection.AddChild(mainDiv)
|
|
|
|
|
|
|
|
// Columns divs.
|
|
|
|
columnsDiv := elements.NewDiv(&elements.DivOptions{
|
2020-03-23 11:10:49 +05:00
|
|
|
Class: "columns is-centered",
|
2020-03-21 13:04:54 +05:00
|
|
|
ID: "mainColumns",
|
|
|
|
})
|
|
|
|
mainDiv.AddChild(columnsDiv)
|
|
|
|
|
|
|
|
// Click-Me button should be in the middle of screen.
|
|
|
|
centerDiv := elements.NewDiv(&elements.DivOptions{
|
2020-03-23 11:10:49 +05:00
|
|
|
Class: "column is-half",
|
2020-03-21 13:04:54 +05:00
|
|
|
})
|
|
|
|
columnsDiv.AddChild(centerDiv)
|
|
|
|
|
|
|
|
startTestButton := elements.NewButton(&elements.ButtonOptions{
|
2020-03-21 22:16:30 +05:00
|
|
|
Class: "is-large is-rounded is-primary",
|
2020-03-21 22:03:53 +05:00
|
|
|
ID: "main_button",
|
2020-03-21 13:04:54 +05:00
|
|
|
Text: "Click Me!",
|
|
|
|
OnClickHandler: func(e *js.Object) {
|
|
|
|
common.Log("Button clicked! Hooray")
|
2020-03-21 22:03:53 +05:00
|
|
|
js.Global.Get(common.HTMLElementDocument).Call("getElementById", "main_button").Set("textContent", "Clicked!")
|
2020-03-21 13:04:54 +05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
centerDiv.AddChild(startTestButton)
|
|
|
|
|
2020-03-23 11:10:49 +05:00
|
|
|
constructTable(mainDiv)
|
|
|
|
|
|
|
|
// Build final document.
|
2020-05-17 19:37:58 +05:00
|
|
|
a.HTML.Body.AddChild(mainSection)
|
2020-03-21 13:04:54 +05:00
|
|
|
}
|
2020-03-23 11:10:49 +05:00
|
|
|
|
|
|
|
func constructTable(mainDiv *elements.Div) {
|
|
|
|
// Columns divs.
|
|
|
|
columnsDiv := elements.NewDiv(&elements.DivOptions{
|
|
|
|
Class: "columns is-centered",
|
|
|
|
ID: "tableColumns",
|
|
|
|
})
|
|
|
|
mainDiv.AddChild(columnsDiv)
|
|
|
|
|
|
|
|
tableDiv := elements.NewDiv(&elements.DivOptions{
|
|
|
|
Class: "column is-half",
|
|
|
|
})
|
|
|
|
columnsDiv.AddChild(tableDiv)
|
|
|
|
|
|
|
|
testTable := elements.NewTable(&elements.TableOptions{
|
|
|
|
IsBordered: true,
|
|
|
|
IsFullWidth: true,
|
|
|
|
IsHoverable: true,
|
|
|
|
IsNarrow: true,
|
2020-05-17 21:12:13 +05:00
|
|
|
|
|
|
|
Header: []string{"Header", "Line"},
|
2020-03-23 11:10:49 +05:00
|
|
|
})
|
|
|
|
tableDiv.AddChild(testTable)
|
|
|
|
|
|
|
|
tableHeader := elements.NewTHead()
|
|
|
|
testTable.AddChild(tableHeader)
|
|
|
|
|
|
|
|
tableHeaderLine := elements.NewTR()
|
|
|
|
tableHeader.AddChild(tableHeaderLine)
|
|
|
|
|
|
|
|
tableBody := elements.NewTBody()
|
|
|
|
testTable.AddChild(tableBody)
|
|
|
|
|
|
|
|
tableBodyLine := elements.NewTR()
|
|
|
|
tableBody.AddChild(tableBodyLine)
|
|
|
|
|
|
|
|
tblOne := elements.NewTD()
|
|
|
|
tblOne.SetTextContent("Body")
|
|
|
|
tableBodyLine.AddChild(tblOne)
|
|
|
|
|
|
|
|
tblTwo := elements.NewTD()
|
|
|
|
tblTwo.SetTextContent("line")
|
|
|
|
tableBodyLine.AddChild(tblTwo)
|
|
|
|
|
|
|
|
tableFooter := elements.NewTFoot()
|
|
|
|
testTable.AddChild(tableFooter)
|
|
|
|
|
|
|
|
tableFooterLine := elements.NewTR()
|
|
|
|
tableFooter.AddChild(tableFooterLine)
|
|
|
|
|
|
|
|
tflOne := elements.NewTD()
|
|
|
|
tflOne.SetTextContent("Footer")
|
|
|
|
tableFooterLine.AddChild(tflOne)
|
|
|
|
|
|
|
|
tflTwo := elements.NewTD()
|
|
|
|
tflTwo.SetTextContent("line")
|
|
|
|
tableFooterLine.AddChild(tflTwo)
|
|
|
|
}
|