Skip to content

Commit 8892c3e

Browse files
authored
Merge pull request #24 from Respo/drawer
add drawer styles; refine README structure
2 parents 568c046 + 947a168 commit 8892c3e

File tree

7 files changed

+367
-40
lines changed

7 files changed

+367
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,82 @@
88
>
99
> Respo was initially designed to work in a dynamic language with persistent data and HMR(hot code replacement), which is dramatically different from Rust. So this is more like an experiment.
1010
11-
Docs https://docs.rs/respo
11+
- Docs https://docs.rs/respo
12+
- Live Demo https://r.tiye.me/Respo/respo.rs/
1213

1314
### Usage
1415

15-
A preview example, to delare a store:
16+
Here is some preview of DOM syntax:
17+
18+
```rust
19+
Ok(
20+
div()
21+
.class(ui_global())
22+
.add_style(RespoStyle::default().padding(12.0).to_owned())
23+
.add_children([
24+
comp_counter(&states.pick("counter"), store.counted)?,
25+
comp_panel(&states.pick("panel"))?,
26+
comp_todolist(memo_caches, &states.pick("todolist"), &store.tasks)?,
27+
])
28+
.to_owned(),
29+
)
30+
```
31+
32+
CSS-in-Rust:
33+
34+
```rust
35+
static_styles!(
36+
style_remove_button,
37+
(
38+
"$0".to_owned(),
39+
RespoStyle::default()
40+
.width(CssSize::Px(16.0))
41+
.height(CssSize::Px(16.0))
42+
.margin(4.)
43+
.cursor("pointer".to_owned())
44+
.margin4(0.0, 0.0, 0.0, 16.0)
45+
.color(CssColor::Hsl(0, 90, 90)),
46+
),
47+
("$0:hover".to_owned(), RespoStyle::default().color(CssColor::Hsl(0, 90, 80))),
48+
);
49+
```
50+
51+
Builtin styles, [demonstrated](http://ui.respo-mvc.org/):
52+
53+
| function | usages |
54+
| ------------------ | ------------------------------- |
55+
| `ui_global` | global styles |
56+
| `ui_fullscreen` | fullscreen styles |
57+
| `ui_button` | button styles |
58+
| `ui_input` | input styles |
59+
| `ui_textarea` | textarea styles |
60+
| `ui_link` | link styles |
61+
| `ui_flex` | `flex:1` styles |
62+
| `ui_expand` | `flex:1` styles with scrolls |
63+
| `ui_center` | flexbox center styles |
64+
| `ui_row` | flexbox row styles |
65+
| `ui_column` | flexbox column styles |
66+
| `ui_row_center` | flexbox row center styles |
67+
| `ui_column_center` | flexbox column center styles |
68+
| `ui_row_around` | flexbox row around styles |
69+
| `ui_column_around` | flexbox column around styles |
70+
| `ui_row_evenly` | flexbox row evenly styles |
71+
| `ui_column_evenly` | flexbox column evenly styles |
72+
| `ui_row_parted` | flexbox row between styles |
73+
| `ui_column_parted` | flexbox column between styles |
74+
| `ui_row_middle` | flexbox row between styles |
75+
| `ui_column_middle` | flexbox column between styles |
76+
| `ui_font_code` | code font family |
77+
| `ui_font_normal` | normal font family(Hind) |
78+
| `ui_font_fancy` | fancy font family(Josefin Sans) |
79+
80+
There are several dialog components in the demo. Syntax is not nice enough, so I'm not advertising it. But they work relatively good.
81+
82+
For more components, read code in `src/app/`, they are just variants like `RespoNode::Component(..)`. It may be sugared in the future, not determined yet.
83+
84+
### Store abstraction
85+
86+
Declaring a store:
1687

1788
```rust
1889
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -48,7 +119,7 @@ impl RespoStore for Store {
48119
}
49120
```
50121

51-
To declare an app:
122+
Declaring an app:
52123

53124
```rust
54125
struct App {
@@ -94,7 +165,7 @@ impl RespoApp for App {
94165
}
95166
```
96167

97-
mount app:
168+
Mounting app:
98169

99170
```rust
100171
let app = App {
@@ -110,27 +181,6 @@ let app = App {
110181
app.render_loop().expect("app render");
111182
```
112183

113-
CSS-in-Rust:
114-
115-
```rust
116-
static_styles!(
117-
style_remove_button,
118-
(
119-
"$0".to_owned(),
120-
RespoStyle::default()
121-
.width(CssSize::Px(16.0))
122-
.height(CssSize::Px(16.0))
123-
.margin(4.)
124-
.cursor("pointer".to_owned())
125-
.margin4(0.0, 0.0, 0.0, 16.0)
126-
.color(CssColor::Hsl(0, 90, 90)),
127-
),
128-
("$0:hover".to_owned(), RespoStyle::default().color(CssColor::Hsl(0, 90, 80))),
129-
);
130-
```
131-
132-
For components, read code in `src/app/`, they are just variants like `RespoNode::Component(..)`. It may be sugared in the future, not decided yet.
133-
134184
### License
135185

136186
Apache License 2.0 .

demo_respo/src/plugins.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::fmt::Debug;
22

3+
use respo::RespoEvent;
34
use respo::{space, ui::ui_row_parted, RespoStyle};
45
use serde::{Deserialize, Serialize};
56

67
use respo::{button, div, span, ui::ui_button, util, DispatchFn, RespoNode, StatesTree};
78

89
use respo::dialog::{
9-
AlertOptions, AlertPlugin, AlertPluginInterface, ConfirmOptions, ConfirmPlugin, ConfirmPluginInterface, ModalOptions, ModalPlugin,
10-
ModalPluginInterface, ModalRenderer, PromptOptions, PromptPlugin, PromptPluginInterface, PromptValidator,
10+
AlertOptions, AlertPlugin, AlertPluginInterface, ConfirmOptions, ConfirmPlugin, ConfirmPluginInterface, DrawerOptions, DrawerPlugin,
11+
DrawerPluginInterface, DrawerRenderer, ModalOptions, ModalPlugin, ModalPluginInterface, ModalRenderer, PromptOptions, PromptPlugin,
12+
PromptPluginInterface, PromptValidator,
1113
};
1214

1315
use super::store::*;
@@ -147,6 +149,48 @@ pub fn comp_plugins_demo(states: &StatesTree) -> Result<RespoNode<ActionOp>, Str
147149
}
148150
};
149151

