From 47514f6857b31c96cbdf2621eca49a231bb988a9 Mon Sep 17 00:00:00 2001 From: Mudream Date: Mon, 21 Oct 2024 22:56:01 +0800 Subject: [PATCH] Update number component, message --- src/components/input/number_input.md | 32 +++++++++++++++++----------- src/components/misc/message.md | 11 ++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/components/input/number_input.md b/src/components/input/number_input.md index 54052b1..2dc863b 100644 --- a/src/components/input/number_input.md +++ b/src/components/input/number_input.md @@ -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 @@ -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 @@ -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 } @@ -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)) diff --git a/src/components/misc/message.md b/src/components/misc/message.md index 9e5a2e4..044926d 100644 --- a/src/components/misc/message.md +++ b/src/components/misc/message.md @@ -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) ``` @@ -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. @@ -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",