Skip to content

Commit

Permalink
Merge pull request #1140 from ameliagapin/email_url_elements
Browse files Browse the repository at this point in the history
add block elements for email_text_input and url_text_input
  • Loading branch information
kanata2 committed Dec 10, 2022
2 parents 501365f + 7a65b11 commit c857464
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions block_conv.go
Expand Up @@ -112,6 +112,10 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error {
e = &TimePickerBlockElement{}
case "plain_text_input":
e = &PlainTextInputBlockElement{}
case "email_text_input":
e = &EmailTextInputBlockElement{}
case "url_text_input":
e = &URLTextInputBlockElement{}
case "static_select", "external_select", "users_select", "conversations_select", "channels_select":
e = &SelectBlockElement{}
case "multi_static_select", "multi_external_select", "multi_users_select", "multi_conversations_select", "multi_channels_select":
Expand Down Expand Up @@ -188,6 +192,10 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error {
blockElement = &TimePickerBlockElement{}
case "plain_text_input":
blockElement = &PlainTextInputBlockElement{}
case "email_text_input":
blockElement = &EmailTextInputBlockElement{}
case "url_text_input":
blockElement = &URLTextInputBlockElement{}
case "checkboxes":
blockElement = &CheckboxGroupsBlockElement{}
case "radio_buttons":
Expand Down
60 changes: 60 additions & 0 deletions block_element.go
Expand Up @@ -11,6 +11,8 @@ const (
METTimepicker MessageElementType = "timepicker"
METPlainTextInput MessageElementType = "plain_text_input"
METRadioButtons MessageElementType = "radio_buttons"
METEmailTextInput MessageElementType = "email_text_input"
METURLTextInput MessageElementType = "url_text_input"
METNumber MessageElementType = "number_input"

MixedElementImage MixedElementType = "mixed_image"
Expand Down Expand Up @@ -390,6 +392,64 @@ func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement {
}
}

// EmailTextInputBlockElement creates a field where a user can enter email
// data.
// email-text-input elements are currently only available in modals.
//
// More Information: https://api.slack.com/reference/block-kit/block-elements#email
type EmailTextInputBlockElement struct {
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialValue string `json:"initial_value,omitempty"`
DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"`
FocusOnLoad bool `json:"focus_on_load,omitempty"`
}

// ElementType returns the type of the Element
func (s EmailTextInputBlockElement) ElementType() MessageElementType {
return s.Type
}

// NewEmailTextInputBlockElement returns an instance of a plain-text input
// element
func NewEmailTextInputBlockElement(placeholder *TextBlockObject, actionID string) *EmailTextInputBlockElement {
return &EmailTextInputBlockElement{
Type: METEmailTextInput,
ActionID: actionID,
Placeholder: placeholder,
}
}

// URLTextInputBlockElement creates a field where a user can enter url data.
//
// url-text-input elements are currently only available in modals.
//
// More Information: https://api.slack.com/reference/block-kit/block-elements#url
type URLTextInputBlockElement struct {
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialValue string `json:"initial_value,omitempty"`
DispatchActionConfig *DispatchActionConfig `json:"dispatch_action_config,omitempty"`
FocusOnLoad bool `json:"focus_on_load,omitempty"`
}

// ElementType returns the type of the Element
func (s URLTextInputBlockElement) ElementType() MessageElementType {
return s.Type
}

// NewURLTextInputBlockElement returns an instance of a plain-text input
// element
func NewURLTextInputBlockElement(placeholder *TextBlockObject, actionID string) *URLTextInputBlockElement {
return &URLTextInputBlockElement{
Type: METURLTextInput,
ActionID: actionID,
Placeholder: placeholder,
}
}

// PlainTextInputBlockElement creates a field where a user can enter freeform
// data.
// Plain-text input elements are currently only available in modals.
Expand Down
14 changes: 14 additions & 0 deletions block_element_test.go
Expand Up @@ -142,6 +142,20 @@ func TestNewPlainTextInputBlockElement(t *testing.T) {

}

func TestNewEmailTextInputBlockElement(t *testing.T) {
emailTextInputElement := NewEmailTextInputBlockElement(nil, "example@example.com")

assert.Equal(t, string(emailTextInputElement.Type), "email_text_input")
assert.Equal(t, emailTextInputElement.ActionID, "example@example.com")
}

func TestNewURLTextInputBlockElement(t *testing.T) {
urlTextInputElement := NewURLTextInputBlockElement(nil, "www.example.com")

assert.Equal(t, string(urlTextInputElement.Type), "url_text_input")
assert.Equal(t, urlTextInputElement.ActionID, "www.example.com")
}

func TestNewCheckboxGroupsBlockElement(t *testing.T) {
// Build Text Objects associated with each option
checkBoxOptionTextOne := NewTextBlockObject("plain_text", "Check One", false, false)
Expand Down

0 comments on commit c857464

Please sign in to comment.