diff --git a/block-kit/README.md b/block-kit/README.md index a35a6c0..828da87 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -11,6 +11,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes - **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.py). - **[Alert](https://docs.slack.dev/reference/block-kit/blocks/alert-block)**: Displays alerts, warnings, and informational messages. [Implementation](./src/blocks/alert.py). - **[Card](https://docs.slack.dev/reference/block-kit/blocks/card-block)**: Displays content in a card. [Implementation](./src/blocks/card.py). +- **[Carousel](https://docs.slack.dev/reference/block-kit/blocks/carousel-block)**: Displays related card blocks in a horizontally-scrolling container. [Implementation](./src/blocks/carousel.py). - **[Context](https://docs.slack.dev/reference/block-kit/blocks/context-block)**: Provides contextual info, which can include both images and text. [Implementation](./src/blocks/context.py). - **[Context actions](https://docs.slack.dev/reference/block-kit/blocks/context-actions-block)**: Displays actions as contextual info, which can include both feedback buttons and icon buttons. [Implementation](./src/blocks/context_actions.py). - **[Divider](https://docs.slack.dev/reference/block-kit/blocks/divider-block)**: Visually separates pieces of info inside of a message. [Implementation](./src/blocks/divider.py). diff --git a/block-kit/src/blocks/carousel.py b/block-kit/src/blocks/carousel.py new file mode 100644 index 0000000..70bb1a7 --- /dev/null +++ b/block-kit/src/blocks/carousel.py @@ -0,0 +1,104 @@ +from slack_sdk.models.blocks import CardBlock, CarouselBlock +from slack_sdk.models.blocks.basic_components import MarkdownTextObject, PlainTextObject +from slack_sdk.models.blocks.block_elements import ButtonElement, ImageElement + + +def example01() -> CarouselBlock: + """ + Displays related card blocks in a horizontally-scrolling container. + https://docs.slack.dev/reference/block-kit/blocks/carousel-block/ + + A sample carousel block. + """ + block = CarouselBlock( + elements=[ + CardBlock( + block_id="carousel-card-1", + icon=ImageElement( + image_url="https://picsum.photos/36/36", + alt_text="Icon", + ), + title=MarkdownTextObject( + text="MDR", + verbatim=False, + ), + subtitle=MarkdownTextObject( + text="Refining data files", + verbatim=False, + ), + hero_image=ImageElement( + image_url="https://picsum.photos/400/300", + alt_text="Sample hero image", + ), + body=MarkdownTextObject( + text="Blue badge required to gain access.", + verbatim=False, + ), + actions=[ + ButtonElement( + text=PlainTextObject(text="Action Button", emoji=False), + action_id="button_action_1", + ) + ], + ), + CardBlock( + block_id="carousel-card-2", + icon=ImageElement( + image_url="https://picsum.photos/36/36", + alt_text="Icon", + ), + title=MarkdownTextObject( + text="O&D", + verbatim=False, + ), + subtitle=MarkdownTextObject( + text="Storage, maintenance, and rotation of art pieces", + verbatim=False, + ), + hero_image=ImageElement( + image_url="https://picsum.photos/400/300", + alt_text="Sample hero image", + ), + body=MarkdownTextObject( + text="Green badge required to gain access.", + verbatim=False, + ), + actions=[ + ButtonElement( + text=PlainTextObject(text="Action Button", emoji=False), + action_id="button_action_2", + ) + ], + ), + CardBlock( + block_id="carousel-card-3", + icon=ImageElement( + image_url="https://picsum.photos/36/36", + alt_text="Icon", + ), + title=MarkdownTextObject( + text="Wellness Center", + verbatim=False, + ), + subtitle=MarkdownTextObject( + text="Wellness sessions", + verbatim=False, + ), + hero_image=ImageElement( + image_url="https://picsum.photos/400/300", + alt_text="Sample hero image", + ), + body=MarkdownTextObject( + text="Please take a seat in the waiting room until called.", + verbatim=False, + ), + actions=[ + ButtonElement( + text=PlainTextObject(text="Action Button", emoji=False), + action_id="button_action_3", + ) + ], + ), + ], + ) + return block diff --git a/block-kit/tests/blocks/test_carousel.py b/block-kit/tests/blocks/test_carousel.py new file mode 100644 index 0000000..9abd39e --- /dev/null +++ b/block-kit/tests/blocks/test_carousel.py @@ -0,0 +1,134 @@ +import json + +from src.blocks import carousel + + +def test_example01(): + block = carousel.example01() + actual = block.to_dict() + expected = { + "type": "carousel", + "elements": [ + { + "type": "card", + "block_id": "carousel-card-1", + "icon": { + "type": "image", + "image_url": "https://picsum.photos/36/36", + "alt_text": "Icon", + }, + "title": { + "type": "mrkdwn", + "text": "MDR", + "verbatim": False, + }, + "subtitle": { + "type": "mrkdwn", + "text": "Refining data files", + "verbatim": False, + }, + "hero_image": { + "type": "image", + "image_url": "https://picsum.photos/400/300", + "alt_text": "Sample hero image", + }, + "body": { + "type": "mrkdwn", + "text": "Blue badge required to gain access.", + "verbatim": False, + }, + "actions": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Action Button", + "emoji": False, + }, + "action_id": "button_action_1", + } + ], + }, + { + "type": "card", + "block_id": "carousel-card-2", + "icon": { + "type": "image", + "image_url": "https://picsum.photos/36/36", + "alt_text": "Icon", + }, + "title": { + "type": "mrkdwn", + "text": "O&D", + "verbatim": False, + }, + "subtitle": { + "type": "mrkdwn", + "text": "Storage, maintenance, and rotation of art pieces", + "verbatim": False, + }, + "hero_image": { + "type": "image", + "image_url": "https://picsum.photos/400/300", + "alt_text": "Sample hero image", + }, + "body": { + "type": "mrkdwn", + "text": "Green badge required to gain access.", + "verbatim": False, + }, + "actions": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Action Button", + "emoji": False, + }, + "action_id": "button_action_2", + } + ], + }, + { + "type": "card", + "block_id": "carousel-card-3", + "icon": { + "type": "image", + "image_url": "https://picsum.photos/36/36", + "alt_text": "Icon", + }, + "title": { + "type": "mrkdwn", + "text": "Wellness Center", + "verbatim": False, + }, + "subtitle": { + "type": "mrkdwn", + "text": "Wellness sessions", + "verbatim": False, + }, + "hero_image": { + "type": "image", + "image_url": "https://picsum.photos/400/300", + "alt_text": "Sample hero image", + }, + "body": { + "type": "mrkdwn", + "text": "Please take a seat in the waiting room until called.", + "verbatim": False, + }, + "actions": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Action Button", + "emoji": False, + }, + "action_id": "button_action_3", + } + ], + }, + ], + } + assert json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True)