Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hotkeys option #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/demo/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use leptos::*;
use leptos_hotkeys::{
provide_hotkeys_context, scopes, use_hotkeys, use_hotkeys_context, use_hotkeys_ref,

Check warning on line 3 in examples/demo/src/app.rs

View workflow job for this annotation

GitHub Actions / Build example (demo, trunk)

unused import: `scopes`

Check warning on line 3 in examples/demo/src/app.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `scopes`

Check warning on line 3 in examples/demo/src/app.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `scopes`
HotkeysContext,
};
use leptos_meta::*;
Expand All @@ -20,7 +20,7 @@
pub fn App() -> impl IntoView {
provide_meta_context();
let main_ref = create_node_ref::<html::Main>();
provide_hotkeys_context(main_ref, false, scopes!("scope_a"));
provide_hotkeys_context(main_ref);

view! {
<Stylesheet id="leptos" href="/pkg/demo.css"/>
Expand Down
4 changes: 2 additions & 2 deletions examples/ssr-demo/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error_template::{AppError, ErrorTemplate};

Check failure on line 1 in examples/ssr-demo/src/app.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/leptos-hotkeys/leptos-hotkeys/examples/ssr-demo/src/app.rs
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::*;
Expand All @@ -13,7 +13,7 @@

let main_ref = create_node_ref::<leptos::html::Main>();

let HotkeysContext { .. } = provide_hotkeys_context(main_ref, false, scopes!());
let HotkeysContext { .. } = provide_hotkeys_context(main_ref);

view! {
<Stylesheet id="leptos" href="/pkg/ssr-demo.css"/>
Expand Down
11 changes: 11 additions & 0 deletions leptos_hotkeys/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use leptos::html::ElementDescriptor;

Check failure on line 1 in leptos_hotkeys/src/context.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/leptos-hotkeys/leptos-hotkeys/leptos_hotkeys/src/context.rs
use leptos::*;
use std::collections::HashSet;
#[cfg(not(feature = "ssr"))]

Check failure on line 4 in leptos_hotkeys/src/context.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/leptos-hotkeys/leptos-hotkeys/leptos_hotkeys/src/context.rs
use wasm_bindgen::JsCast;
use crate::scopes;

// Defining a hotkey context structure
#[derive(Clone, Copy)]
Expand All @@ -19,10 +20,20 @@
pub active_scopes: RwSignal<HashSet<String>>,
pub enable_scope: Callback<String>,
pub disable_scope: Callback<String>,
pub toggle_scope: Callback<String>,

Check failure on line 23 in leptos_hotkeys/src/context.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/leptos-hotkeys/leptos-hotkeys/leptos_hotkeys/src/context.rs
}


pub fn provide_hotkeys_context<T>(
#[cfg_attr(feature = "ssr", allow(unused_variables))] node_ref: NodeRef<T>
) -> HotkeysContext
where
T: ElementDescriptor + 'static + Clone,
{
provide_hotkeys_context_option(node_ref, false, scopes!())
}

fn provide_hotkeys_context_option<T>(
#[cfg_attr(feature = "ssr", allow(unused_variables))] node_ref: NodeRef<T>,
#[cfg_attr(feature = "ssr", allow(unused_variables))] allow_blur_event: bool,
initially_active_scopes: HashSet<String>,
Expand Down
Loading