-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinterop.rs
60 lines (50 loc) · 1.91 KB
/
interop.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
use crate::static_url::static_url;
use js_sys::{Object, Reflect};
use wasm_bindgen::{prelude::*, JsValue};
use web_sys::{HtmlCanvasElement, HtmlImageElement};
use yew_interop::declare_resources;
declare_resources!(
toast
"https://cdn.jsdelivr.net/npm/[email protected]/src/toastify.min.js"
"https://cdn.jsdelivr.net/npm/[email protected]/src/toastify.min.css"
cropper
"https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.12/cropper.min.js"
"https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.12/cropper.min.css"
! blessings
static_url!("blessings.js")
! social_media_buttons
"https://cdn.jsdelivr.net/npm/[email protected]/dist/share-buttons.min.js"
);
// The javascript API: https://github.com/apvarun/toastify-js/blob/572517040fae6a7f8be4a99778dacda9c933db45/README.md
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = Toastify)]
pub type Toast;
#[wasm_bindgen(constructor, js_class = "Toastify")]
pub fn new(config: &JsValue) -> Toast;
#[wasm_bindgen(method, structural, js_class = "Toastify", js_name = showToast)]
pub fn show_toast(this: &Toast);
}
pub fn show_congrats_toast() {
let config = Object::new();
Reflect::set(
&config,
&"text".into(),
&"Yew is awesome!".to_string().into(),
)
.ok();
let toast = Toast::new(&config);
toast.show_toast();
}
// The javascript API: https://www.npmjs.com/package/cropperjs/v/1.5.12
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = Cropper)]
pub type Cropper;
#[wasm_bindgen(constructor, js_class = "Cropper")]
pub fn new(image: &HtmlImageElement, options: &JsValue) -> Cropper;
#[wasm_bindgen(method, structural, js_class = "Cropper", js_name = destroy)]
pub fn destroy(this: &Cropper);
#[wasm_bindgen(method, structural, js_class = "Cropper", js_name = getCroppedCanvas)]
pub fn get_cropped_canvas(this: &Cropper) -> HtmlCanvasElement;
}