Skip to content

Commit

Permalink
Introduce italic description for Button Builder API (#1450)
Browse files Browse the repository at this point in the history
Add new style API for ButtonBuilder
  • Loading branch information
pkosiec authored May 27, 2024
1 parent 9d1c897 commit a3f727e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/api/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ type ButtonDescriptionStyle string
const (
// ButtonDescriptionStyleBold defines the bold style for the button description.
ButtonDescriptionStyleBold ButtonDescriptionStyle = "bold"

// ButtonDescriptionStyleItalic defines the bold style for the button description.
ButtonDescriptionStyleItalic ButtonDescriptionStyle = "italic"
// ButtonDescriptionStyleText defines the plaintext style for the button description.
ButtonDescriptionStyleText ButtonDescriptionStyle = "text"
// ButtonDescriptionStyleCode defines the code style for the button description.
Expand Down Expand Up @@ -351,6 +354,15 @@ func (b *ButtonBuilder) ForCommandWithDescCmd(name, cmd string, style ...ButtonS
return b.commandWithCmdDesc(name, cmd, cmd, bt)
}

// ForCommandWithItalicDesc returns button command where description and command are different and the description is italic.
func (b *ButtonBuilder) ForCommandWithItalicDesc(name, desc, cmd string, style ...ButtonStyle) Button {
bt := ButtonStyleDefault
if len(style) > 0 {
bt = style[0]
}
return b.commandWithDesc(name, cmd, desc, bt, ButtonDescriptionStyleItalic)
}

// ForCommandWithBoldDesc returns button command where description and command are different.
func (b *ButtonBuilder) ForCommandWithBoldDesc(name, desc, cmd string, style ...ButtonStyle) Button {
bt := ButtonStyleDefault
Expand Down
2 changes: 2 additions & 0 deletions pkg/bot/slack_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func (b *SlackRenderer) renderButtonsWithDescription(in api.Buttons) []slack.Blo
switch btn.DescriptionStyle {
case api.ButtonDescriptionStyleBold:
desc = fmt.Sprintf("*%s*", desc)
case api.ButtonDescriptionStyleItalic:
desc = fmt.Sprintf("_%s_", desc)
case api.ButtonDescriptionStyleText:
// no op, it should be just a simple string
case api.ButtonDescriptionStyleCode:
Expand Down

0 comments on commit a3f727e

Please sign in to comment.