Skip to content

Commit

Permalink
feat: optional setting of note next label (#225)
Browse files Browse the repository at this point in the history
* feat: optional setting of note next label

* review comments

* move nextLabel up with the other customization fields
  • Loading branch information
abtmr committed May 24, 2024
1 parent b9d3be4 commit fd062fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion examples/burger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func main() {
form := huh.NewForm(
huh.NewGroup(huh.NewNote().
Title("Charmburger").
Description("Welcome to _Charmburger™_.\n\nHow may we take your order?")),
Description("Welcome to _Charmburger™_.\n\nHow may we take your order?\n\n").
Next(true).
NextLabel("Let's go!"),
),

// Choose a burger.
// We'll need to know what topping to add too.
Expand Down
10 changes: 9 additions & 1 deletion field_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Note struct {
// customization
title string
description string
nextLabel string

// state
showNextButton bool
Expand All @@ -32,6 +33,7 @@ func NewNote() *Note {
return &Note{
showNextButton: false,
skip: true,
nextLabel: "Next",
}
}

Expand All @@ -53,6 +55,12 @@ func (n *Note) Next(show bool) *Note {
return n
}

// NextLabel sets the next button label.
func (n *Note) NextLabel(label string) *Note {
n.nextLabel = label
return n
}

// Focus focuses the note field.
func (n *Note) Focus() tea.Cmd {
n.focused = true
Expand Down Expand Up @@ -131,7 +139,7 @@ func (n *Note) View() string {
sb.WriteString(render(n.description))
}
if n.showNextButton {
sb.WriteString(styles.Next.Render("Next"))
sb.WriteString(styles.Next.Render(n.nextLabel))
}
return styles.Card.Render(sb.String())
}
Expand Down

0 comments on commit fd062fd

Please sign in to comment.