Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for DateTimepicker, EmailInput, NumberInput and URLInput #1549

Merged
merged 5 commits into from Oct 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 75 additions & 2 deletions packages/types/src/index.ts
Expand Up @@ -289,6 +289,23 @@ export interface RadioButtons extends Action, Confirmable, Focusable {
options: Option[];
}

/**
* @description An element that allows the selection of a time of day formatted as a UNIX timestamp. On desktop
* clients, this time picker will take the form of a dropdown list and the date picker will take the form of a dropdown
* calendar. Both options will have free-text entry for precise choices. On mobile clients, the time picker and date
* picker will use native UIs.
* {@link https://api.slack.com/reference/block-kit/block-elements#datetimepicker}
*/
export interface DateTimepicker extends Action, Confirmable, Focusable {
type: 'datetimepicker';
/**
* @description The initial date and time that is selected when the element is loaded, represented as a UNIX
* timestamp in seconds. This should be in the format of 10 digits, for example 1628633820 represents the date and
* time August 10th, 2021 at 03:17pm PST.
*/
initial_date_time?: number;
}

export interface Checkboxes extends Action, Confirmable, Focusable {
type: 'checkboxes';
initial_options?: Option[];
Expand All @@ -301,6 +318,60 @@ export interface PlainTextInput extends Action, Dispatchable, Focusable, Placeho
multiline?: boolean;
min_length?: number;
max_length?: number;
dispatch_action_config?: DispatchActionConfig;
focus_on_load?: boolean;
}

/**
* @description A URL input element, similar to the {@see PlainTextInput} element, creates a single line field where
* a user can enter URL-encoded data.
* {@link https://api.slack.com/reference/block-kit/block-elements#url}
*/
export interface URLInput extends Action, Dispatchable, Focusable, Placeholdable {
type: 'url_text_input';
/**
* @description The initial value in the URL input when it is loaded.
*/
initial_value?: string;
}

/**
* @description An email input element, similar to the {@see PlainTextInput} element, creates a single line field where
* a user can enter an email address.
* {@link https://api.slack.com/reference/block-kit/block-elements#email}
*/
export interface EmailInput extends Action, Dispatchable, Focusable, Placeholdable {
type: 'email_text_input';
/**
* @description The initial value in the email input when it is loaded.
*/
initial_value?: string;
}

/**
* @description A number input element, similar to the {@see PlainTextInput} element, creates a single line field where
* a user can a number. This input elements accepts floating point numbers, for example, 0.25, 5.5, and -10 are all
* valid input values. Decimal numbers are only allowed when `is_decimal_allowed` is equal to `true`.
* {@link https://api.slack.com/reference/block-kit/block-elements#number}
*/
export interface NumberInput extends Action, Dispatchable, Focusable, Placeholdable {
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;
/**
* @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;
}

/*
Expand Down Expand Up @@ -329,7 +400,8 @@ export interface ContextBlock extends Block {

export interface ActionsBlock extends Block {
type: 'actions';
elements: (Button | Overflow | Datepicker | Timepicker | Select | RadioButtons | Checkboxes | Action)[];
elements: (Button | Overflow | Datepicker | Timepicker | DateTimepicker | Select | RadioButtons | Checkboxes
| Action)[];
}

export interface DividerBlock extends Block {
Expand Down Expand Up @@ -368,7 +440,8 @@ export interface InputBlock extends Block {
label: PlainTextElement;
hint?: PlainTextElement;
optional?: boolean;
element: Select | MultiSelect | Datepicker | Timepicker | PlainTextInput | RadioButtons | Checkboxes;
element: Select | MultiSelect | Datepicker | Timepicker | DateTimepicker | PlainTextInput | URLInput | EmailInput
| NumberInput | RadioButtons | Checkboxes;
dispatch_action?: boolean;
}

Expand Down