-
Notifications
You must be signed in to change notification settings - Fork 0
feat(block-kit): add block element examples #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
099fd69
feat(block-kit): add block element examples
zimeg ab09747
Add rich text, feedback, and URL source block element examples
zimeg 6ce0f64
refactor(block-kit): rename block_elements module to elements
zimeg 0fec1d8
refactor(block-kit): renumber button section+actions example to examp…
zimeg 6758c88
fix(block-kit): mirror the docs checkboxes payload 1:1 (full modal view)
zimeg 185fc3d
fix(block-kit): wrap file_input and rich_text_input examples in their…
zimeg 0b72464
docs(block-kit): align example descriptions with the reviewed JS wording
zimeg 60c0b81
docs(block-kit): shorten checkboxes example description
zimeg 244ea93
style(block-kit): omit emoji arg where the docs example omits emoji
zimeg 869a603
refactor(block-kit): use typed TextStyle instead of raw style dict
zimeg ec3f5d3
docs(block-kit): align url_source first docstring line with the JS wo…
zimeg fcb4f06
docs(block-kit): match time_picker first docstring line to the JS wor…
zimeg 1a78611
docs(block-kit): match time_picker README line to JS (buggy docs summ…
zimeg f100c04
docs(block-kit): align workflow button description with docs wording
zimeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from slack_sdk.models.blocks import RichTextBlock | ||
| from slack_sdk.models.blocks.block_elements import ( | ||
| RichTextElementParts, | ||
| RichTextSectionElement, | ||
| ) | ||
|
|
||
|
|
||
| def example01() -> RichTextBlock: | ||
| """ | ||
| Displays a broadcast mention such as here, channel, or everyone. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/broadcast-element/ | ||
|
|
||
| A rich text block with a broadcast mention in a section. | ||
| """ | ||
| block = RichTextBlock( | ||
| elements=[ | ||
| RichTextSectionElement( | ||
| elements=[ | ||
| RichTextElementParts.Broadcast(range="everyone"), | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from slack_sdk.models.blocks import ActionsBlock, Block, SectionBlock | ||
| from slack_sdk.models.blocks.basic_components import MarkdownTextObject, PlainTextObject | ||
| from slack_sdk.models.blocks.block_elements import ButtonElement | ||
|
|
||
|
|
||
| def example01() -> ButtonElement: | ||
| """ | ||
| Allows users a direct path to performing basic actions. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/button-element/ | ||
|
|
||
| A regular interactive button. | ||
| """ | ||
| element = ButtonElement( | ||
| text=PlainTextObject(text="Click Me"), | ||
| value="click_me_123", | ||
| action_id="button", | ||
| ) | ||
| return element | ||
|
|
||
|
|
||
| def example02() -> ButtonElement: | ||
| """ | ||
| A button with a primary style attribute. | ||
| """ | ||
| element = ButtonElement( | ||
| text=PlainTextObject(text="Save"), | ||
| style="primary", | ||
| value="click_me_123", | ||
| action_id="button", | ||
| ) | ||
| return element | ||
|
|
||
|
|
||
| def example03() -> ButtonElement: | ||
| """ | ||
| A link button. | ||
| """ | ||
| element = ButtonElement( | ||
| text=PlainTextObject(text="Link Button"), | ||
| url="https://docs.slack.dev/block-kit", | ||
| ) | ||
| return element | ||
|
|
||
|
|
||
| def example05() -> list[Block]: | ||
| """ | ||
| The button element used inside either the section or actions block. | ||
| """ | ||
| blocks: list[Block] = [ | ||
| SectionBlock( | ||
| text=MarkdownTextObject(text="This is a section block with a button."), | ||
| accessory=ButtonElement( | ||
| text=PlainTextObject(text="Click Me"), | ||
| value="click_me_123", | ||
| action_id="button", | ||
| ), | ||
| ), | ||
| ActionsBlock( | ||
| block_id="actionblock789", | ||
| elements=[ | ||
| ButtonElement( | ||
| text=PlainTextObject(text="Primary Button"), | ||
| style="primary", | ||
| value="click_me_456", | ||
| ), | ||
| ButtonElement( | ||
| text=PlainTextObject(text="Link Button"), | ||
| url="https://api.slack.com/block-kit", | ||
| ), | ||
| ], | ||
| ), | ||
| ] | ||
| return blocks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from slack_sdk.models.blocks import RichTextBlock | ||
| from slack_sdk.models.blocks.block_elements import ( | ||
| RichTextElementParts, | ||
| RichTextSectionElement, | ||
| ) | ||
|
|
||
|
|
||
| def example01() -> RichTextBlock: | ||
| """ | ||
| Renders as a mention of a channel. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/channel-element/ | ||
|
|
||
| A rich text block with a channel mention in a section. | ||
| """ | ||
| block = RichTextBlock( | ||
| elements=[ | ||
| RichTextSectionElement( | ||
| elements=[ | ||
| RichTextElementParts.Channel(channel_id="C123ABC456"), | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from slack_sdk.models.blocks import SectionBlock | ||
| from slack_sdk.models.blocks.basic_components import ( | ||
| MarkdownTextObject, | ||
| Option, | ||
| PlainTextObject, | ||
| ) | ||
| from slack_sdk.models.blocks.block_elements import CheckboxesElement | ||
| from slack_sdk.models.views import View | ||
|
|
||
|
|
||
| def example01() -> View: | ||
| """ | ||
| Allows users to choose multiple items from a list of options. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/checkboxes-element/ | ||
|
|
||
| A section block containing a group of checkboxes. | ||
| """ | ||
| view = View( | ||
| type="modal", | ||
| title=PlainTextObject(text="My App", emoji=True), | ||
| submit=PlainTextObject(text="Submit", emoji=True), | ||
| close=PlainTextObject(text="Cancel", emoji=True), | ||
| blocks=[ | ||
| SectionBlock( | ||
| text=PlainTextObject(text="Check out these charming checkboxes"), | ||
| accessory=CheckboxesElement( | ||
| action_id="this_is_an_action_id", | ||
| initial_options=[ | ||
| Option(value="A1", text=PlainTextObject(text="Checkbox 1")), | ||
| ], | ||
| options=[ | ||
| Option(value="A1", text=PlainTextObject(text="Checkbox 1")), | ||
| Option( | ||
| value="A2", | ||
| text=PlainTextObject(text="Checkbox 2"), | ||
| description=MarkdownTextObject( | ||
| text="*A description of option two*" | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
| return view |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from slack_sdk.models.blocks import RichTextBlock | ||
| from slack_sdk.models.blocks.block_elements import ( | ||
| RichTextElementParts, | ||
| RichTextSectionElement, | ||
| ) | ||
|
|
||
|
|
||
| def example01() -> RichTextBlock: | ||
| """ | ||
| Displays a color swatch from a hex value. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/color-element/ | ||
|
|
||
| A rich text block with a color element in a section. | ||
| """ | ||
| block = RichTextBlock( | ||
| elements=[ | ||
| RichTextSectionElement( | ||
| elements=[ | ||
| RichTextElementParts.Color(value="#F405B3"), | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from slack_sdk.models.blocks import RichTextBlock | ||
| from slack_sdk.models.blocks.block_elements import ( | ||
| RichTextElementParts, | ||
| RichTextSectionElement, | ||
| ) | ||
|
|
||
|
|
||
| def example01() -> RichTextBlock: | ||
| """ | ||
| Displays a formatted, localized date. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/date-element/ | ||
|
|
||
| A rich text block with a date element in a section. | ||
| """ | ||
| block = RichTextBlock( | ||
| elements=[ | ||
| RichTextSectionElement( | ||
| elements=[ | ||
| RichTextElementParts.Date( | ||
| timestamp=1720710212, | ||
| format="{date_num} at {time}", | ||
| fallback="timey", | ||
| ), | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from slack_sdk.models.blocks import SectionBlock | ||
| from slack_sdk.models.blocks.basic_components import MarkdownTextObject, PlainTextObject | ||
| from slack_sdk.models.blocks.block_elements import DatePickerElement | ||
|
|
||
|
|
||
| def example01() -> SectionBlock: | ||
| """ | ||
| Allows users to select a date from a calendar style UI. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/date-picker-element/ | ||
|
|
||
| A section block with a date picker accessory. | ||
| """ | ||
| block = SectionBlock( | ||
| block_id="section1234", | ||
| text=MarkdownTextObject(text="Pick a date for the deadline."), | ||
| accessory=DatePickerElement( | ||
| action_id="datepicker123", | ||
| initial_date="1990-04-28", | ||
| placeholder=PlainTextObject(text="Select a date"), | ||
| ), | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from slack_sdk.models.blocks import InputBlock | ||
| from slack_sdk.models.blocks.basic_components import PlainTextObject | ||
| from slack_sdk.models.blocks.block_elements import DateTimePickerElement | ||
|
|
||
|
|
||
| def example01() -> InputBlock: | ||
| """ | ||
| Allows users to select both a date and a time of day. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/datetime-picker-element/ | ||
|
|
||
| An input block with a datetime picker element. | ||
| """ | ||
| block = InputBlock( | ||
| element=DateTimePickerElement(action_id="datetimepicker-action"), | ||
| hint=PlainTextObject(text="This is some hint text", emoji=True), | ||
| label=PlainTextObject(text="Start date", emoji=True), | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from slack_sdk.models.blocks import InputBlock | ||
| from slack_sdk.models.blocks.basic_components import PlainTextObject | ||
| from slack_sdk.models.blocks.block_elements import EmailInputElement | ||
|
|
||
|
|
||
| def example01() -> InputBlock: | ||
| """ | ||
| Allows user to enter an email into a single-line field. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/email-input-element/ | ||
|
|
||
| An input block with an email input element. | ||
| """ | ||
| block = InputBlock( | ||
| block_id="input123", | ||
| label=PlainTextObject(text="Email Address"), | ||
| element=EmailInputElement( | ||
| action_id="email_text_input-action", | ||
| placeholder=PlainTextObject(text="Enter an email"), | ||
| ), | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from slack_sdk.models.blocks import RichTextBlock | ||
| from slack_sdk.models.blocks.block_elements import ( | ||
| RichTextElementParts, | ||
| RichTextSectionElement, | ||
| ) | ||
|
|
||
|
|
||
| def example01() -> RichTextBlock: | ||
| """ | ||
| Displays an emoji. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/emoji-element/ | ||
|
|
||
| A rich text block with emoji elements in a section. | ||
| """ | ||
| block = RichTextBlock( | ||
| elements=[ | ||
| RichTextSectionElement( | ||
| elements=[ | ||
| RichTextElementParts.Emoji(name="basketball"), | ||
| RichTextElementParts.Text(text=" "), | ||
| RichTextElementParts.Emoji(name="snowboarder"), | ||
| RichTextElementParts.Text(text=" "), | ||
| RichTextElementParts.Emoji(name="checkered_flag"), | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
| return block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from slack_sdk.models.blocks import ContextActionsBlock | ||
| from slack_sdk.models.blocks.basic_components import ( | ||
| FeedbackButtonObject, | ||
| PlainTextObject, | ||
| ) | ||
| from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement | ||
|
|
||
|
|
||
| def example01() -> ContextActionsBlock: | ||
| """ | ||
| Buttons to indicate positive or negative feedback. | ||
| https://docs.slack.dev/reference/block-kit/block-elements/feedback-buttons-element/ | ||
|
|
||
| A context actions block with feedback buttons. | ||
| """ | ||
| block = ContextActionsBlock( | ||
| elements=[ | ||
| FeedbackButtonsElement( | ||
| action_id="feedback_buttons_1", | ||
| positive_button=FeedbackButtonObject( | ||
| text=PlainTextObject(text="Good"), | ||
| value="positive_feedback", | ||
| accessibility_label="Mark this response as good", | ||
| ), | ||
| negative_button=FeedbackButtonObject( | ||
| text=PlainTextObject(text="Bad"), | ||
| value="negative_feedback", | ||
| accessibility_label="Mark this response as bad", | ||
| ), | ||
| ), | ||
| ] | ||
| ) | ||
| return block |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⌛ note: This is perhaps unexpected working upstream according to some metadata but we're matching what's shown in HTML at this time.