AI Component Specific Rules
This library is focused on AI chat interfaces. All components should be designed with AI use cases in mind.
Spartan UI Components (Preferred)
IMPORTANT: When building UI for this project, prefer using Spartan UI components from @angular-ai-kit/spartan-ui/*.
Spartan UI provides accessible, well-designed primitives that integrate seamlessly with our Tailwind-based styling system.
Available Spartan UI Libraries
| Package |
Purpose |
@angular-ai-kit/spartan-ui/avatar |
User/assistant avatars |
@angular-ai-kit/spartan-ui/badge |
Status badges, labels |
@angular-ai-kit/spartan-ui/button |
Buttons with variants |
@angular-ai-kit/spartan-ui/button-group |
Grouped button actions |
@angular-ai-kit/spartan-ui/checkbox |
Checkbox inputs |
@angular-ai-kit/spartan-ui/command |
Command palette / search |
@angular-ai-kit/spartan-ui/dropdown-menu |
Context menus, action menus |
@angular-ai-kit/spartan-ui/empty |
Empty state displays |
@angular-ai-kit/spartan-ui/field |
Form field wrapper with label/error |
@angular-ai-kit/spartan-ui/icon |
Icon wrapper for ng-icons |
@angular-ai-kit/spartan-ui/input |
Text inputs |
@angular-ai-kit/spartan-ui/input-group |
Input with addons (buttons, icons) |
@angular-ai-kit/spartan-ui/item |
List items with actions |
@angular-ai-kit/spartan-ui/popover |
Popover overlays |
@angular-ai-kit/spartan-ui/radio-group |
Radio button groups |
@angular-ai-kit/spartan-ui/select |
Select dropdowns |
@angular-ai-kit/spartan-ui/separator |
Visual dividers |
@angular-ai-kit/spartan-ui/spinner |
Loading spinners |
@angular-ai-kit/spartan-ui/switch |
Toggle switches |
@angular-ai-kit/spartan-ui/textarea |
Multiline text inputs |
Usage Pattern
import { HlmButton } from '@angular-ai-kit/spartan-ui/button';
import { HlmButtonGroupImports } from '@angular-ai-kit/spartan-ui/button-group';
import { HlmIcon } from '@angular-ai-kit/spartan-ui/icon';
import { HlmInputGroupImports } from '@angular-ai-kit/spartan-ui/input-group';
@Component({
selector: 'ai-chat-input',
imports: [HlmButtonGroupImports, HlmInputGroupImports, HlmButton, HlmIcon],
template: `
<div hlmInputGroup>
<textarea
hlmInputGroupTextarea
placeholder="Send a message..."
></textarea>
<div hlmInputGroupAddon align="inline-end">
<button hlmInputGroupButton size="icon-sm">
<ng-icon hlm name="lucideArrowUp" size="sm" />
</button>
</div>
</div>
`,
})
export class ChatInputComponent {}
When to Use Spartan UI
- Form inputs (use
hlmInput, hlmInputGroup, hlmField)
- Buttons and actions (use
hlmBtn, hlmButtonGroup)
- Dropdowns and menus (use
hlmDropdownMenu, hlmPopover)
- Avatars (use
hlmAvatar)
- Badges and labels (use
hlmBadge)
- Loading states (use
hlmSpinner)
- Empty states (use
hlmEmpty)
- List items (use
hlmItem)
When to Build Custom
- Spartan doesn't have an equivalent component
- Need highly specialized AI-specific behavior
- Performance-critical streaming components
Chat Components
Message Styling
User Messages:
- Display in a card/bubble with background styling
- Align to the right side
- Include edit and copy functionality
AI/Assistant Responses:
- Display as plain text (no card or wrapper)
- Align to the left side
- Support markdown rendering with syntax highlighting
- Include action buttons: copy, regenerate, thumbs up/down
Message Bubbles (User)
- Display with card styling (bg-card, border, rounded corners)
- Include copy and edit functionality
- Show timestamps (optional, configurable)
AI Response
- Plain text display - no card, border, or wrapper styling
- Full markdown support (GFM)
- Code blocks with syntax highlighting and copy buttons
- Support streaming text display with typing cursor
- Action buttons appear on hover
Message Lists
- Auto-scroll to latest message
- Support virtual scrolling for long conversations
- Group messages by date/time
- Handle loading states between messages
Chat Containers
- Manage conversation state
- Handle message submission
- Support regeneration of responses
- Provide clear error states
Input Components
Message Input
- Support keyboard shortcuts:
Enter to submit
Shift+Enter for new line
Escape to clear/cancel
- Include loading/disabled states during AI response
- Auto-resize textarea as content grows
- Character/token count display (optional)
- Validate inputs when appropriate
- Provide clear visual feedback
Prompt Suggestions
- Display suggested prompts/starters
- Handle click to populate input
- Support customizable suggestions
Display Components
Markdown Rendering
- Support full markdown syntax
- Code blocks with syntax highlighting
- Copy-to-clipboard for code blocks
- Handle long content (scrolling, truncation)
- Support tables, lists, blockquotes
Code Blocks
- Syntax highlighting for common languages
- Language label display
- Copy button
- Line numbers (optional)
- Word wrap handling
Streaming Text
- Character-by-character or word-by-word reveal
- Cursor/caret animation
- Smooth transitions
- Pause/resume capability
Control Components
Action Buttons
- Copy message content
- Regenerate response
- Edit message
- Delete message
- Thumbs up/down feedback
State Indicators
- Loading spinners
- Typing indicators
- Connection status
- Error states with retry options
Common Patterns
Loading States
// Always provide loading feedback
@if (isLoading()) {
<ai-typing-indicator />
} @else {
<ai-message-content [content]="message().content" />
}
Error Handling
// Graceful error states with retry
@if (error()) {
<ai-error-message
[error]="error()"
(retry)="handleRetry()"
/>
}
Empty States
// Welcoming empty state with suggestions
@if (messages().length === 0) {
<ai-empty-state
[suggestions]="promptSuggestions"
(selectPrompt)="handlePromptSelect($event)"
/>
}
Streaming Support
// Support for streaming responses
message = input.required<ChatMessage>();
isStreaming = input(false);
// Show cursor while streaming
@if (isStreaming()) {
<span class="typing-cursor">cursor</span>
}
Accessibility for AI Components
Screen Reader Announcements
- Announce new messages with
aria-live
- Announce loading/streaming states
- Announce errors clearly
Keyboard Navigation
- Navigate between messages with arrow keys
- Focus management when new messages arrive
- Escape to cancel ongoing operations
Visual Indicators
- Clear distinction between user/assistant messages
- Loading states visible to all users
- Error states with clear instructions
Performance Considerations
Message Lists
- Virtual scrolling for 100+ messages
- Lazy load older messages
- Debounce scroll events
- Efficient re-renders with trackBy
Streaming
- Batch DOM updates during streaming
- Use
requestAnimationFrame for smooth animations
- Avoid layout thrashing
Memory Management
- Clean up subscriptions on destroy
- Limit stored message history
- Clear streaming buffers when complete
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: ai-components3description: Use when building AI chat interfaces. Triggers on "chat", "message", "AI", "streaming", "typing indicator", "message bubble", "chat input", "Spartan UI", "hlmBtn", "hlmAvatar", or chat component questions.4---56# AI Component Specific Rules78**This library is focused on AI chat interfaces. All components should be designed with AI use cases in mind.**910## Spartan UI Components (Preferred)1112**IMPORTANT: When building UI for this project, prefer using Spartan UI components from `@angular-ai-kit/spartan-ui/*`.**1314Spartan UI provides accessible, well-designed primitives that integrate seamlessly with our Tailwind-based styling system.1516### Available Spartan UI Libraries1718| Package | Purpose |19| ------------------------------------------ | ----------------------------------- |20| `@angular-ai-kit/spartan-ui/avatar` | User/assistant avatars |21| `@angular-ai-kit/spartan-ui/badge` | Status badges, labels |22| `@angular-ai-kit/spartan-ui/button` | Buttons with variants |23| `@angular-ai-kit/spartan-ui/button-group` | Grouped button actions |24| `@angular-ai-kit/spartan-ui/checkbox` | Checkbox inputs |25| `@angular-ai-kit/spartan-ui/command` | Command palette / search |26| `@angular-ai-kit/spartan-ui/dropdown-menu` | Context menus, action menus |27| `@angular-ai-kit/spartan-ui/empty` | Empty state displays |28| `@angular-ai-kit/spartan-ui/field` | Form field wrapper with label/error |29| `@angular-ai-kit/spartan-ui/icon` | Icon wrapper for ng-icons |30| `@angular-ai-kit/spartan-ui/input` | Text inputs |31| `@angular-ai-kit/spartan-ui/input-group` | Input with addons (buttons, icons) |32| `@angular-ai-kit/spartan-ui/item` | List items with actions |33| `@angular-ai-kit/spartan-ui/popover` | Popover overlays |34| `@angular-ai-kit/spartan-ui/radio-group` | Radio button groups |35| `@angular-ai-kit/spartan-ui/select` | Select dropdowns |36| `@angular-ai-kit/spartan-ui/separator` | Visual dividers |37| `@angular-ai-kit/spartan-ui/spinner` | Loading spinners |38| `@angular-ai-kit/spartan-ui/switch` | Toggle switches |39| `@angular-ai-kit/spartan-ui/textarea` | Multiline text inputs |4041### Usage Pattern4243```typescript44import { HlmButton } from '@angular-ai-kit/spartan-ui/button';45import { HlmButtonGroupImports } from '@angular-ai-kit/spartan-ui/button-group';46import { HlmIcon } from '@angular-ai-kit/spartan-ui/icon';47import { HlmInputGroupImports } from '@angular-ai-kit/spartan-ui/input-group';4849@Component({50 selector: 'ai-chat-input',51 imports: [HlmButtonGroupImports, HlmInputGroupImports, HlmButton, HlmIcon],52 template: `53 <div hlmInputGroup>54 <textarea55 hlmInputGroupTextarea56 placeholder="Send a message..."57 ></textarea>58 <div hlmInputGroupAddon align="inline-end">59 <button hlmInputGroupButton size="icon-sm">60 <ng-icon hlm name="lucideArrowUp" size="sm" />61 </button>62 </div>63 </div>64 `,65})66export class ChatInputComponent {}67```6869### When to Use Spartan UI7071- Form inputs (use `hlmInput`, `hlmInputGroup`, `hlmField`)72- Buttons and actions (use `hlmBtn`, `hlmButtonGroup`)73- Dropdowns and menus (use `hlmDropdownMenu`, `hlmPopover`)74- Avatars (use `hlmAvatar`)75- Badges and labels (use `hlmBadge`)76- Loading states (use `hlmSpinner`)77- Empty states (use `hlmEmpty`)78- List items (use `hlmItem`)7980### When to Build Custom8182- Spartan doesn't have an equivalent component83- Need highly specialized AI-specific behavior84- Performance-critical streaming components8586## Chat Components8788### Message Styling8990**User Messages:**9192- Display in a card/bubble with background styling93- Align to the right side94- Include edit and copy functionality9596**AI/Assistant Responses:**9798- Display as plain text (no card or wrapper)99- Align to the left side100- Support markdown rendering with syntax highlighting101- Include action buttons: copy, regenerate, thumbs up/down102103### Message Bubbles (User)104105- Display with card styling (bg-card, border, rounded corners)106- Include copy and edit functionality107- Show timestamps (optional, configurable)108109### AI Response110111- Plain text display - no card, border, or wrapper styling112- Full markdown support (GFM)113- Code blocks with syntax highlighting and copy buttons114- Support streaming text display with typing cursor115- Action buttons appear on hover116117### Message Lists118119- Auto-scroll to latest message120- Support virtual scrolling for long conversations121- Group messages by date/time122- Handle loading states between messages123124### Chat Containers125126- Manage conversation state127- Handle message submission128- Support regeneration of responses129- Provide clear error states130131## Input Components132133### Message Input134135- Support keyboard shortcuts:136 - `Enter` to submit137 - `Shift+Enter` for new line138 - `Escape` to clear/cancel139- Include loading/disabled states during AI response140- Auto-resize textarea as content grows141- Character/token count display (optional)142- Validate inputs when appropriate143- Provide clear visual feedback144145### Prompt Suggestions146147- Display suggested prompts/starters148- Handle click to populate input149- Support customizable suggestions150151## Display Components152153### Markdown Rendering154155- Support full markdown syntax156- Code blocks with syntax highlighting157- Copy-to-clipboard for code blocks158- Handle long content (scrolling, truncation)159- Support tables, lists, blockquotes160161### Code Blocks162163- Syntax highlighting for common languages164- Language label display165- Copy button166- Line numbers (optional)167- Word wrap handling168169### Streaming Text170171- Character-by-character or word-by-word reveal172- Cursor/caret animation173- Smooth transitions174- Pause/resume capability175176## Control Components177178### Action Buttons179180- Copy message content181- Regenerate response182- Edit message183- Delete message184- Thumbs up/down feedback185186### State Indicators187188- Loading spinners189- Typing indicators190- Connection status191- Error states with retry options192193## Common Patterns194195### Loading States196197```typescript198// Always provide loading feedback199@if (isLoading()) {200 <ai-typing-indicator />201} @else {202 <ai-message-content [content]="message().content" />203}204```205206### Error Handling207208```typescript209// Graceful error states with retry210@if (error()) {211 <ai-error-message212 [error]="error()"213 (retry)="handleRetry()"214 />215}216```217218### Empty States219220```typescript221// Welcoming empty state with suggestions222@if (messages().length === 0) {223 <ai-empty-state224 [suggestions]="promptSuggestions"225 (selectPrompt)="handlePromptSelect($event)"226 />227}228```229230### Streaming Support231232```typescript233// Support for streaming responses234message = input.required<ChatMessage>();235isStreaming = input(false);236237// Show cursor while streaming238@if (isStreaming()) {239 <span class="typing-cursor">cursor</span>240}241```242243## Accessibility for AI Components244245### Screen Reader Announcements246247- Announce new messages with `aria-live`248- Announce loading/streaming states249- Announce errors clearly250251### Keyboard Navigation252253- Navigate between messages with arrow keys254- Focus management when new messages arrive255- Escape to cancel ongoing operations256257### Visual Indicators258259- Clear distinction between user/assistant messages260- Loading states visible to all users261- Error states with clear instructions262263## Performance Considerations264265### Message Lists266267- Virtual scrolling for 100+ messages268- Lazy load older messages269- Debounce scroll events270- Efficient re-renders with trackBy271272### Streaming273274- Batch DOM updates during streaming275- Use `requestAnimationFrame` for smooth animations276- Avoid layout thrashing277278### Memory Management279280- Clean up subscriptions on destroy281- Limit stored message history282- Clear streaming buffers when complete283284---285> Converted and distributed by [TomeVault](https://tomevault.io/claim/hassantayyab) — claim your Tome and manage your conversions.286<!-- tomevault:4.0:skill_md:2026-04-11 -->