152+
// declare drawer
153+
154+
let drawer_plugin = DrawerPlugin::new(
155+
states.pick("drawer"),
156+
DrawerOptions {
157+
title: Some(String::from("Modal demo")),
158+
render: DrawerRenderer::new(|close_drawer: _| {
159+
let handler = move |_e: _, dispatch: DispatchFn<ActionOp>| {
160+
respo::util::log!("on modal handle");
161+
close_drawer(dispatch)
162+
};
163+
Ok(
164+
div()
165+
.style(RespoStyle::default().padding(8.0).to_owned())
166+
.children([
167+
div()
168+
.children([span().inner_text("content in custom drawer").to_owned()])
169+
.to_owned(),
170+
div()
171+
.class(ui_row_parted())
172+
.children([span(), button().class(ui_button()).inner_text("close").on_click(handler).to_owned()])
173+
.to_owned(),
174+
])
175+
.to_owned(),
176+
)
177+
}),
178+
..DrawerOptions::default()
179+
},
180+
)?
181+
.share_with_ref();
182+
183+
let on_drawer = {
184+
let drawer_plugin = drawer_plugin.clone();
185+
move |e: RespoEvent, dispatch: DispatchFn<_>| -> Result<(), String> {
186+
util::log!("click {:?}", e);
187+
188+
drawer_plugin.show(dispatch)?;
189+
190+
Ok(())
191+
}
192+
};
193+
150194
Ok(
151195
div()
152196
.children([
@@ -168,12 +212,19 @@ pub fn comp_plugins_demo(states: &StatesTree) -> Result<RespoNode<ActionOp>, Str
168212
.inner_text("Try Custom Modal")
169213
.on_click(on_modal)
170214
.to_owned(),
215+
space(Some(8), None),
216+
button()
217+
.class(ui_button())
218+
.inner_text("Try Custom Drawer")
219+
.on_click(on_drawer)
220+
.to_owned(),
171221
])
172222
.to_owned(),
173223
alert_plugin.render()?,
174224
confirm_plugin.render()?,
175225
prompt_plugin.render()?,
176226
modal_plugin.render()?,
227+
drawer_plugin.render()?,
177228
])
178229
.to_owned(),
179230
)

