Skip to main content

glimmer_yew/
lib.rs

1//! The Glimmer library
2//!
3//! This library is a design system for Yew applications. It provides styled components commonly
4//! needed in the Visions UI application.
5pub mod adjustable_value_field;
6pub mod foundation;
7pub mod notebook;
8pub mod range;
9pub mod sidebar;
10pub mod theme_provider;
11
12pub mod prelude {
13    use std::{ops::Deref, rc::Rc};
14
15    use gloo_console::error;
16
17    pub use crate::adjustable_value_field::AdjustableValueField;
18    pub use crate::foundation::Orientation;
19    pub use crate::foundation::animations::ExpansionAnimation;
20    pub use crate::foundation::button::{self, Button, Toggle};
21    pub use crate::foundation::dialog::Dialog;
22    pub use crate::foundation::image::Image;
23    pub use crate::foundation::layout::{Centered, Row};
24    pub use crate::foundation::list::{List, ListItem, ListItemProps};
25    pub use crate::foundation::panel::Panel;
26    pub use crate::foundation::tabs::Tabs;
27    pub use crate::foundation::text_entry::TextEntry;
28    pub use crate::notebook::{self, NotebookView, Page, PageProps};
29    pub use crate::range::{self, DiscreteRange};
30    pub use crate::sidebar::{Sidebar, SidebarSide};
31
32    #[derive(Clone, Debug, Default, PartialEq)]
33    pub struct Prop<A>(Rc<A>);
34
35    impl<A> AsRef<A> for Prop<A> {
36        fn as_ref(&self) -> &A {
37            self.0.as_ref()
38        }
39    }
40
41    impl<A: Clone> Prop<A> {
42        #[must_use]
43        pub fn value(&self) -> A {
44            self.0.as_ref().clone()
45        }
46    }
47
48    impl<A> From<A> for Prop<A> {
49        fn from(value: A) -> Self {
50            Self(Rc::new(value))
51        }
52    }
53
54    impl<A> Deref for Prop<A> {
55        type Target = A;
56
57        fn deref(&self) -> &Self::Target {
58            self.0.as_ref()
59        }
60    }
61
62    pub fn navigate_to(path: &str) {
63        match web_sys::window() {
64            Some(window) => match window.location().set_pathname(path) {
65                Ok(()) => {}
66                Err(err) => {
67                    error!(format!("navigating to path failed: {:?}", err));
68                }
69            },
70            _ => {
71                error!("window cannot be retrieved");
72            }
73        }
74    }
75}