Skip to main content

Components and Utilities

Generated from actual PHP reflection and PHPDoc. Names live in the Slackblocks namespace. Use named arguments and declare(strict_types=1); values validate before construction returns.

Accordion​

Expands validated collapsible containers into ordinary Slack blocks.

create​

Expands a nonempty sequence of collapsible sections in display order.

public static function create(array $sections): array
ParameterDescription
sectionslist<ContainerBlock> — Ordered, nonempty collapsible sections.

Returns: list<ContainerBlock> Blocks to spread into a modal or Home tab.

ThrowsWhen
ValidationErrorA section is missing, wrongly typed or not collapsible.

AccordionSection​

Creates one validated collapsible container for an accordion.

create​

Creates a collapsible container with the requested initial expansion state.

public static function create(PlainText|string $title, array $blocks, PlainText|string|null $subtitle = NULL, ?ImageElement $icon = NULL, bool $expanded = false, ContainerWidth $width = ContainerWidth::Standard, ?string $blockId = NULL): ContainerBlock
ParameterDescription
titlePlainText|string — Section heading.
blockslist<Block> — Ordered child blocks.
subtitlePlainText|string|null — Secondary heading.
iconImageElement|null — Optional image beside the heading.
expandedbool — Whether the section initially displays its child blocks.
widthContainerWidth — Layout width, standard by default.
blockIdstring|null — Stable identifier returned in interaction payloads.

Returns: ContainerBlock Validated section for a modal or Home tab.

ThrowsWhen
ValidationErrorA heading, child block or container option is invalid.

Related types: ContainerBlock, ContainerWidth, ImageElement, PlainText

Builder​

Slack Block Kit Builder previews, without making network requests.

url​

Blocks are wrapped in a blocks object; payloads and explicit JsonObject input are used as-is.

public static function url(Block|MessagePayload|MessageResponse|WebhookMessage|ModalView|HomeTabView|JsonObject|array $payload, ?string $teamId = NULL): string
ParameterDescription
payloadBlock|MessagePayload|MessageResponse|WebhookMessage|ModalView|HomeTabView|JsonObject|list<Block> — Preview content.
teamIdstring|null — Optional workspace ID, encoded as one URL path segment.

Returns: string URL with the Slack JSON encoded in its fragment.

ThrowsWhen
ValidationErrorBlocks, serialization context or the workspace ID are invalid.

Related types: Block, HomeTabView, JsonObject, MessagePayload, MessageResponse, ModalView, WebhookMessage

Color​

Attachment color conveniences. Pass these strings to Attachment's color argument.

ConstantSlack valueMeaning
GOOD'good'Slack's positive semantic color.
WARNING'warning'Slack's warning semantic color.
DANGER'danger'Slack's negative semantic color.
RED'#ff0000'Red (#ff0000).
BLUE'#0000ff'Blue (#0000ff).
YELLOW'#ffff00'Yellow (#ffff00).
GREEN'#00ff00'Green (#00ff00).
ORANGE'#ff8800'Orange (#ff8800).
PURPLE'#8800ff'Purple (#8800ff).
BLACK'#000000'Black (#000000).

hex​

Validates six hexadecimal digits and adds one leading # if absent.

public static function hex(string $value): string
ParameterDescription
valuestring — Six hexadecimal digits with an optional leading #.

Returns: string Color with one leading #, preserving letter case.

ThrowsWhen
ValidationErrorThe value is not a six-digit hexadecimal color.

Paginator​

Expands one page into blocks, optional page text and navigation buttons.

create​

Selects one page and adds navigation only when multiple pages exist.

public static function create(string $actionIdPrefix, array $blocks, int $page = 1, int $pageSize = 5, PlainText|string $previousText = 'Previous', PlainText|string $nextText = 'Next', bool $showPageIndicator = true, ?string $blockId = NULL): array
ParameterDescription
actionIdPrefixstring — Nonempty prefix for .previous and .next action IDs.
blockslist<Block> — Full nonempty sequence of content blocks.
pageint — One-based page number.
pageSizeint — Positive number of content blocks per page; controls are additional.
previousTextPlainText|string — Previous-button label.
nextTextPlainText|string — Next-button label.
showPageIndicatorbool — Whether to add a context block showing the current page.
blockIdstring|null — Identifier for the navigation actions block.

Returns: list<Block> Spread into a payload to enforce that surface's total block limit.

ThrowsWhen
ValidationErrorContent, page bounds or generated navigation controls are invalid.

Related types: PlainText