Skip to main content

logicaffeine_web/ui/components/
input.rs

1//! Text input component for the REPL interface.
2//!
3//! Provides a styled text input with submit button for entering English sentences.
4//! Handles Enter key submission.
5//!
6//! # Props
7//!
8//! - `on_send` - Callback invoked with the input text when submitted
9
10use dioxus::prelude::*;
11
12/// Text input area with submit button.
13#[component]
14pub fn InputArea(on_send: EventHandler<String>) -> Element {
15    let mut text = use_signal(String::new);
16
17    let mut submit = move || {
18        let current_text = text.read().clone();
19        if !current_text.trim().is_empty() {
20            on_send.call(current_text);
21            text.set(String::new());
22        }
23    };
24
25    rsx! {
26        div { class: "input-area",
27            div { class: "input-row",
28                input {
29                    placeholder: "Type an English sentence...",
30                    value: "{text}",
31                    oninput: move |evt| text.set(evt.value()),
32                    onkeydown: move |evt| {
33                        if evt.key() == Key::Enter {
34                            submit();
35                        }
36                    }
37                }
38                button {
39                    onclick: move |_| submit(),
40                    "Transpile →"
41                }
42            }
43        }
44    }
45}