respo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "respo"
3-
version = "0.0.14"
3+
version = "0.0.15"
44
edition = "2021"
55
description = "a tiny virtual DOM library migrated from ClojureScript"
66
license = "Apache-2.0"

respo/src/dialog.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
mod alert;
44
mod confirm;
5+
mod drawer;
56
mod modal;
67
mod prompt;
78

@@ -17,6 +18,7 @@ pub(crate) const BUTTON_NAME: &str = "dialog-button";
1718

1819
pub use alert::{AlertOptions, AlertPlugin, AlertPluginInterface};
1920
pub use confirm::{ConfirmOptions, ConfirmPlugin, ConfirmPluginInterface};
21+
pub use drawer::{DrawerOptions, DrawerPlugin, DrawerPluginInterface, DrawerRenderer};
2022
pub use modal::{ModalOptions, ModalPlugin, ModalPluginInterface, ModalRenderer};
2123
pub use prompt::{PromptOptions, PromptPlugin, PromptPluginInterface, PromptValidator};
2224

@@ -71,7 +73,7 @@ pub(crate) fn effect_fade(args: Vec<RespoEffectArg>, effect_type: RespoEffectTyp
7173
let card = cloned.first_child().unwrap();
7274
let card_style = card.dyn_ref::<HtmlElement>().unwrap().style();
7375
card_style.set_property("transition-duration", "240ms").unwrap();
74-
card_style.set_property("transform", "scale(0.94) translate(0px,-20px)").unwrap();
76+
card_style.set_property("transform", "translate(100%,0px)").unwrap();
7577
});
7678
window
7779
.set_timeout_with_callback_and_timeout_and_arguments_0(immediate_call.as_ref().unchecked_ref(), 10)
@@ -98,12 +100,12 @@ pub(crate) fn effect_fade(args: Vec<RespoEffectArg>, effect_type: RespoEffectTyp
98100
let style = target.dyn_ref::<HtmlElement>().unwrap().style();
99101
let card_style = target.first_child().unwrap().dyn_ref::<HtmlElement>().unwrap().style();
100102
style.set_property("opacity", "0").unwrap();
101-
card_style.set_property("transform", "scale(0.94)").unwrap();
103+
card_style.set_property("transform", "translate(100%, 0px)").unwrap();
102104
let call = Closure::once(move || {
103105
style.set_property("transition-duration", "240ms").unwrap();
104106
card_style.set_property("transition-duration", "240ms").unwrap();
105107
style.set_property("opacity", "1").unwrap();
106-
card_style.set_property("transform", "scale(1) translate(0px,0px)").unwrap();
108+
card_style.set_property("transform", "translate(0px,0px)").unwrap();
107109
});
108110
let window = web_sys::window().unwrap();
109111
window
@@ -126,7 +128,6 @@ static_styles!(
126128
.background_color(CssColor::Hsla(0.0, 30.0, 10.0, 0.6))
127129
.position(CssPosition::Fixed)
128130
.z_index(999)
129-
.padding(16.0)
130131
)
131132
);
132133

@@ -136,14 +137,17 @@ static_styles!(
136137
"$0".to_owned(),
137138
RespoStyle::default()
138139
.background_color(CssColor::Hsl(0, 0, 100))
139-
.max_width(CssSize::Px(600.0))
140-
.width(CssSize::Percent(100.))
141-
.max_height(CssSize::Vh(80.0))
140+
.max_width(CssSize::Vw(50.0))
141+
.width(CssSize::Px(400.))
142+
.height(CssSize::Vh(100.0))
142143
.overflow(CssOverflow::Auto)
143-
.border_radius(3.0)
144144
.color(CssColor::Hsl(0, 0, 0))
145-
.insert("margin", "auto".to_owned())
146-
.padding(16.0)
145+
.top(CssSize::Px(0.))
146+
.right(CssSize::Px(0.))
147+
.bottom(CssSize::Px(0.))
148+
.position(CssPosition::Absolute)
149+
.box_shadow(-2., 0., 12., 0., CssColor::Hsla(0., 0., 0., 0.2))
150+
.transform_property("transform, opacity".to_owned())
147151
)
148152
);
149153

0 commit comments

Comments
 (0)