UNPKG

fox-block-builder

Version:

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

242 lines (241 loc) 11 kB
import { Actionable, ChannelsSelect, Checkboxes, Confirmable, DateTimepicker, Dispatchable, EmailInput, FileInput, Focusable, MaxItemsSelectable, MultiChannelsSelect, MultiStaticSelect, Placeholdable, PlainTextElement, StaticSelect, Timepicker, URLInput, URLRespondable } from '@slack/web-api'; import { DatePickerPickerParams, DirectoryParams, FoxKnownBlock, InitialUserParams, OffsetParams, OffsetRangeParams, OneSSelectType, Prop, TImageSelectVariant, MaxDateRangeParams } from '..'; import { FoxOption } from './bits.interfaces'; import { Channel, UserProfile } from 'fox-loop-sdk'; import { TeamSettable, TextProppable } from './extensions.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; } /** * @description Allows users to choose one item from a list of possible options. * @see {@link https://api.slack.com/reference/block-kit/block-elements#radio Radio button group element reference}. * @see {@link https://api.slack.com/interactivity/handling This is an interactive component - see our guide to enabling interactivity}. */ export interface FoxRadioButtons extends Actionable, Confirmable, Focusable { /** * @description The type of element. In this case `type` is always `radio_buttons`. */ type: 'radio_buttons'; /** * @description An {@link Option} object that exactly matches one of the options within `options`. This option will * be selected when the radio button group initially loads. */ initial_option?: FoxOption; /** * @description An array of {@link Option} objects. A maximum of 10 options are allowed. */ 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`. */ [Prop.MinOffset]?: OffsetParams; [Prop.MaxOffset]?: OffsetParams; [Prop.InitialOffset]?: OffsetParams; [Prop.DatePickerPicker]?: DatePickerPickerParams; } /** * @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.MinOffset]?: OffsetParams; [Prop.MaxOffset]?: OffsetParams; [Prop.InitialOffsetRange]?: OffsetRangeParams; [Prop.DatePickerPicker]?: DatePickerPickerParams; [Prop.MaxDateRange]?: MaxDateRangeParams; } export interface FoxStaticSelect extends StaticSelect { initial_option?: FoxOption; options?: FoxOption[]; option_groups?: { label: PlainTextElement; options: FoxOption[]; }[]; } export interface FoxMultiStaticSelect extends MultiStaticSelect { initial_option?: FoxOption; options?: FoxOption[]; option_groups?: { label: PlainTextElement; options: FoxOption[]; }[]; } 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; } /** * @description This select menu will populate its options with a list of Slack users visible to the current user in the * active workspace. * @see {@link https://api.slack.com/reference/block-kit/block-elements#users_select Select menu of users reference}. * @see {@link https://api.slack.com/interactivity/handling This is an interactive component - see our guide to enabling interactivity}. */ export interface FoxUsersSelect extends Actionable, Confirmable, Focusable, Placeholdable, TextProppable<UserProfile>, TeamSettable { /** * @description The type of element. In this case `type` is always `users_select`. */ type: 'users_select'; /** * @description The user ID of any valid user to be pre-selected when the menu loads. */ [Prop.InitialUser]?: InitialUserParams; } export interface FoxMultiUsersSelect extends Actionable, Confirmable, Focusable, MaxItemsSelectable, Placeholdable, TextProppable<UserProfile>, TeamSettable { /** * @description The type of element. In this case `type` is always `multi_users_select`. */ type: 'multi_users_select'; /** * @description An array of user IDs of any valid users to be pre-selected when the menu loads. */ initial_users?: string[]; } /** * @description This select menu will populate its options with a list of public channels visible to the current user * in the active workspace. * @see {@link https://api.slack.com/reference/block-kit/block-elements#channels_select Select menu of public channels reference}. * @see {@link https://api.slack.com/interactivity/handling This is an interactive component - see our guide to enabling interactivity}. */ export interface FoxChannelsSelect extends Actionable, Confirmable, Focusable, Placeholdable, URLRespondable, TextProppable<Channel>, TeamSettable { /** * @description The type of element. In this case `type` is always `channels_select`. */ type: 'channels_select'; /** * @description The ID of any valid public channel to be pre-selected when the menu loads. */ initial_channel?: string; } /** * @description This multi-select menu will populate its options with a list of public channels visible to the current * user in the active workspace. * @see {@link https://api.slack.com/reference/block-kit/block-elements#channel_multi_select Multi-select menu of public channels reference}. * @see {@link https://api.slack.com/interactivity/handling This is an interactive component - see our guide to enabling interactivity}. */ export interface FoxMultiChannelsSelect extends Actionable, Confirmable, Focusable, MaxItemsSelectable, Placeholdable, TextProppable<Channel>, TeamSettable { /** * @description The type of element. In this case `type` is always `multi_channels_select`. */ type: 'multi_channels_select'; /** * @description An array of one or more IDs of any valid public channel to be pre-selected when the menu loads. */ initial_channels?: string[]; } export type FoxInputBlockElement = Checkboxes | FoxDatepicker | FoxDateRangePicker | DateTimepicker | EmailInput | FileInput | FoxNumberInput | FoxPlainTextInput | FoxRadioButtons | Timepicker | URLInput | FoxUsersSelect | FoxStaticSelect | ChannelsSelect | MultiChannelsSelect | FoxMultiUsersSelect | FoxMultiStaticSelect | OneSSelect | DirectorySelect | ImageSelect | AddableInput;