Added some type safety to Step
This commit is contained in:
parent
cbd897677b
commit
391d7a912b
@ -763,14 +763,6 @@ func Start(value string) hatmill.Attrib {
|
||||
}
|
||||
}
|
||||
|
||||
// Step creates a "step" attribute
|
||||
func Step(value string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "step",
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
// Style creates a "style" attribute
|
||||
func Style(value string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
|
25
attribute/step.go
Normal file
25
attribute/step.go
Normal file
@ -0,0 +1,25 @@
|
||||
package attribute
|
||||
|
||||
import "strconv"
|
||||
import "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
|
||||
type StepValue *float32
|
||||
|
||||
func StepAny() StepValue {
|
||||
return nil
|
||||
}
|
||||
|
||||
func StepFloat(value float32) StepValue {
|
||||
return &value
|
||||
}
|
||||
|
||||
// Step indicates the minimum allowed change to a number input.
|
||||
func Step(value StepValue) hatmill.Attrib {
|
||||
var attr = hatmill.Attrib{Key: "step"}
|
||||
if value == nil {
|
||||
attr.Value = "any"
|
||||
} else {
|
||||
attr.Value = strconv.FormatFloat(float64(*value), 'G', -1, 32)
|
||||
}
|
||||
return attr
|
||||
}
|
18
attribute/step_test.go
Normal file
18
attribute/step_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
package attribute_test
|
||||
|
||||
import (
|
||||
"gitlab.codemonkeysoftware.net/b/hatmill/attribute"
|
||||
"gitlab.codemonkeysoftware.net/b/hatmill/element"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ExampleStep() {
|
||||
s1 := attribute.Step(attribute.StepAny())
|
||||
s2 := attribute.Step(attribute.StepFloat(0.5))
|
||||
e := element.Div()(
|
||||
element.Input(s1),
|
||||
element.Input(s2),
|
||||
)
|
||||
e.WriteTo(os.Stdout)
|
||||
// Output: <div><input step='any'><input step='0.5'></div>
|
||||
}
|
@ -97,7 +97,6 @@
|
||||
{"name": "srclang", "type": "string"},
|
||||
{"name": "srcset", "type": "string"},
|
||||
{"name": "start", "type": "string"},
|
||||
{"name": "step", "type": "string"},
|
||||
{"name": "style", "type": "string"},
|
||||
{"name": "summary", "type": "string"},
|
||||
{"name": "tabindex", "type": "int"},
|
||||
|
Loading…
Reference in New Issue
Block a user