Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions block-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes
### Blocks

- **[Actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block)**: Holds multiple interactive elements. [Implementation](./src/blocks/actions.py).
- **[Carousel](https://docs.slack.dev/reference/block-kit/blocks/carousel-block)**: Displays a scrollable, horizontal collection of cards. [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).
Expand Down
82 changes: 82 additions & 0 deletions block-kit/src/blocks/carousel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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 a scrollable, horizontal collection of cards.
https://docs.slack.dev/reference/block-kit/blocks/carousel-block/

A carousel with three cards, each with an icon, title, subtitle, hero
image, body, and an action button.
"""
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"),
subtitle=MarkdownTextObject(text="Refining data files"),
hero_image=ImageElement(
image_url="https://picsum.photos/400/300",
alt_text="Sample hero image",
),
body=MarkdownTextObject(text="Blue badge required to gain access."),
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"),
subtitle=MarkdownTextObject(
text="Storage, maintenance, and rotation of art pieces"
),
hero_image=ImageElement(
image_url="https://picsum.photos/400/300",
alt_text="Sample hero image",
),
body=MarkdownTextObject(text="Green badge required to gain access."),
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"),
subtitle=MarkdownTextObject(text="Wellness sessions"),
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."
),
actions=[
ButtonElement(
text=PlainTextObject(text="Action Button", emoji=False),
action_id="button_action_3",
)
],
),
],
)
return block
110 changes: 110 additions & 0 deletions block-kit/tests/blocks/test_carousel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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"},
"subtitle": {"type": "mrkdwn", "text": "Refining data files"},
"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.",
},
"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"},
"subtitle": {
"type": "mrkdwn",
"text": "Storage, maintenance, and rotation of art pieces",
},
"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.",
},
"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"},
"subtitle": {"type": "mrkdwn", "text": "Wellness sessions"},
"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.",
},
"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)