-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91152a2
commit e99cf96
Showing
5 changed files
with
59 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod all_placements; | ||
pub mod new; | ||
pub mod use_size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use leptos::{create_signal, event_target_value, ReadSignal, WriteSignal}; | ||
use wasm_bindgen::closure::Closure; | ||
use web_sys::{js_sys::Reflect, window, Event}; | ||
|
||
pub fn use_size( | ||
initial_size: Option<i32>, | ||
key: Option<&'static str>, | ||
) -> (ReadSignal<i32>, WriteSignal<i32>) { | ||
let initial_size = initial_size.unwrap_or(80); | ||
let key = key.unwrap_or("floating"); | ||
|
||
let (size, set_size) = create_signal(initial_size); | ||
|
||
let closure: Closure<dyn Fn(Event)> = Closure::new(move |event: Event| { | ||
set_size(event_target_value(&event).parse().unwrap()); | ||
}); | ||
|
||
Reflect::set( | ||
&window().expect("Window should exist."), | ||
&format!("__handleSizeChange_{}", key).into(), | ||
&closure.into_js_value(), | ||
) | ||
.expect("Reflect set should be successful."); | ||
|
||
(size, set_size) | ||
} |