leptos_bulma/
lib.rs

1use leptos::ev::{Event, MouseEvent};
2
3pub mod columns;
4pub mod components;
5pub mod elements;
6pub mod enums;
7pub mod form;
8pub mod layout;
9
10#[cfg(feature = "leptos-icons")]
11pub mod icons {
12    #[cfg(feature = "icondata-ai")]
13    pub use icondata_ai;
14
15    #[cfg(feature = "icondata-bi")]
16    pub use icondata_bi;
17
18    #[cfg(feature = "icondata-bs")]
19    pub use icondata_bs;
20
21    #[cfg(feature = "icondata-cg")]
22    pub use icondata_cg;
23
24    #[cfg(feature = "icondata-ch")]
25    pub use icondata_ch;
26
27    #[cfg(feature = "icondata-fa")]
28    pub use icondata_fa;
29
30    #[cfg(feature = "icondata-fi")]
31    pub use icondata_fi;
32
33    #[cfg(feature = "icondata-hi")]
34    pub use icondata_hi;
35
36    #[cfg(feature = "icondata-im")]
37    pub use icondata_im;
38
39    #[cfg(feature = "icondata-io")]
40    pub use icondata_io;
41
42    #[cfg(feature = "icondata-lu")]
43    pub use icondata_lu;
44
45    #[cfg(feature = "icondata-oc")]
46    pub use icondata_oc;
47
48    #[cfg(feature = "icondata-ri")]
49    pub use icondata_ri;
50
51    #[cfg(feature = "icondata-si")]
52    pub use icondata_si;
53
54    #[cfg(feature = "icondata-tb")]
55    pub use icondata_tb;
56
57    #[cfg(feature = "icondata-ti")]
58    pub use icondata_ti;
59
60    #[cfg(feature = "icondata-vs")]
61    pub use icondata_vs;
62
63    #[cfg(feature = "icondata-wi")]
64    pub use icondata_wi;
65}
66
67pub struct EventFn(Box<dyn Fn(Event) + 'static>);
68
69impl<T> From<T> for EventFn
70where
71    T: Fn(Event) + 'static,
72{
73    fn from(value: T) -> Self {
74        Self(Box::new(value))
75    }
76}
77
78impl EventFn {
79    pub fn into_inner(self) -> Box<dyn Fn(Event) + 'static> {
80        self.0
81    }
82}
83
84pub struct MouseEventFn(Box<dyn Fn(MouseEvent) + 'static>);
85
86impl<T> From<T> for MouseEventFn
87where
88    T: Fn(MouseEvent) + 'static,
89{
90    fn from(value: T) -> Self {
91        Self(Box::new(value))
92    }
93}
94
95impl MouseEventFn {
96    pub fn into_inner(self) -> Box<dyn Fn(MouseEvent) + 'static> {
97        self.0
98    }
99}
100
101#[cfg(feature = "build-script")]
102pub fn build<P: AsRef<std::path::Path>>(output_dir: P) {
103    use std::fs::{create_dir_all, read_to_string, File};
104    use std::io::Write;
105    use std::path::{Component, Path};
106    use std::process::Command;
107
108    let output_dir = output_dir.as_ref();
109    let output_path = output_dir.join("leptos-bulma.scss");
110    let main_scss_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("style/main.scss");
111
112    let _ = create_dir_all(output_dir);
113
114    let mut output_file = File::options()
115        .truncate(true)
116        .create(true)
117        .write(true)
118        .open(output_path)
119        .expect("Could not create output file");
120
121    Command::new("npm")
122        .args(["--prefix", "./target", "install", "bulma@1.0"])
123        .output()
124        .expect("Could not install Bulma");
125
126    let mut bulma_sass_prefix_dir = "".to_owned();
127
128    for _ in output_dir.components().filter(|c| c != &Component::CurDir) {
129        bulma_sass_prefix_dir += "../";
130    }
131
132    let use_bulma_sass = format!(
133        "@forward \"{}target/node_modules/bulma/sass\";\n\n",
134        bulma_sass_prefix_dir
135    );
136    let main_scss_content = read_to_string(main_scss_path).unwrap();
137    let output_file_content = use_bulma_sass + main_scss_content.as_str();
138
139    output_file
140        .write_all(output_file_content.as_bytes())
141        .expect("Could not write output file");
142}