UNPKG

@shgysk8zer0/slack

Version:

An npm package for sending messages in Slack

106 lines (86 loc) 2.12 kB
'use strict'; var block = require('./block.cjs'); var plainText = require('../element/plain-text.cjs'); var input = require('../element/input/input.cjs'); var functions = require('../functions.cjs'); /** * @see https://api.slack.com/reference/block-kit/blocks#input */ class SlackInputBlock extends block.SlackBlock { #element; #optional; #label; #hint; constructor(element, { id, hint, label, optional } = {}) { super({ id }); this.element = element; if (typeof hint !== 'undefined') { this.hint = hint; } if (typeof label !== 'undefined') { this.label = label; } if (typeof optional !== 'undefined') { this.optional = optional; } } get element() { return this.#element; } set element(val) { if (val instanceof input.SlackInputElement) { this.#element = val; } else { throw new TypeError('element must be a SlackInputElement.'); } } get hint() { return this.#hint; } set hint(val) { if (typeof val === 'string') { this.#hint = new plainText.SlackPlainTextElement(val); } else if (val instanceof plainText.SlackPlainTextElement) { this.#hint = val; } else { throw new TypeError('hint must be a string or SlackPlainText object.'); } } get label() { return this.#label; } set label(val) { if (typeof val === 'string') { this.#label = new plainText.SlackPlainTextElement(val); } else if (val instanceof plainText.SlackPlainTextElement) { this.#label = val; } else { throw new TypeError('label must be a string or SlackPlainText object.'); } } get optional() { return this.#optional; } set optional(val) { if (typeof val === 'boolean') { this.#optional = val; } else { throw new TypeError('optional must be a boolean.'); } } toJSON() { return { ...super.toJSON(), element: this.#element, label: this.#label, optional: this.#optional, hint: this.#hint, }; } static get TYPE() { return 'input'; } } const createSlackInputBlock = functions.createFactory(SlackInputBlock); exports.SlackInputBlock = SlackInputBlock; exports.createSlackInputBlock = createSlackInputBlock;