UNPKG

slack-block-builder

Version:

Maintainable code for interactive Slack messages, modals, home tabs, and workflow steps. A must-have for the Slack Block Kit framework.

37 lines (36 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccordionUIComponent = void 0; const blocks_1 = require("../blocks"); const elements_1 = require("../elements"); const constants_1 = require("../internal/constants"); const lib_1 = require("../internal/lib"); class AccordionUIComponent { constructor(params) { this.items = params.items; this.paginator = params.paginator; this.expandButtonText = params.expandButtonText || constants_1.ComponentUIText.More; this.collapseButtonText = params.collapseButtonText || constants_1.ComponentUIText.Close; this.titleTextFunction = params.titleTextFunction; this.actionIdFunction = params.actionIdFunction; this.builderFunction = params.builderFunction; } getBlocks() { const unpruned = this.items.map((item, index) => { const isExpanded = this.paginator.checkItemIsExpandedByIndex(index); const blocks = [ blocks_1.Blocks.Section({ text: this.titleTextFunction({ item }) }) .accessory(elements_1.Elements.Button({ text: isExpanded ? this.collapseButtonText : this.expandButtonText, actionId: this.actionIdFunction({ expandedItems: this.paginator.getNextStateByItemIndex(index), }), })), ...isExpanded ? this.builderFunction({ item }).flat() : [], ]; return index === 0 ? blocks : [blocks_1.Blocks.Divider(), ...blocks]; }).flat(); return lib_1.Builder.pruneUndefinedFromArray(unpruned); } } exports.AccordionUIComponent = AccordionUIComponent;