AI prompt box
A chat input that grows with the text, with attach, search and reasoning toggles and a send button that wakes up when ready.
Svelte 5 · Version 1.0.0 · Zero extra packages
Live preview
Design decision
Mode toggles sit beside the input so people choose how to ask before they send. Enter sends and Shift+Enter adds a line. Original Svelte 5 implementation. No code was copied from the inspiring component.
Inspired by AI Prompt Box by @jahed on 21st.dev ↗
Source and integration
Handle onsubmit, which receives the text and the search and think flags. Wire the attach button to your upload flow.
You may copy and adapt this original SaaSCrisp implementation in personal and commercial websites.
AIPromptBox.svelte
<script lang="ts">
let {
onsubmit,
placeholder = 'Ask anything…',
label = 'Message'
}: { onsubmit: (message: { text: string; search: boolean; think: boolean }) => void; placeholder?: string; label?: string } =
$props();
let text = $state('');
let search = $state(false);
let think = $state(false);
const ready = $derived(text.trim().length > 0);
function send(event?: SubmitEvent) {
event?.preventDefault();
if (!ready) return;
onsubmit({ text: text.trim(), search, think });
text = '';
}
function onkeydown(event: KeyboardEvent) {
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
event.preventDefault();
send();
}
}
</script>
<form class="ap" onsubmit={send}>
<textarea bind:value={text} {onkeydown} {placeholder} aria-label={label} rows="1"></textarea>
<div class="ap-bar">
<div class="ap-tools">
<button type="button" class="ap-icon" aria-label="Attach a file">
<svg viewBox="0 0 24 24" aria-hidden="true"
><path d="m21.4 11.1-9.2 9.2a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5" /></svg
>
</button>
<button type="button" class="ap-chip" aria-pressed={search} onclick={() => (search = !search)}>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20zM2 12h20M12 2a15 15 0 0 1 0 20M12 2a15 15 0 0 0 0 20" /></svg>
Search
</button>
<button type="button" class="ap-chip" aria-pressed={think} onclick={() => (think = !think)}>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7V16h8v-1.3A7 7 0 0 0 12 2z" /></svg>
Think
</button>
</div>
<button type="submit" class="ap-send" disabled={!ready} aria-label="Send message">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7" /></svg>
</button>
</div>
</form>
<style>
.ap {
--_bg: var(--ui-bg, #ffffff);
--_border: var(--ui-border, rgb(15 23 42 / 0.1));
--_text: var(--ui-text, #0f172a);
--_muted: var(--ui-muted, #64748b);
--_accent: var(--ui-accent, #4f46e5);
display: grid;
gap: 6px;
padding: 12px;
border: 1px solid var(--_border);
border-radius: 22px;
background:
linear-gradient(180deg, rgb(15 23 42 / 0.03), transparent 60%),
var(--_bg);
box-shadow:
inset 0 1px 0 rgb(255 255 255 / 0.05),
0 20px 50px -24px rgb(15 23 42 / 0.12);
font-family: var(--ui-font, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif);
transition:
border-color 0.2s,
box-shadow 0.2s;
}
.ap:focus-within {
border-color: rgb(15 23 42 / 0.16);
box-shadow:
inset 0 1px 0 rgb(255 255 255 / 0.05),
0 0 0 4px rgb(15 23 42 / 0.03),
0 20px 50px -24px rgb(15 23 42 / 0.12);
}
textarea {
field-sizing: content;
min-height: 48px;
max-height: 200px;
padding: 4px 6px;
resize: none;
border: 0;
outline: 0;
background: none;
color: var(--_text);
font: inherit;
font-size: 15px;
line-height: 1.5;
}
textarea::placeholder {
color: var(--_muted);
}
.ap-bar,
.ap-tools {
display: flex;
align-items: center;
gap: 6px;
}
.ap-bar {
justify-content: space-between;
}
button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
border: 1px solid var(--_border);
background: rgb(15 23 42 / 0.03);
color: var(--_muted);
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition:
color 0.15s,
background-color 0.15s,
border-color 0.15s,
transform 0.15s;
}
button svg {
width: 15px;
height: 15px;
fill: none;
stroke: currentColor;
stroke-width: 1.9;
stroke-linecap: round;
stroke-linejoin: round;
}
button:hover:not(:disabled) {
background: rgb(15 23 42 / 0.07);
color: var(--_text);
}
button:focus-visible {
outline: 2px solid var(--_accent);
outline-offset: 2px;
}
.ap-icon {
width: 34px;
height: 34px;
border-radius: 999px;
}
.ap-chip {
height: 34px;
padding: 0 12px;
border-radius: 999px;
}
.ap-chip[aria-pressed='true'] {
border-color: color-mix(in srgb, var(--_accent) 45%, transparent);
background: color-mix(in srgb, var(--_accent) 12%, transparent);
color: var(--_accent);
}
.ap-send {
width: 36px;
height: 36px;
border-radius: 999px;
border-color: transparent;
background: var(--_text);
color: #fff;
}
.ap-send:hover:not(:disabled) {
background: color-mix(in srgb, var(--_text) 85%, #fff);
color: #fff;
}
.ap-send:active:not(:disabled) {
transform: scale(0.94);
}
.ap-send:disabled {
background: rgb(15 23 42 / 0.08);
color: var(--_muted);
cursor: not-allowed;
}
@media (max-width: 420px) {
.ap-chip {
padding: 0 10px;
}
}
</style>
Agent prompt
Use the SaaSCrisp UI Library MCP at https://www.saascrisp.com/api/library/mcp. Retrieve ai-prompt-box version 1.0.0 for svelte with get_ui_asset. Preview: https://www.saascrisp.com/library/ai-prompt-box. Confirm the project's stack, reuse local primitives and map CSS variables to existing design tokens. Integrate the files and run the project's checks. Report changed files and additional dependencies.