seyfert
Version:
The most advanced framework for discord bots
87 lines (86 loc) • 2.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Container = void 0;
const common_1 = require("../common");
const types_1 = require("../types");
const _1 = require(".");
const Base_1 = require("./Base");
/**
* Represents a container component builder.
* Containers group other components together.
* @example
* ```ts
* const container = new Container()
* .addComponents(
* new TextDisplay('This is text inside a container!'),
* new ActionRow().addComponents(new Button().setLabel('Click me!'))
* )
* .setColor('Blue');
* ```
*/
class Container extends Base_1.BaseComponentBuilder {
/**
* The components held within this container.
*/
components;
/**
* Constructs a new Container.
* @param data Optional initial data for the container.
*/
constructor({ components, ...data } = {}) {
super({ ...data, type: types_1.ComponentType.Container });
this.components = (components?.map(_1.fromComponent) ?? []);
}
/**
* Adds components to the container.
* @param components The components to add. Can be a single component, an array of components, or multiple components as arguments.
* @returns The updated Container instance.
*/
addComponents(...components) {
this.components = this.components.concat(components.flat());
return this;
}
/**
* Sets the components for the container, replacing any existing components.
* @param components The components to set. Can be a single component, an array of components, or multiple components as arguments.
* @returns The updated Container instance.
*/
setComponents(...components) {
this.components = components.flat();
return this;
}
/**
* Sets whether the container's content should be visually marked as a spoiler.
* @param spoiler Whether the content is a spoiler (defaults to true).
* @returns The updated Container instance.
*/
setSpoiler(spoiler = true) {
this.data.spoiler = spoiler;
return this;
}
/**
* Sets the accent color for the container.
* @param color The color resolvable (e.g., hex code, color name, integer).
* @returns The updated Container instance.
*/
setColor(color) {
this.data.accent_color = (0, common_1.resolveColor)(color);
return this;
}
/**
* Sets the ID for the container.
* @param id The ID to set.
* @returns The updated Container instance.
*/
setId(id) {
this.data.id = id;
return this;
}
toJSON() {
return {
...this.data,
components: this.components.map(c => c.toJSON()),
};
}
}
exports.Container = Container;