-
Notifications
You must be signed in to change notification settings - Fork 11
/
slider.go
59 lines (49 loc) · 1.39 KB
/
slider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package slider
import (
"strconv"
"qlova.org/seed"
"qlova.org/seed/client"
"qlova.org/seed/client/clientside"
"qlova.org/seed/use/html"
"qlova.org/seed/use/html/attr"
"qlova.org/seed/use/js"
"qlova.org/seed/new/html/input"
)
//New returns a new textbox widget.
func New(options ...seed.Option) seed.Seed {
return input.New(attr.Set("type", "range"), seed.Options(options))
}
//Update updates the given variable whenever the textbox text is modified.
func Update(variable *clientside.Int) seed.Option {
return seed.NewOption(func(c seed.Seed) {
clientside.Hook(variable, c)
c.With(
client.On("render", html.Element(c).Set("value", variable)),
client.On("input", variable.SetTo(js.Number{Value: js.NewValue("+%v", html.Element(c).Get("value"))})),
)
})
}
//SetMin sets the minumum value of this slider.
func SetMin(min int) seed.Option {
return attr.Set("min", strconv.Itoa(min))
}
//SetMax sets the maximum value of this slider.
func SetMax(max int) seed.Option {
return attr.Set("max", strconv.Itoa(max))
}
//SetRange sets the range of the slider.
func SetRange(min, max int) seed.Option {
return seed.Options{
SetMin(min), SetMax(max),
}
}
//SetReadOnly sets the textbox to be readonly.
func SetReadOnly() seed.Option {
return attr.Set("readonly", "")
}
//Focus focuses the textbox.
func Focus(c seed.Seed) js.Script {
return func(q js.Ctx) {
q(html.Element(c).Run(`focus`))
}
}