mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
feat: message structures (#10982)
* feat: message structures * fix: docs * chore: components and more * feat: embed and more * feat: more substructures and code review suggestions * chore: tests and date conversions * chore: jsdoc strings * fix: tests * fix: tests * feat: hexColor getters * chore: remove getters for nested data * chore: apply suggestions from code review * fix: burst_colors in toJSON * docs: rephrase SectionBuilder remark * chore: add LabelComponent * fix: add name and size to file component * chore: move resolved interaction data to interactions dir * fix: code review * chore: bump discord-api-types * chore: apply code review suggestions * fix: lockfile * chore: update remark * fix: missing export * chore: code review and tests * build: fix file * fix: typo * fix: missing toJSON * fix: remove redundant patch overrides * chore: missing component suffix * chore: better name * chore: add comment explaining timestamp conversion --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type { APIButtonComponent, APIButtonComponentWithCustomId, ButtonStyle } from 'discord-api-types/v10';
|
||||
import { kData } from '../../utils/symbols.js';
|
||||
import type { Partialize } from '../../utils/types.js';
|
||||
import { Component } from './Component.js';
|
||||
|
||||
/**
|
||||
* The data stored by a {@link ButtonComponent} structure based on its {@link (ButtonComponent:class)."style"} property.
|
||||
*/
|
||||
export type ButtonDataType<Style extends ButtonStyle> = Style extends
|
||||
| ButtonStyle.Danger
|
||||
| ButtonStyle.Primary
|
||||
| ButtonStyle.Secondary
|
||||
| ButtonStyle.Success
|
||||
? APIButtonComponentWithCustomId
|
||||
: Extract<APIButtonComponent, { style: Style }>;
|
||||
|
||||
export abstract class ButtonComponent<
|
||||
Style extends ButtonStyle,
|
||||
Omitted extends keyof ButtonDataType<Style> | '' = '',
|
||||
> extends Component<ButtonDataType<Style>, Omitted> {
|
||||
/**
|
||||
* @param data - The raw data received from the API for the button
|
||||
*/
|
||||
public constructor(data: Partialize<ButtonDataType<Style>, Omitted>) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The style of the button
|
||||
*/
|
||||
public get style() {
|
||||
return this[kData].style;
|
||||
}
|
||||
|
||||
/**
|
||||
* The status of the button
|
||||
*/
|
||||
public get disabled() {
|
||||
return typeof this[kData].disabled === 'boolean' ? this[kData].disabled : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user