| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import type {
- Action,
- ActionsBlock,
- ActionsBlockElement,
- Button,
- Checkboxes,
- Datepicker,
- DividerBlock,
- HeaderBlock,
- InputBlock,
- MultiSelect,
- Option,
- Overflow,
- PlainTextInput,
- RadioButtons,
- SectionBlock,
- Select,
- } from '@slack/types';
- export function divider(): DividerBlock {
- return {
- type: 'divider',
- };
- }
- export function markdownHeaderBlock(text: string): HeaderBlock {
- return {
- type: 'header',
- text: {
- type: 'plain_text',
- text,
- },
- };
- }
- export function markdownSectionBlock(text: string): SectionBlock {
- return {
- type: 'section',
- text: {
- type: 'mrkdwn',
- text,
- },
- };
- }
- export function inputSectionBlock(
- blockId: string,
- labelText: string,
- actionId: string,
- isMultiline: boolean,
- placeholder: string,
- ): InputBlock {
- return {
- type: 'input',
- block_id: blockId,
- label: {
- type: 'plain_text',
- text: labelText,
- },
- element: {
- type: 'plain_text_input',
- action_id: actionId,
- multiline: isMultiline,
- placeholder: {
- type: 'plain_text',
- text: placeholder,
- },
- },
- };
- }
- export function actionsBlock(...elements: ActionsBlockElement[]): ActionsBlock {
- return {
- type: 'actions',
- elements,
- };
- }
- export function inputBlock(
- element:
- | Select
- | MultiSelect
- | Datepicker
- | PlainTextInput
- | RadioButtons
- | Checkboxes,
- blockId: string,
- labelText: string,
- ): InputBlock {
- return {
- type: 'input',
- block_id: blockId,
- element,
- label: {
- type: 'plain_text',
- text: labelText,
- },
- };
- }
- type ButtonElement = {
- text: string;
- actionId: string;
- style?: string;
- value?: string;
- };
- /**
- * Button element
- * https://api.slack.com/reference/block-kit/block-elements#button
- */
- export function buttonElement({
- text,
- actionId,
- style,
- value,
- }: ButtonElement): Button {
- const button: Button = {
- type: 'button',
- text: {
- type: 'plain_text',
- text,
- },
- action_id: actionId,
- value,
- };
- if (style === 'primary' || style === 'danger') {
- button.style = style;
- }
- return button;
- }
- /**
- * Option object
- * https://api.slack.com/reference/block-kit/composition-objects#option
- */
- export function checkboxesElementOption(
- text: string,
- description: string,
- value: string,
- ): Option {
- return {
- text: {
- type: 'mrkdwn',
- text,
- },
- description: {
- type: 'plain_text',
- text: description,
- },
- value,
- };
- }
|