UNPKG

@discord-additions/components

Version:

Some helpful additions to make creating components easier.

87 lines (86 loc) 3.66 kB
import Component from "./Component"; import type { TextInputStyles } from "../util/Constants"; import { ComponentTypes } from "../util/Constants"; import type { TextInput as ITextInput } from "../util/types"; export declare type TextInputStyle = typeof TextInputStyles[keyof typeof TextInputStyles]; export default class TextInput extends Component<typeof ComponentTypes["TEXT_INPUT"]> { customID: string; style: TextInputStyle; label: string; minLength?: number; maxLength?: number; required?: boolean; value?: string; placeholder?: string; constructor(style: TextInputStyle, label: string, customID: string); /** * Set the style of this text input * * * 1 - short * * 2 - paragraph * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles * @param {TextInputStyle} style - the style of this text input * @returns {TextInput} */ setStyle(style: TextInputStyle): this; /** * Set the custom id of this text input * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @param {string} customID - a developer-defined identifier for the input, max 100 characters * @returns {TextInput} */ setCustomID(customID: string): this; /** * Set the label of this text input * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @param {string} label - the label to display on this text input * @returns {TextInput} */ setLabel(label: string): this; /** * Set the placeholder of this text input * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @param {string} placeholder - custom placeholder text if nothing is selected, max 100 characters * @returns {TextInput} */ setPlaceholder(placeholder: string): this; /** * Set the minimum/maximum length of this text input. * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @param {number} [min] - the minimum length * @param {number} [max] - the maximum length * @returns {TextInput} */ setLength(min?: number, max?: number): this; /** * Make this text input required. * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @param {boolean} [required=true] - if this text input should be required or not - default true, setOptional also exists. * @returns {TextInput} */ setRequired(required?: boolean): this; /** * Make this text input optional. * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @returns {TextInput} */ setOptional(): this; /** * Set the initial value of this text input * * @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure * @param {string} value - a pre-filled value for this component, max 4000 characters * @returns {TextInput} */ setValue(value: string): this; /** this method is meant to be for internal use only, don't use it, as it may break or change at a moments notice */ load(style?: TextInputStyle, label?: string, customID?: string, placeholder?: string, value?: string, minLength?: number, maxLength?: number, required?: boolean): this; toJSON(): ITextInput; }