hydroxy

Thread

A whole conversation: chat bubbles in a message scroller over a composer, with a typing indicator, streaming text, stop, and copy and retry on each message.

What are the main churn drivers in the Q3 interviews?
09:41
Three themes stand out: pricing surprises at renewal, skipped onboarding, and slow support on integrations.
q3-interviews.mdsupport-tickets.csv
09:41

Usage

use std::time::Duration;

use hydroxy_leptos::thread::{Action, Message, MessageRole, Thread};
use leptos::prelude::*;

const REPLY: &str = "Pricing came up in nine of the fourteen interviews, usually as a surprise at renewal rather than at sign-up. Onboarding was the second theme: people who skipped the setup call churned twice as often.";

pub fn demo() -> AnyView {
    let (messages, set_messages) = signal(vec![
        Message::new("m1", MessageRole::User, "What are the main churn drivers in the Q3 interviews?").time("09:41"),
        Message::new("m2", MessageRole::Assistant, "Three themes stand out: pricing surprises at renewal, skipped onboarding, and slow support on integrations.")
            .time("09:41")
            .sources(vec!["q3-interviews.md".to_string(), "support-tickets.csv".to_string()]),
    ]);
    let (streaming, set_streaming) = signal(false);
    // Each reply gets a number; Stop (or a newer reply) bumps it so the old timer ends.
    let run = StoredValue::new(0_u32);
    let next = StoredValue::new(3_u32);

    let reply = move || {
        run.update_value(|r| *r += 1);
        let mine = run.get_value();
        let id = format!("m{}", next.get_value());
        next.update_value(|n| *n += 1);
        set_streaming.set(true);
        let words: Vec<&str> = REPLY.split_inclusive(' ').collect();
        // A pause with the typing indicator, then one word at a time.
        set_timeout(
            move || {
                if run.try_get_value() != Some(mine) {
                    return;
                }
                set_messages.try_update(|m| m.push(Message::new(id.clone(), MessageRole::Assistant, "")));
                for (i, w) in words.iter().enumerate() {
                    let (word, id) = ((*w).to_string(), format!("m{}", next.try_get_value().unwrap_or(1) - 1));
                    let last = i == words.len() - 1;
                    set_timeout(
                        move || {
                            if run.try_get_value() != Some(mine) {
                                return;
                            }
                            set_messages.try_update(|m| {
                                if let Some(msg) = m.iter_mut().find(|m| m.id == id) {
                                    msg.text.push_str(&word);
                                }
                            });
                            if last {
                                set_streaming.try_set(false);
                            }
                        },
                        Duration::from_millis(60 * (i as u64 + 1)),
                    );
                }
            },
            Duration::from_millis(900),
        );
    };

    view! {
        <div style="height: 460px; max-width: 640px;">
            <Thread
                messages=messages
                streaming=streaming
                suggestions=vec!["What changed since August?".to_string()]
                on_send=move |text: String| {
                    let id = format!("u{}", next.get_value());
                    next.update_value(|n| *n += 1);
                    set_messages.update(|m| m.push(Message::new(id, MessageRole::User, text)));
                    reply();
                }
                on_stop=move |()| {
                    run.update_value(|r| *r += 1);
                    set_streaming.set(false);
                }
                on_action=move |(id, action): (String, Action)| {
                    if action == Action::Retry {
                        set_messages.update(|m| m.retain(|m| m.id != id));
                        reply();
                    }
                }
            />
        </div>
    }
    .into_any()
}

Anatomy

Componentdata-partRenders
ThreadrootColumn of scroller and composer. data-streaming while a reply streams
scrollerWraps the message scroller
messageOne message: bubble plus actions. data-role: user or assistant
textThe message text, line breaks kept
actionsCopy, and Retry on the last assistant message
typingThree dots while a reply is coming and has no text
stopStop button, shown while streaming when on_stop is set
composerThe Composer and the stop button

Keyboard

KeyDoes
EnterSends the message
Shift + EnterAdds a new line
TabMoves through the list, the actions, then the composer

Props

