use crate::impl_ssr_safe_method;
use crate::{UseDocument, use_document};
use cfg_if::cfg_if;
use std::ops::Deref;
#[cfg(not(feature = "ssr"))]
use leptos::prelude::*;
pub fn use_window() -> UseWindow {
cfg_if! { if #[cfg(feature = "ssr")] {
UseWindow(None)
} else {
UseWindow(Some(window()))
}}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UseWindow(Option<web_sys::Window>);
impl Deref for UseWindow {
type Target = Option<web_sys::Window>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl UseWindow {
impl_ssr_safe_method!(
navigator(&self) -> Option<web_sys::Navigator>
);
#[inline(always)]
pub fn document(&self) -> UseDocument {
use_document()
}
impl_ssr_safe_method!(
match_media(&self, query: &str) -> Result<Option<web_sys::MediaQueryList>, wasm_bindgen::JsValue>;
.unwrap_or(Ok(None))
);
}