Skip to content

Commit

Permalink
feat: optional setting of note next label
Browse files Browse the repository at this point in the history
  • Loading branch information
abtmr committed May 8, 2024
1 parent 0a35040 commit cd08cba
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).
WithNextLabel("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 @@ -25,13 +25,15 @@ type Note struct {
accessible bool
theme *Theme
keymap NoteKeyMap
nextLabel string
}

// NewNote creates a new note field.
func NewNote() *Note {
return &Note{
showNextButton: false,
skip: true,
nextLabel: "Next",
}
}

Expand Down Expand Up @@ -131,7 +133,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 Expand Up @@ -205,6 +207,12 @@ func (n *Note) WithPosition(p FieldPosition) Field {
return n
}

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

// GetValue satisfies the Field interface, notes do not have values.
func (n *Note) GetValue() any {
return nil
Expand Down

0 comments on commit cd08cba

Please sign in to comment.