Skip to content

Commit b37c728

Browse files
committed
docs: update Modal component example
1 parent f152ef4 commit b37c728

File tree

3 files changed

+35
-118
lines changed

3 files changed

+35
-118
lines changed

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
StringSelectMenuOption,
99
OnStringSelectMenuKitSubmit,
1010
ChatInputCommand,
11+
OnModalKitSubmit,
12+
Modal,
13+
ShortInput,
14+
ParagraphInput,
1115
} from 'commandkit';
1216
import { ButtonStyle, MessageFlags } from 'discord.js';
1317

@@ -44,37 +48,34 @@ export const command: CommandData = {
4448
// );
4549
// }
4650

47-
const handleSelect: OnStringSelectMenuKitSubmit = async (
48-
interaction,
49-
context,
50-
) => {
51-
const selections = interaction.values;
51+
const handleSubmit: OnModalKitSubmit = async (interaction, context) => {
52+
const name = interaction.fields.getTextInputValue('name');
53+
const description = interaction.fields.getTextInputValue('description');
54+
5255
await interaction.reply({
53-
content: `You selected: ${selections.join(', ')}`,
56+
content: `**Profile Created!**\n**Name:** ${name}\n**Description:** ${description}`,
5457
flags: MessageFlags.Ephemeral,
5558
});
59+
5660
context.dispose();
5761
};
5862

5963
export const chatInput: ChatInputCommand = async ({ interaction }) => {
60-
const selectMenu = (
61-
<ActionRow>
62-
<StringSelectMenu
63-
placeholder="Choose multiple options"
64-
minValues={1}
65-
maxValues={3}
66-
onSelect={handleSelect}
67-
>
68-
<StringSelectMenuOption label="Pizza" value="pizza" emoji="🍕" />
69-
<StringSelectMenuOption label="Burger" value="burger" emoji="🍔" />
70-
<StringSelectMenuOption label="Pasta" value="pasta" emoji="🍝" />
71-
<StringSelectMenuOption label="Sushi" value="sushi" emoji="🍣" />
72-
</StringSelectMenu>
73-
</ActionRow>
64+
const modal = (
65+
<Modal title="User Profile" onSubmit={handleSubmit}>
66+
<ShortInput
67+
customId="name"
68+
label="Name"
69+
placeholder="Enter your name"
70+
required
71+
/>
72+
<ParagraphInput
73+
customId="description"
74+
label="Description"
75+
placeholder="Tell us about yourself"
76+
/>
77+
</Modal>
7478
);
7579

76-
await interaction.reply({
77-
content: 'Select your favorite foods (1-3 options):',
78-
components: [selectMenu],
79-
});
80+
await interaction.showModal(modal);
8081
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export const chatInput: ChatInputCommand = async ({
2929

3030
## Button styles
3131

32-
Discord provides several built-in button styles:
32+
Discord provides several button styles that you can import from the
33+
[`discord.js`](https://discord.js.org) package:
3334

3435
```tsx title="src/app/commands/button-styles.tsx"
3536
import { type ChatInputCommand, ActionRow, Button } from 'commandkit';

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

Lines changed: 8 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ appear as popups in Discord.
88
## Basic usage
99

1010
```tsx title="src/app/commands/user-profile.tsx"
11-
import type { ChatInputCommand, OnModalKitSubmit } from 'commandkit';
12-
import { Modal, ShortInput, ParagraphInput } from 'commandkit';
11+
import {
12+
type ChatInputCommand,
13+
type OnModalKitSubmit,
14+
Modal,
15+
ShortInput,
16+
ParagraphInput,
17+
} from 'commandkit';
1318
import { MessageFlags } from 'discord.js';
1419

1520
const handleSubmit: OnModalKitSubmit = async (
@@ -25,6 +30,7 @@ const handleSubmit: OnModalKitSubmit = async (
2530
flags: MessageFlags.Ephemeral,
2631
});
2732

33+
// Clean up the modal context
2834
context.dispose();
2935
};
3036

@@ -50,94 +56,3 @@ export const chatInput: ChatInputCommand = async ({
5056
await interaction.showModal(modal);
5157
};
5258
```
53-
54-
## Input types
55-
56-
### Short input
57-
58-
For single-line text input:
59-
60-
```tsx title="src/app/commands/username.tsx"
61-
import type { ChatInputCommand, OnModalKitSubmit } from 'commandkit';
62-
import { Modal, ShortInput } from 'commandkit';
63-
import { MessageFlags } from 'discord.js';
64-
65-
const handleSubmit: OnModalKitSubmit = async (
66-
interaction,
67-
context,
68-
) => {
69-
const username = interaction.fields.getTextInputValue('username');
70-
71-
await interaction.reply({
72-
content: `Username set to: ${username}`,
73-
flags: MessageFlags.Ephemeral,
74-
});
75-
76-
context.dispose();
77-
};
78-
79-
export const chatInput: ChatInputCommand = async ({
80-
interaction,
81-
}) => {
82-
const modal = (
83-
<Modal title="Set Username" onSubmit={handleSubmit}>
84-
<ShortInput
85-
customId="username"
86-
label="Username"
87-
placeholder="Enter username"
88-
required
89-
minLength={3}
90-
maxLength={20}
91-
/>
92-
</Modal>
93-
);
94-
95-
await interaction.showModal(modal);
96-
};
97-
```
98-
99-
### Paragraph input
100-
101-
For multi-line text input:
102-
103-
```tsx title="src/app/commands/feedback.tsx"
104-
import type { ChatInputCommand, OnModalKitSubmit } from 'commandkit';
105-
import { Modal, ParagraphInput } from 'commandkit';
106-
import { MessageFlags } from 'discord.js';
107-
108-
const handleSubmit: OnModalKitSubmit = async (
109-
interaction,
110-
context,
111-
) => {
112-
const feedback = interaction.fields.getTextInputValue('feedback');
113-
114-
await interaction.reply({
115-
content: "Thank you for your feedback! We'll review it soon.",
116-
flags: MessageFlags.Ephemeral,
117-
});
118-
119-
// Here you could save the feedback to a database
120-
console.log(`Feedback received: ${feedback}`);
121-
122-
context.dispose();
123-
};
124-
125-
export const chatInput: ChatInputCommand = async ({
126-
interaction,
127-
}) => {
128-
const modal = (
129-
<Modal title="Feedback Form" onSubmit={handleSubmit}>
130-
<ParagraphInput
131-
customId="feedback"
132-
label="Your Feedback"
133-
placeholder="What do you think about our service?"
134-
required
135-
minLength={10}
136-
maxLength={1000}
137-
/>
138-
</Modal>
139-
);
140-
141-
await interaction.showModal(modal);
142-
};
143-
```

0 commit comments

Comments
 (0)