Skip to content

Commit

Permalink
Update number component, message
Browse files Browse the repository at this point in the history
  • Loading branch information
mudream4869 committed Oct 21, 2024
1 parent 69abbb4 commit 47514f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/components/input/number_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ NumberInput create a number input and return its value.
### Interface

```go
func Number(s *tgframe.State, c *tgframe.Container, label string) int
func NumberWithConf(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf) int
func NumberFloat64(s *tgframe.State, c *tgframe.Container, label string) *float64
func NumberWithConfFloat64(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf[float64]) *float64

func NumberInt64(s *tgframe.State, c *tgframe.Container, label string) *int64
func NumberWithConfInt64(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf[int64]) *int64
```

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

```go
// NumberConf is the configuration for a number component.
type NumberConf struct {
type NumberConf[T float64 | int64] struct {
// Default is the default value of the number component.
Default *float64
Default *T

// Min is the minimum value of the number component.
Min *float64
Min *T

// Max is the maximum value of the number component.
Max *float64
Max *T

// Step is the step of the number component.
Step *float64
Step *T

// Color is the color of the number component.
Color tcutil.Color
Expand All @@ -45,17 +48,22 @@ type NumberConf struct {
ID string
}

func (c *NumberConf) SetMin(min float64) *NumberConf {
func (c *NumberConf[T]) SetDefault(default T) *NumberConf[T] {
c.Default = &default
return c
}

func (c *NumberConf[T]) SetMin(min T) *NumberConf[T] {
c.Min = &min
return c
}

func (c *NumberConf) SetMax(max float64) *NumberConf {
func (c *NumberConf[T]) SetMax(max T) *NumberConf[T] {
c.Max = &max
return c
}

func (c *NumberConf) SetStep(step float64) *NumberConf {
func (c *NumberConf[T]) SetStep(step T) *NumberConf[T] {
c.Step = &step
return c
}
Expand All @@ -64,8 +72,8 @@ func (c *NumberConf) SetStep(step float64) *NumberConf {
## Example

```go
numberValue := tgcomp.NumberWithConf(numberCompCol, p.State, "Number",
(&tgcomp.NumberConf{
numberValue := tgcomp.NumberWithConfFloat64(numberCompCol, p.State, "Number",
(&tgcomp.NumberConf[float64]{
Placeholder: "input the value here",
Color: tcutil.ColorSuccess,
}).SetMin(10).SetMax(20).SetStep(2))
Expand Down
11 changes: 11 additions & 0 deletions src/components/misc/message.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Message is a component that displays a message.

```go
func Message(c *tgframe.Container, text string)
func MessageInfo(c *tgframe.Container, text string)
func MessageSuccess(c *tgframe.Container, text string)
func MessageWarning(c *tgframe.Container, text string)
func MessageDanger(c *tgframe.Container, text string)

func MessageWithConf(c *tgframe.Container, text string, conf *MessageConf)
```

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

* `Message[Info|Success|Warning|Danger]`: Create a message with a specific color.

```go
type MessageConf struct {
// Title is the title of the message. Optional.
Expand All @@ -36,6 +43,10 @@ type MessageConf struct {
tgcomp.Message(c, "Hello, World!")
```

```go
tgcomp.MessageInfo(c, "Hello, World!")
```

```go
tgcomp.MessageWithConf(c, "Hello, World!", &tgcomp.MessageConf{
Title: "Info",
Expand Down

0 comments on commit 47514f6

Please sign in to comment.