UNPKG

fox-block-builder

Version:

Maintainable code for loop slack-block-kit-like modal builder

116 lines (115 loc) 5.18 kB
import { PlainTextElement } from '@slack/web-api'; import { PlainTextObject } from '../objects'; import { BlockType, Prop } from '../constants'; import { FoxInputBlockElement } from './input-elements.interfaces'; import { FoxButton } from './section-elements.interfaces'; import { BlockVisibleIfRef } from '../types/visible-if.types'; export interface FoxBlock { /** * @description The type of block. */ type: string; /** * @description A string acting as a unique identifier for a block. If not specified, a `block_id` will be generated. * You can use this `block_id` when you receive an interaction payload to * {@link https://api.slack.com/interactivity/handling#payloads identify the source of the action}. * Maximum length for this field is 255 characters. `block_id` should be unique for each message and each iteration of * a message. If a message is updated, use a new `block_id`. */ block_id: string; /** Видимость по командам */ [Prop.ForTeams]?: string[]; /** Доступ к блоку по конкретным группам */ [Prop.Access]?: string; [Prop.NoSubmit]?: boolean; [Prop.VisibleIf]?: BlockVisibleIfRef[]; } /** * @description Visually separates pieces of info inside of a message. A content divider, like an `<hr>`, to split up * different blocks inside of a message. The divider block is nice and neat, requiring only a `type`. * @see {@link https://api.slack.com/reference/block-kit/blocks#divider Divider block reference}. */ export interface FoxDividerBlock extends FoxBlock { /** * @description The type of block. For a divider block, `type` is always `divider`. */ type: BlockType.Divider; } /** * @description Displays a larger-sized text block. A `header` is a plain-text block that displays in a larger, bold * font. Use it to delineate between different groups of content in your app's surfaces. * @see {@link https://api.slack.com/reference/block-kit/blocks#header Header block reference}. */ export interface FoxHeaderBlock extends FoxBlock { /** * @description The type of block. For a header block, `type` is always `header`. */ type: BlockType.Header; /** * @description The text for the block, in the form of a {@link PlainTextElement}. * Maximum length for the text in this field is 150 characters. */ text: PlainTextElement; } /** @description Displays text */ export interface FoxSectionBlock extends FoxBlock { /** * @description The type of block. For a section block, `type` is always `section`. */ type: BlockType.Section; /** * @description The text for the block, in the form of a {@link TextObject}. Minimum length for the `text` in this * field is 1 and maximum length is 3000 characters. This field is not required if a valid array of `fields` objects * is provided instead. */ text?: PlainTextObject; /** * @description One of the compatible element objects. */ accessory?: FoxButton; } /** * @description Collects information from users via block elements. * @see {@link https://api.slack.com/reference/block-kit/blocks#input Input block reference}. * @see {@link https://api.slack.com/surfaces/modals#gathering_input Collecting input in modals guide}. * @see {@link https://api.slack.com/surfaces/app-home#gathering_input Collecting input in Home tabs guide}. */ export interface FoxInputBlock extends FoxBlock { /** * @description The type of block. For an input block, `type` is always `input`. */ type: BlockType.Input; /** * @description A label that appears above an input element in the form of a {@link PlainTextElement} object. * Maximum length for the text in this field is 2000 characters. */ label: PlainTextElement; /** * @description An optional hint that appears below an input element in a lighter grey. It must be a * {@link PlainTextElement object}. Maximum length for the `text` in this field is 2000 characters. */ hint?: PlainTextElement; /** * @description A boolean that indicates whether the input element may be empty when a user submits the modal. * Defaults to `false`. */ optional?: boolean; /** * @description A block element. */ element: FoxInputBlockElement; /** * @description A boolean that indicates whether or not the use of elements in this block should dispatch a * {@link https://api.slack.com/reference/interaction-payloads/block-actions block_actions payload}. Defaults to `false`. */ dispatch_action?: boolean; /** Custom поле планфикса */ [Prop.CustomField]?: number | false; /** Флаг получения значений вместо текста */ [Prop.GetValue]?: boolean; /** Исключение из заполнения данных задачи */ [Prop.Exclude]?: boolean; /** значение как название задачи */ [Prop.AsTitle]?: boolean; } export type FoxKnownBlock = FoxDividerBlock | FoxSectionBlock | FoxInputBlock | FoxHeaderBlock;