PropTypeNotes
messagesVec<ThreadMessage>Oldest first. A message has id, role, text, optional time and sources
streamingboolA reply is being written. Shows the typing indicator, then follows the text as it grows
on_sendCallback<String>Called with the trimmed text. You append the message
on_stopCallback<()>Stop button handler. The button shows only while streaming
on_actionCallback<(String, MessageAction)>Message id and Copy or Retry. Copy also writes to the clipboard
suggestionsVec<String>Tags above the composer
label / placeholder / emptyStringAccessible name, composer placeholder, empty text
Actions
Button
Icon button
Toolbar
Theme menu
Display
Avatar
Badge
Card
Chip
Code block
Markdown
Doc card
Due pill
Kbd
Priority mark
Source chip
Space icon
Status diamond
Tag
Value diff
Carousel
Reveal
Media timeline
QR code
Transcript viewer
Audio waveform
Audio player
Forms
Calendar
Checkbox
Combobox
Date picker
Color picker
Cron builder
Theme editor
Mention input
Signature pad
Image cropper
Date field
Date range picker
Duration field
Quantity stepper
Filter chip
Input
Markdown editor
Radio group
Search field
Segmented control
Select
Slider
Range slider
Rating
Toggle button
File dropzone
Upload queue
Attachment
Switch
Tags input
Number field
Money field
Phone field
Time field
OTP input
Password field
Questionnaire
Availability picker
Voice input
Recording control
Inline edit
Async validated input
Shortcut recorder
Data
Spreadsheet grid
Week scheduler
Virtual list
Stat card
Step track
Kanban board
Sortable list
Filter builder
Data table
Grid
Access editor
File manager
Gantt chart
Log stream
Diff viewer
JSON inspector
Terminal
Node editor
Whiteboard
Navigation
Table of contents
Breadcrumb
Tabs
Wizard
Nav item
Nav section
Tree view
Pagination
Menubar
Navigation menu
Saved views
Layout
Master detail
App shell
Sidebar layout
Resizable panels
Dashboard layout
Dock layout
Feedback
Callout
Check list
Empty state
Progress bar
Toast
Approval card
Skeleton
Notification center
Bars
Bar chart
Diverging bar chart
Span chart
Pictogram chart
Stacked bar chart
Funnel chart
Bullet chart
Waffle chart
Marimekko chart
Dot plot chart
Error bar chart
Pareto chart
Waterfall chart
Lollipop chart
Grouped bar chart
Bar race chart
KPIs and frames
Chart frame
Metric card
Sparkline
Points
Scatter chart
Smith chart
Strip plot
Beeswarm chart
Parallel coordinates
Ternary chart
Bland-Altman chart
Quiver chart
Connected scatter chart
Grids and tables
Heatmap chart
Chart table
Cohort chart
Radial
Radial charts
Radar chart
Polar area chart
Stat ring
Clock chart
Spiral chart
Lines and areas
Bump chart
Slope chart
Line chart
Composed chart
Small multiples
Cycle plot chart
Horizon chart
Stacked area chart
Threshold chart
Split line chart
Linked charts
Confidence band chart
Forecast fan chart
Step chart
Range area chart
Distributions
Contour chart
Histogram
Box plot
Density chart
Ridgeline chart
Violin chart
Q-Q chart
Survival chart
ECDF chart
Raincloud plot
Forest plot
Maps
Geo map
Bubble map
Hexbin map
Cartogram
Flow map
Parts of a whole
Donut chart
Voronoi treemap
Nested donut chart
Treemap chart
Sunburst chart
Bubble pack chart
Icicle chart
Flame graph chart
Pie chart
Word cloud
Relationships
Sankey chart
Network chart
Chord chart
UpSet chart
Venn chart
Alluvial chart
Adjacency matrix chart
Dependency graph chart
Tree chart
Arc diagram
Hive plot
Edge bundling
Finance
Candlestick chart
OHLC chart
Depth chart
Renko chart
Time
Timeline chart
Calendar heatmap chart
Spectrogram chart
Marey chart
Overlays
Tour
Lightbox
Alert dialog
Command palette
Dialog
Menu
Popover
Tooltip
Sheet
Hover card
Context menu
Utilities
Pacer
Hotkeys
Disclosure
Accordion
Collapsible
Chat
Chat bubble
Voice session
Composer
Thread
Thread list
Assistant composer
Assistant MCP
Assistant modal
Assistant thread
Assistant thread list
Message scroller
Insight note
Emoji picker
Tool trace
Model picker
Citation popover
Activity
Activity feed
Comment thread
Timeline
Presence bar
Live cursors
Reaction bar
Guides
Getting started
All components
All charts