From e8ad8c2cce5b51b55bddde3e251df2909d2ad280 Mon Sep 17 00:00:00 2001 From: Matthew Kim <38759997+friendlymatthew@users.noreply.github.com> Date: Thu, 2 May 2024 13:06:09 -0400 Subject: [PATCH] add hotkeys option --- examples/demo/src/app.rs | 2 +- examples/ssr-demo/src/app.rs | 4 ++-- leptos_hotkeys/src/context.rs | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/demo/src/app.rs b/examples/demo/src/app.rs index e527629..bba070b 100644 --- a/examples/demo/src/app.rs +++ b/examples/demo/src/app.rs @@ -20,7 +20,7 @@ pub fn Button(href: &'static str, children: Children) -> impl IntoView { pub fn App() -> impl IntoView { provide_meta_context(); let main_ref = create_node_ref::(); - provide_hotkeys_context(main_ref, false, scopes!("scope_a")); + provide_hotkeys_context(main_ref); view! { diff --git a/examples/ssr-demo/src/app.rs b/examples/ssr-demo/src/app.rs index 8fd3f05..166d8fc 100644 --- a/examples/ssr-demo/src/app.rs +++ b/examples/ssr-demo/src/app.rs @@ -1,7 +1,7 @@ use crate::error_template::{AppError, ErrorTemplate}; use leptos::*; use leptos_hotkeys::{ - provide_hotkeys_context, scopes, use_hotkeys, use_hotkeys_ref, HotkeysContext, + provide_hotkeys_context, use_hotkeys, use_hotkeys_ref, HotkeysContext, }; use leptos_meta::*; use leptos_router::*; @@ -13,7 +13,7 @@ pub fn App() -> impl IntoView { let main_ref = create_node_ref::(); - let HotkeysContext { .. } = provide_hotkeys_context(main_ref, false, scopes!()); + let HotkeysContext { .. } = provide_hotkeys_context(main_ref); view! { diff --git a/leptos_hotkeys/src/context.rs b/leptos_hotkeys/src/context.rs index f95e447..7bbb005 100644 --- a/leptos_hotkeys/src/context.rs +++ b/leptos_hotkeys/src/context.rs @@ -3,6 +3,7 @@ use leptos::*; use std::collections::HashSet; #[cfg(not(feature = "ssr"))] use wasm_bindgen::JsCast; +use crate::scopes; // Defining a hotkey context structure #[derive(Clone, Copy)] @@ -22,7 +23,17 @@ pub struct HotkeysContext { pub toggle_scope: Callback, } + pub fn provide_hotkeys_context( + #[cfg_attr(feature = "ssr", allow(unused_variables))] node_ref: NodeRef +) -> HotkeysContext +where +T: ElementDescriptor + 'static + Clone, +{ + provide_hotkeys_context_option(node_ref, false, scopes!()) +} + +fn provide_hotkeys_context_option( #[cfg_attr(feature = "ssr", allow(unused_variables))] node_ref: NodeRef, #[cfg_attr(feature = "ssr", allow(unused_variables))] allow_blur_event: bool, initially_active_scopes: HashSet,