Skip to content

Commit 6403808

Browse files
committed
docs: update Button component examples
1 parent c0b35cf commit 6403808

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

apps/test-bot/src/app/commands/(interactions)/commandkit.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,16 @@ export const command: CommandData = {
4343
// }
4444

4545
export async function chatInput({ interaction }: ChatInputCommandContext) {
46-
// await interaction.deferReply();
47-
48-
// await interaction.editReply({
49-
// content: 'Click the button below to test CommandKit buttons.',
50-
// components: <ButtonGrid />,
51-
// });
52-
53-
const firstRow = (
46+
const row = (
5447
<ActionRow>
55-
<Button style={ButtonStyle.Primary} customId="button-1">
56-
Primary Action
57-
</Button>
58-
<Button style={ButtonStyle.Secondary} customId="button-2">
59-
Secondary Action
60-
</Button>
61-
</ActionRow>
62-
);
63-
64-
const secondRow = (
65-
<ActionRow>
66-
<Button style={ButtonStyle.Success} customId="button-3">
67-
Confirm
68-
</Button>
69-
<Button style={ButtonStyle.Danger} customId="button-4">
70-
Cancel
48+
<Button disabled customId="disabled">
49+
Cannot Click
7150
</Button>
51+
<Button customId="enabled">Can Click</Button>
7252
</ActionRow>
7353
);
7454

7555
await interaction.reply({
76-
components: [firstRow, secondRow],
56+
components: [row],
7757
});
7858
}

apps/website/docs/guide/04-jsx-components/02-discord-components-v1/02-button.mdx

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ emojis.
99
## Basic usage
1010

1111
```tsx title="src/app/commands/button-example.tsx"
12-
import type { ChatInputCommand } from 'commandkit';
13-
import { ActionRow, Button } from 'commandkit';
12+
import { type ChatInputCommand, ActionRow, Button } from 'commandkit';
1413

1514
export const chatInput: ChatInputCommand = async ({
1615
interaction,
1716
}) => {
18-
const button = (
17+
const buttonRow = (
1918
<ActionRow>
20-
<Button>Click me!</Button>
19+
<Button customId="clickme-button">Click me!</Button>
2120
</ActionRow>
2221
);
2322

2423
await interaction.reply({
2524
content: "Here's a button:",
26-
components: [button],
25+
components: [buttonRow],
2726
});
2827
};
2928
```
@@ -33,18 +32,26 @@ export const chatInput: ChatInputCommand = async ({
3332
Discord provides several built-in button styles:
3433

3534
```tsx title="src/app/commands/button-styles.tsx"
36-
import type { ChatInputCommand } from 'commandkit';
37-
import { ActionRow, Button } from 'commandkit';
35+
import { type ChatInputCommand, ActionRow, Button } from 'commandkit';
36+
import { ButtonStyle } from 'discord.js';
3837

3938
export const chatInput: ChatInputCommand = async ({
4039
interaction,
4140
}) => {
4241
const buttons = (
4342
<ActionRow>
44-
<Button style="primary">Primary</Button>
45-
<Button style="secondary">Secondary</Button>
46-
<Button style="success">Success</Button>
47-
<Button style="danger">Danger</Button>
43+
<Button style={ButtonStyle.Primary} customId="primary">
44+
Primary
45+
</Button>
46+
<Button style={ButtonStyle.Secondary} customId="secondary">
47+
Secondary
48+
</Button>
49+
<Button style={ButtonStyle.Success} customId="success">
50+
Success
51+
</Button>
52+
<Button style={ButtonStyle.Danger} customId="danger">
53+
Danger
54+
</Button>
4855
</ActionRow>
4956
);
5057

@@ -60,15 +67,15 @@ export const chatInput: ChatInputCommand = async ({
6067
Link buttons redirect users to external URLs:
6168

6269
```tsx title="src/app/commands/link-button.tsx"
63-
import type { ChatInputCommand } from 'commandkit';
64-
import { ActionRow, Button } from 'commandkit';
70+
import { type ChatInputCommand, ActionRow, Button } from 'commandkit';
71+
import { ButtonStyle } from 'discord.js';
6572

6673
export const chatInput: ChatInputCommand = async ({
6774
interaction,
6875
}) => {
6976
const linkButton = (
7077
<ActionRow>
71-
<Button style="link" url="https://discord.com">
78+
<Button style={ButtonStyle.Link} url="https://discord.com">
7279
Visit Discord
7380
</Button>
7481
</ActionRow>
@@ -86,16 +93,19 @@ export const chatInput: ChatInputCommand = async ({
8693
Add emojis to make your buttons more visually appealing:
8794

8895
```tsx title="src/app/commands/emoji-button.tsx"
89-
import type { ChatInputCommand } from 'commandkit';
90-
import { ActionRow, Button } from 'commandkit';
96+
import { type ChatInputCommand, ActionRow, Button } from 'commandkit';
9197

9298
export const chatInput: ChatInputCommand = async ({
9399
interaction,
94100
}) => {
95101
const emojiButton = (
96102
<ActionRow>
97-
<Button emoji="🎮">Play Game</Button>
98-
<Button emoji="⚙️">Settings</Button>
103+
<Button emoji="🎮" customId="play-game">
104+
Play Game
105+
</Button>
106+
<Button emoji="⚙️" customId="settings">
107+
Settings
108+
</Button>
99109
</ActionRow>
100110
);
101111

@@ -111,16 +121,17 @@ export const chatInput: ChatInputCommand = async ({
111121
Disable buttons to prevent interaction:
112122

113123
```tsx title="src/app/commands/disabled-button.tsx"
114-
import type { ChatInputCommand } from 'commandkit';
115-
import { ActionRow, Button } from 'commandkit';
124+
import { type ChatInputCommand, ActionRow, Button } from 'commandkit';
116125

117126
export const chatInput: ChatInputCommand = async ({
118127
interaction,
119128
}) => {
120129
const disabledButton = (
121130
<ActionRow>
122-
<Button disabled>Cannot Click</Button>
123-
<Button>Can Click</Button>
131+
<Button disabled customId="disabled">
132+
Cannot Click
133+
</Button>
134+
<Button customId="enabled">Can Click</Button>
124135
</ActionRow>
125136
);
126137

@@ -136,8 +147,12 @@ export const chatInput: ChatInputCommand = async ({
136147
Handle button interactions with the `onClick` prop:
137148

138149
```tsx title="src/app/commands/interactive-button.tsx"
139-
import type { ChatInputCommand, OnButtonKitClick } from 'commandkit';
140-
import { ActionRow, Button } from 'commandkit';
150+
import {
151+
type ChatInputCommand,
152+
type OnButtonKitClick,
153+
ActionRow,
154+
Button,
155+
} from 'commandkit';
141156
import { MessageFlags } from 'discord.js';
142157

143158
const handleClick: OnButtonKitClick = async (
@@ -158,7 +173,9 @@ export const chatInput: ChatInputCommand = async ({
158173
}) => {
159174
const interactiveButton = (
160175
<ActionRow>
161-
<Button onClick={handleClick}>Click me!</Button>
176+
<Button onClick={handleClick} customId="clickme-button">
177+
Click me!
178+
</Button>
162179
</ActionRow>
163180
);
164181

0 commit comments

Comments
 (0)