UNPKG

fox-block-builder

Version:

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

166 lines (165 loc) 6.95 kB
import { Actionable, ChannelsSelect, Checkboxes, Confirmable, DateTimepicker, Dispatchable, EmailInput, FileInput, Focusable, MultiChannelsSelect, MultiStaticSelect, MultiUsersSelect, Placeholdable, PlainTextElement, RadioButtons, StaticSelect, Timepicker, URLInput, UsersSelect } from '@slack/web-api'; import { DirectoryParams, FoxKnownBlock, OffsetParams, OffsetRangeParams, OneSSelectType, Prop, TImageSelectVariant, YearSinceParams } from '..'; import { FoxOption } from './bits.interfaces'; export interface FoxNumberInput extends Actionable, Dispatchable, Focusable, Placeholdable { /** * @description The type of element. In this case `type` is always `number_input`. */ type: 'number_input'; /** * @description Decimal numbers are allowed if this property is `true`, set the value to `false` otherwise. */ is_decimal_allowed: boolean; /** * @description The initial value in the input when it is loaded. */ initial_value?: string; [Prop.MinLength]?: number; [Prop.MaxLength]?: number; [Prop.MinValue]?: number; [Prop.MaxValue]?: number; } export interface FoxPlainTextInput extends Actionable, Dispatchable, Focusable, Placeholdable { /** * @description The type of element. In this case `type` is always `plain_text_input`. */ type: 'plain_text_input'; /** * @description The initial value in the plain-text input when it is loaded. */ initial_value?: string; /** * @description Indicates whether the input will be a single line (`false`) or a larger textarea (`true`). * Defaults to `false`. */ multiline?: boolean; /** * @description The minimum length of input that the user must provide. If the user provides less, they will receive * an error. Maximum value is 3000. */ [Prop.MinLength]?: number; /** * @description The maximum length of input that the user can provide. If the user provides more, * they will receive an error. */ [Prop.MaxLength]?: number; /** Регекс для валидации */ [Prop.RegExp]?: RegExp; } export interface FoxRadioButtons extends RadioButtons { options: FoxOption[]; } /** * @description Allows users to select a date from a calendar style UI. * @see {@link https://api.slack.com/reference/block-kit/block-elements#datepicker Date picker element reference}. * @see {@link https://api.slack.com/interactivity/handling This is an interactive component - see our guide to enabling interactivity}. */ export interface FoxDatepicker extends Actionable, Confirmable, Focusable, Placeholdable { /** * @description The type of element. In this case `type` is always `datepicker`. */ type: 'datepicker'; /** * @description The initial date that is selected when the element is loaded. * This should be in the format `YYYY-MM-DD`. */ initialOffset?: OffsetParams; [Prop.MinOffset]?: OffsetParams; [Prop.MaxOffset]?: OffsetParams; } /** * @description Allows users to select a date from a calendar style UI. * @see {@link https://api.slack.com/reference/block-kit/block-elements#datepicker Date picker element reference}. * @see {@link https://api.slack.com/interactivity/handling This is an interactive component - see our guide to enabling interactivity}. */ export interface FoxDateRangePicker extends Actionable, Confirmable, Focusable, Placeholdable { /** * @description The type of element. In this case `type` is always `date_range_picker`. */ type: 'date_range_picker'; /** * @description The initial date that is selected when the element is loaded. * This should be in the format `YYYY-MM-DD`. */ [Prop.InitialOffsetRange]?: OffsetRangeParams; [Prop.MinOffset]?: OffsetParams; [Prop.MaxOffset]?: OffsetParams; } export interface FoxStaticSelect extends StaticSelect { initial_option?: FoxOption; options?: FoxOption[]; option_groups?: { label: PlainTextElement; options: FoxOption[]; }[]; /** Года начиная с */ [Prop.YearSince]?: YearSinceParams; } export interface FoxMultiStaticSelect extends MultiStaticSelect { initial_option?: FoxOption; options?: FoxOption[]; option_groups?: { label: PlainTextElement; options: FoxOption[]; }[]; /** Года начиная с */ [Prop.YearSince]?: YearSinceParams; } export interface DirectorySelect extends Actionable, Confirmable, Focusable, Placeholdable { /** * @description The type of element. In this case `type` is always `static_select`. */ type: 'directory_select'; /** * @description A single option that exactly matches one of the options within `options` or `option_groups`. * This option will be selected when the menu initially loads. */ initial_option?: FoxOption; [Prop.Directory]: DirectoryParams; } export interface OneSSelect extends Actionable, Confirmable, Focusable, Placeholdable { /** * @description The type of element. In this case `type` is always `static_select`. */ type: 'one_s_select'; /** * @description A single option that exactly matches one of the options within `options` or `option_groups`. * This option will be selected when the menu initially loads. */ initial_option?: FoxOption; [Prop.OneSType]: OneSSelectType; } export interface ImageSelect extends Actionable, Confirmable, Focusable, Placeholdable { type: 'image_select'; initial_option?: FoxOption; options?: FoxOption[]; option_groups?: { label: PlainTextElement; options: FoxOption[]; }[]; variant: TImageSelectVariant; } export interface AddableInput extends Actionable, Confirmable, Focusable { type: 'addable'; /** @description An array of {@link AnyBlock} that defines the content of the view. Max of 100 blocks. */ blocks: FoxKnownBlock[]; /** * @description A single option that exactly matches one of the options within `options` or `option_groups`. * This option will be selected when the menu initially loads. */ initial_option?: FoxOption; [Prop.OneSType]: OneSSelectType; /** * @description The initial value in the input when it is loaded. */ initial_value?: string; /** * @description The minimum value, cannot be greater than `max_value`. */ min_value?: string; /** * @description The maximum value, cannot be less than `min_value`. */ max_value?: string; } export type FoxInputBlockElement = Checkboxes | FoxDatepicker | FoxDateRangePicker | DateTimepicker | EmailInput | FileInput | FoxNumberInput | FoxPlainTextInput | FoxRadioButtons | Timepicker | URLInput | UsersSelect | FoxStaticSelect | ChannelsSelect | MultiUsersSelect | FoxMultiStaticSelect | MultiChannelsSelect | OneSSelect | DirectorySelect | ImageSelect | AddableInput;