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

Remove HotkeysProvider component from docs #81

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
69 changes: 37 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,14 @@ pub fn App() -> impl IntoView {
provide_hotkeys_context(main_ref, false, scopes!());

view! {
<HotkeysProvider>
<Router>
<main _ref=main_ref> // <-- attach main ref here!
<Routes>
<Route path="/" view=HomePage/>
<Route path="/:else" view=ErrorPage/>
</Routes>
</main>
</Router>
</HotkeysProvider>
<Router>
<main _ref=main_ref> // <-- attach main ref here!
<Routes>
<Route path="/" view=HomePage/>
<Route path="/:else" view=ErrorPage/>
</Routes>
</main>
</Router>
}
}
```
Expand All @@ -209,16 +207,22 @@ pub fn App() -> impl IntoView {
If you're using [scopes](#scoped-hotkeys), you can initialize with a specific scope.

```rust
use leptos_hotkeys::{scopes, HotkeysProvider};
use leptos_hotkeys::{provide_hotkeys_context, scopes};

view! {
<HotkeysProvider
initially_active_scopes=scopes!("some_scope_id")
>
#[component]
pub fn App() -> impl IntoView {
let main_ref = create_node_ref::<html::Main>();
provide_hotkeys_context(main_ref, false, scopes!("some_scope_id"));

view! {
<Router>
//... routes
<main _ref=main_ref>
<Routes>
// ... routes
</Routes>
</main>
</Router>
</HotkeysProvider>
}
}
```

Expand Down Expand Up @@ -287,14 +291,22 @@ Maybe you want to initialize a certain scope upon load, that's where the prop `i
Instead of having to create a `vec!["scope_name".to_string()]`, use the `scopes!()` macro.

```rust
use leptos_hotkeys::{scopes, HotkeysProvider};

view! {
<HotkeysProvider
initially_active_scopes=scopes!("scope_a", "settings_scope");
>
// pages here...
</HotkeysProvider>
use leptos_hotkeys::{provide_hotkeys_context, scopes};

#[component]
pub fn App() -> impl IntoView {
let main_ref = create_node_ref::<html::Main>();
provide_hotkeys_context(main_ref, false, scopes!("scope_a", "settings_scope"));

view! {
<Router>
<main _ref=main_ref>
<Routes>
// ... routes
</Routes>
</main>
</Router>
}
}
```

Expand All @@ -312,13 +324,6 @@ leptos_hotkeys = { path = "0.2.0-alpha.1", features = ["debug"] }

## API

### `<HotkeysProvider />`

| Prop Name | Type | Default Value | Description |
| ------------------------- | ----------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `allow_blur_event` | `bool` | `false` | Determines if the component should reset `pressed_keys` when a blur event occurs on the window. This is useful for resetting the state when the user navigates away from the window. |
| `initially_active_scopes` | `HashSet<String>` | `scopes!("*")` (Global State) | Specifies the set of scopes that are active when the component mounts. Useful for initializing the component with a predefined set of active hotkey scopes. |

### `HotkeysContext`

| Field Name | Type | Description |
Expand Down