Skip to content

Commit 47514f6

Browse files
committed
Update number component, message
1 parent 69abbb4 commit 47514f6

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/components/input/number_input.md

+20-12
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ NumberInput create a number input and return its value.
77
### Interface
88

99
```go
10-
func Number(s *tgframe.State, c *tgframe.Container, label string) int
11-
func NumberWithConf(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf) int
10+
func NumberFloat64(s *tgframe.State, c *tgframe.Container, label string) *float64
11+
func NumberWithConfFloat64(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf[float64]) *float64
12+
13+
func NumberInt64(s *tgframe.State, c *tgframe.Container, label string) *int64
14+
func NumberWithConfInt64(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf[int64]) *int64
1215
```
1316

1417
### Parameters
@@ -19,18 +22,18 @@ func NumberWithConf(s *tgframe.State, c *tgframe.Container, label string, conf *
1922

2023
```go
2124
// NumberConf is the configuration for a number component.
22-
type NumberConf struct {
25+
type NumberConf[T float64 | int64] struct {
2326
// Default is the default value of the number component.
24-
Default *float64
27+
Default *T
2528

2629
// Min is the minimum value of the number component.
27-
Min *float64
30+
Min *T
2831

2932
// Max is the maximum value of the number component.
30-
Max *float64
33+
Max *T
3134

3235
// Step is the step of the number component.
33-
Step *float64
36+
Step *T
3437

3538
// Color is the color of the number component.
3639
Color tcutil.Color
@@ -45,17 +48,22 @@ type NumberConf struct {
4548
ID string
4649
}
4750

48-
func (c *NumberConf) SetMin(min float64) *NumberConf {
51+
func (c *NumberConf[T]) SetDefault(default T) *NumberConf[T] {
52+
c.Default = &default
53+
return c
54+
}
55+
56+
func (c *NumberConf[T]) SetMin(min T) *NumberConf[T] {
4957
c.Min = &min
5058
return c
5159
}
5260

53-
func (c *NumberConf) SetMax(max float64) *NumberConf {
61+
func (c *NumberConf[T]) SetMax(max T) *NumberConf[T] {
5462
c.Max = &max
5563
return c
5664
}
5765

58-
func (c *NumberConf) SetStep(step float64) *NumberConf {
66+
func (c *NumberConf[T]) SetStep(step T) *NumberConf[T] {
5967
c.Step = &step
6068
return c
6169
}
@@ -64,8 +72,8 @@ func (c *NumberConf) SetStep(step float64) *NumberConf {
6472
## Example
6573

6674
```go
67-
numberValue := tgcomp.NumberWithConf(numberCompCol, p.State, "Number",
68-
(&tgcomp.NumberConf{
75+
numberValue := tgcomp.NumberWithConfFloat64(numberCompCol, p.State, "Number",
76+
(&tgcomp.NumberConf[float64]{
6977
Placeholder: "input the value here",
7078
Color: tcutil.ColorSuccess,
7179
}).SetMin(10).SetMax(20).SetStep(2))

src/components/misc/message.md

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Message is a component that displays a message.
88

99
```go
1010
func Message(c *tgframe.Container, text string)
11+
func MessageInfo(c *tgframe.Container, text string)
12+
func MessageSuccess(c *tgframe.Container, text string)
13+
func MessageWarning(c *tgframe.Container, text string)
14+
func MessageDanger(c *tgframe.Container, text string)
15+
1116
func MessageWithConf(c *tgframe.Container, text string, conf *MessageConf)
1217
```
1318

@@ -17,6 +22,8 @@ func MessageWithConf(c *tgframe.Container, text string, conf *MessageConf)
1722
* `text`: Text to display.
1823
* `conf`: Configuration for the message component.
1924

25+
* `Message[Info|Success|Warning|Danger]`: Create a message with a specific color.
26+
2027
```go
2128
type MessageConf struct {
2229
// Title is the title of the message. Optional.
@@ -36,6 +43,10 @@ type MessageConf struct {
3643
tgcomp.Message(c, "Hello, World!")
3744
```
3845

46+
```go
47+
tgcomp.MessageInfo(c, "Hello, World!")
48+
```
49+
3950
```go
4051
tgcomp.MessageWithConf(c, "Hello, World!", &tgcomp.MessageConf{
4152
Title: "Info",

0 commit comments

Comments
 (0)