-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.rs
157 lines (128 loc) · 6.55 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#![recursion_limit = "4096"]
use yew::{classes, html, Component, Context, Html};
use yew_mdc_widgets::dom::existing::JsObjectAccess;
use yew_mdc_widgets::dom::{self};
use yew_mdc_widgets::{auto_init, drawer, Drawer, Element, IconButton, List, ListItem, MdcWidget, TopAppBar};
mod buttons;
mod cards;
mod checkboxes;
mod chips;
mod data_tables;
mod dialog;
mod fabs;
mod icon_buttons;
mod linear_progress;
mod lists;
mod menu;
mod radio_buttons;
mod snackbars;
mod switch;
mod tabs;
mod text_fields;
struct Root;
impl Component for Root {
type Message = ();
type Properties = ();
fn create(_ctx: &Context<Self>) -> Self {
Self
}
fn view(&self, _ctx: &Context<Self>) -> Html {
let contents = vec![
ListItem::link("#buttons").text("Buttons").tab_index(0),
ListItem::link("#icon_buttons").text("Icon buttons"),
ListItem::link("#fabs").text("Floating Action Buttons"),
ListItem::link("#checkboxes").text("Checkboxes"),
ListItem::link("#radio_buttons").text("Radio buttons"),
ListItem::link("#switch").text("Switch"),
ListItem::link("#chips").text("Chips"),
ListItem::link("#snackbars").text("Snackbars"),
ListItem::link("#linear_progress").text("LinearProgress"),
ListItem::link("#text_fields").text("Text fields"),
ListItem::link("#lists").text("Lists"),
ListItem::link("#menu").text("Menu"),
ListItem::link("#data_tables").text("Data tables"),
ListItem::link("#dialog").text("Dialog"),
ListItem::link("#tabs").text("Tabs"),
ListItem::link("#cards").text("Cards"),
];
let drawer = Drawer::new()
.id("app-drawer")
.title(html! { <h3 tabindex = 0>{ "Widgets" }</h3> })
.modal()
.content(
List::nav()
.items(contents.clone().into_iter().map(|item| {
item.on_click(|_| {
let drawer =
dom::existing::get_element_by_id::<Element>("app-drawer").get(drawer::mdc::TYPE_NAME);
drawer.set("open", false);
})
}))
.markup_only(),
);
let top_app_bar = TopAppBar::new()
.id("top-app-bar")
.title("Yew MDC Widgets")
.navigation_item(IconButton::new().icon("menu"))
.enable_shadow_when_scroll_window()
.on_navigation(|_| {
let drawer = dom::existing::get_element_by_id::<Element>("app-drawer").get(drawer::mdc::TYPE_NAME);
let opened = drawer.get("open").as_bool().unwrap_or(false);
drawer.set("open", !opened);
});
html! {
<>
{ drawer }
<div class = "mdc-drawer-scrim"></div>
<div class = { classes!("app-content", Drawer::APP_CONTENT_CLASS) }>
{ top_app_bar }
<div class = { TopAppBar::FIXED_ADJUST_CLASS }>
<div class = "demo-content">
<h1 class = "demo-title mdc-typography--headline5">{ "Material design components" }</h1>
{ List::nav().items(contents) }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "buttons"></a>{ "Buttons" }</h2>
{ buttons::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "icon_buttons"></a>{ "Icon buttons" }</h2>
{ icon_buttons::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "fabs"></a>{ "Floating Action Buttons" }</h2>
{ fabs::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "checkboxes"></a>{ "Checkboxes" }</h2>
{ checkboxes::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "radio_buttons"></a>{ "Radio buttons" }</h2>
{ radio_buttons::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "switch"></a>{ "Switch" }</h2>
{ switch::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "chips"></a>{ "Chips" }</h2>
{ chips::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "snackbars"></a>{ "Snackbars" }</h2>
{ snackbars::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "linear_progress"></a>{ "LinearProgress" }</h2>
{ linear_progress::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "text_fields"></a>{ "Text fields" }</h2>
{ text_fields::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "lists"></a>{ "Lists" }</h2>
{ lists::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "menu"></a>{ "Menu" }</h2>
{ menu::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "data_tables"></a>{ "Data tables" }</h2>
{ data_tables::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "dialog"></a>{ "Dialog" }</h2>
{ dialog::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "tabs"></a>{ "Tabs" }</h2>
{ tabs::view() }
<h2 class = "demo-title mdc-typography--headline6"><a href = "#" name = "cards"></a>{ "Cards" }</h2>
{ cards::view() }
</div>
</div>
</div>
</>
}
}
fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool) {
auto_init();
}
}
fn main() {
let root = dom::existing::get_element_by_id::<Element>("root");
yew::Renderer::<Root>::with_root(root).render();
}