Skip to main content

AiPromptBar

Package: @synapse-ui/ai-prompt
Selector: synapse-ai-prompt-bar
Status: Stable

An auto-resizing text input bar designed for AI prompt entry. Supports token estimation, submit/stop events, and keyboard shortcuts.

Overview

AiPromptBar is the primary user input surface for generative AI interactions. It handles multi-line input with automatic height adjustment, displays estimated token count, and emits events for submission and generation cancellation.

Installation

npm install @synapse-ui/ai-prompt @synapse-ui/theme

Basic Example

import { Component } from '@angular/core';
import { AiPromptBarComponent } from '@synapse-ui/ai-prompt';

@Component({
selector: 'app-chat',
standalone: true,
imports: [AiPromptBarComponent],
template: ` <synapse-ai-prompt-bar placeholder="Ask anything..." [maxRows]="8" [showTokenEstimate]="true" (submit)="onSubmit($event)" (stopGeneration)="onStop()" /> `,
})
export class ChatComponent {
onSubmit(event: PromptSubmitEvent): void {
console.log('Prompt:', event.text);
console.log('Estimated tokens:', event.estimatedTokens);
}

onStop(): void {
console.log('User requested stop');
}
}

API Reference (Planned)

Inputs

InputTypeDefaultDescription
placeholderstring'Enter a prompt...'Placeholder text
disabledbooleanfalseDisables input and submit
loadingbooleanfalseShows stop button instead of submit
maxRowsnumber6Maximum visible rows before scroll
minRowsnumber1Minimum visible rows
maxLengthnumber | nullnullCharacter limit (null = unlimited)
showTokenEstimatebooleantrueDisplay estimated token count
submitOnEnterbooleantrueEnter submits; Shift+Enter inserts newline

Outputs

OutputPayloadDescription
submitPromptSubmitEventFired when user submits a prompt
stopGenerationvoidFired when user clicks stop during loading
valueChangestringFired on every input change

Types

interface PromptSubmitEvent {
text: string;
estimatedTokens: number;
}

Token Estimation

Token count uses a client-side heuristic (characters ÷ 4, adjusted for whitespace). This is an approximation — not a substitute for server-side token counting.

// Approximate formula (planned)
estimatedTokens = Math.ceil(text.trim().length / 4);

Display format: ~128 tokens with muted styling via --synapse-text-muted.

Keyboard Shortcuts

KeyAction
EnterSubmit prompt (when submitOnEnter is true)
Shift + EnterInsert newline
EscapeClear focus (does not clear text)

States

stateDiagram-v2
[*] --> Idle
Idle --> Typing: User input
Typing --> Submitting: Enter / Submit click
Submitting --> Loading: App sets and starts stream
Loading --> Idle: Stream complete
Loading --> Idle: stopGeneration
Typing --> Idle: Clear

Accessibility

  • Textarea has an associated <label> (visible or aria-label).
  • Submit and stop buttons have descriptive aria-label attributes.
  • Token estimate uses aria-live="polite" for screen reader updates.
  • Focus ring uses --synapse-focus-ring token.

Theming

The prompt bar uses these tokens:

ElementToken
Background--synapse-surface-primary
Border--synapse-border-default
Text--synapse-text-primary
Submit button--synapse-color-accent
Stop button--synapse-color-error
Token estimate--synapse-text-muted