feat: with updated things

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-07-07 21:23:52 +02:00
parent 36e2766bb9
commit 8ee2ca5c14
21 changed files with 386 additions and 24 deletions

View File

@@ -0,0 +1,56 @@
use leptos::*;
#[derive(Clone, Debug)]
pub struct CommandLineState {
hidden: bool,
}
#[component]
pub fn CommandLineModalView(cx: Scope) -> impl IntoView {
view! { cx, <div>"modal"</div> }
}
#[component]
pub fn CommandLineModal(cx: Scope) -> impl IntoView {
let state =
use_context::<RwSignal<CommandLineState>>(cx).expect("command line state must be provided");
let (hidden, _) = create_slice(cx, state, |state| state.hidden, |state, n| state.hidden = n);
view! { cx,
{move || {
if !hidden.get() {
view! { cx, <CommandLineModalView/> }
} else {
view! { cx, }
}
}}
}
}
#[component]
pub fn CommandLine(cx: Scope, children: Children) -> impl IntoView {
let state = create_rw_signal(cx, CommandLineState { hidden: true });
provide_context(cx, state);
let (hidden, set_hidden) =
create_slice(cx, state, |state| state.hidden, |state, n| state.hidden = n);
leptos_dom::helpers::window_event_listener(ev::keypress, move |event| {
if event.ctrl_key() {
match event.code().as_str() {
"KeyK" => {
set_hidden(!hidden.get());
log!("toggle command")
}
_ => {}
}
}
});
view! { cx,
<div>
<div>{children(cx)}</div>
<CommandLineModal/>
</div>
}
}