docs(builders/components): document constructors (#8636)

This commit is contained in:
Almeida
2022-09-19 01:32:28 +01:00
committed by GitHub
parent 6d43e26676
commit 8444576f45
5 changed files with 119 additions and 7 deletions

View File

@@ -1,3 +1,5 @@
/* eslint-disable jsdoc/check-param-names */
import {
type APIActionRowComponent,
ComponentType,
@@ -33,6 +35,40 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
*/
public readonly components: T[];
/**
* Creates a new action row from API data
*
* @param data - The API data to create this action row with
* @example
* Creating an action row from an API data object
* ```ts
* const actionRow = new ActionRowBuilder({
* components: [
* {
* custom_id: "custom id",
* label: "Type something",
* style: TextInputStyle.Short,
* type: ComponentType.TextInput,
* },
* ],
* });
* ```
* @example
* Creating an action row using setters and API data
* ```ts
* const actionRow = new ActionRowBuilder({
* components: [
* {
* custom_id: "custom id",
* label: "Click me",
* style: ButtonStyle.Primary,
* type: ComponentType.Button,
* },
* ],
* })
* .addComponents(button2, button3);
* ```
*/
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
super({ type: ComponentType.ActionRow, ...data });
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];