From 7d60ac14746a6fc99f354e7630bf30dc82d07f15 Mon Sep 17 00:00:00 2001 From: Yota <91780796+wiyota@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:10:17 +0900 Subject: [PATCH 01/26] Update icondata (#82) * Update icondata * merge upstream * feat: update icondata --------- Co-authored-by: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Co-authored-by: luoxiao --- demo/Cargo.toml | 11 ++--------- demo/src/components/site_header.rs | 6 +++--- demo/src/pages/nav_bar/mod.rs | 2 +- demo/src/pages/tabbar/mod.rs | 2 +- demo_markdown/docs/_mobile/nav_bar/mod.md | 2 +- demo_markdown/docs/_mobile/tabbar/mod.md | 2 +- demo_markdown/docs/auto_complete/mod.md | 4 ++-- demo_markdown/docs/button/mod.md | 8 ++++---- demo_markdown/docs/icon/mod.md | 4 ++-- demo_markdown/docs/input/mod.md | 6 +++--- thaw/Cargo.toml | 20 ++------------------ thaw/src/alert/mod.rs | 7 +++---- thaw/src/button/mod.rs | 2 +- thaw/src/calendar/mod.rs | 5 ++--- thaw/src/checkbox/mod.rs | 3 +-- thaw/src/collapse/collapse_item.rs | 3 +-- thaw/src/date_picker/mod.rs | 4 ++-- thaw/src/date_picker/panel/date_panel.rs | 10 +++++----- thaw/src/date_picker/panel/month_panel.rs | 6 +++--- thaw/src/date_picker/panel/year_panel.rs | 6 +++--- thaw/src/icon/mod.rs | 6 ++---- thaw/src/input_number/mod.rs | 6 +++--- thaw/src/message/mod.rs | 9 ++++----- thaw/src/mobile/nav_bar/mod.rs | 2 +- thaw/src/modal/mod.rs | 2 +- thaw/src/time_picker/mod.rs | 4 ++-- 26 files changed, 56 insertions(+), 86 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 9cd1532e..28678257 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -12,14 +12,7 @@ leptos_meta = { version = "0.5.7" } leptos_router = { version = "0.5.7" } leptos_devtools = { version = "0.0.1", optional = true} thaw = { path = "../thaw", default-features = false } -icondata = { version = "0.1.0", features = [ - "AiCloseOutlined", - "AiCheckOutlined", - "AiGithubOutlined", - "AiUserOutlined", - "AiSearchOutlined", - "AiUnorderedListOutlined" -] } +icondata = "0.3.0" demo_markdown = { path = "../demo_markdown" } [features] @@ -41,4 +34,4 @@ nightly = ["leptos/nightly", "leptos_meta/nightly", "leptos_router/nightly"] opt-level = 1 [profile.dev.package."*"] -opt-level = 3 \ No newline at end of file +opt-level = 3 diff --git a/demo/src/components/site_header.rs b/demo/src/components/site_header.rs index dacbb757..730c869e 100644 --- a/demo/src/components/site_header.rs +++ b/demo/src/components/site_header.rs @@ -141,14 +141,14 @@ pub fn SiteHeader() -> impl IntoView { comp_ref=auto_complete_ref > - + diff --git a/thaw/src/message/mod.rs b/thaw/src/message/mod.rs index 1ea50eee..02cc741b 100644 --- a/thaw/src/message/mod.rs +++ b/thaw/src/message/mod.rs @@ -3,7 +3,6 @@ mod message_provider; mod theme; use crate::{theme::use_theme, Icon, Theme, components::{If, Then}}; -use icondata::*; use leptos::*; use uuid::Uuid; pub use message_provider::*; @@ -20,9 +19,9 @@ pub enum MessageVariant { impl MessageVariant { fn icon(&self) -> Icon { match self { - MessageVariant::Success => icondata::Icon::Ai(AiCloseCircleFilled), - MessageVariant::Warning => icondata::Icon::Ai(AiExclamationCircleFilled), - MessageVariant::Error => icondata::Icon::Ai(AiCheckCircleFilled), + MessageVariant::Success => icondata::AiCloseCircleFilled, + MessageVariant::Warning => icondata::AiExclamationCircleFilled, + MessageVariant::Error => icondata::AiCheckCircleFilled, } } fn theme_color(&self, theme: &Theme) -> String { @@ -64,7 +63,7 @@ pub(crate) fn Message(
- +
diff --git a/thaw/src/mobile/nav_bar/mod.rs b/thaw/src/mobile/nav_bar/mod.rs index f28a4312..163eee4f 100644 --- a/thaw/src/mobile/nav_bar/mod.rs +++ b/thaw/src/mobile/nav_bar/mod.rs @@ -78,7 +78,7 @@ pub fn NavBar(
- + {move || left_text.get()} diff --git a/thaw/src/modal/mod.rs b/thaw/src/modal/mod.rs index 6daa285e..f679931c 100644 --- a/thaw/src/modal/mod.rs +++ b/thaw/src/modal/mod.rs @@ -35,7 +35,7 @@ pub fn Modal( - + {children()} diff --git a/thaw/src/time_picker/mod.rs b/thaw/src/time_picker/mod.rs index fb80152e..5350d54f 100644 --- a/thaw/src/time_picker/mod.rs +++ b/thaw/src/time_picker/mod.rs @@ -5,7 +5,7 @@ use crate::{ components::{Binder, Follower, FollowerPlacement}, use_theme, utils::{mount_style, ComponentRef}, - AiIcon, Button, ButtonSize, ButtonVariant, Icon, Input, InputSuffix, SignalWatch, Theme, + Button, ButtonSize, ButtonVariant, Icon, Input, InputSuffix, SignalWatch, Theme, }; use leptos::*; pub use theme::TimePickerTheme; @@ -77,7 +77,7 @@ pub fn TimePicker( From fc60bea4e05730b12c59d3520c3ad5e44b0c6bca Mon Sep 17 00:00:00 2001 From: luoxiao Date: Fri, 26 Jan 2024 23:26:56 +0800 Subject: [PATCH 02/26] feat: sync upstream Icon --- demo/Cargo.toml | 1 - demo/src/pages/nav_bar/mod.rs | 2 +- demo/src/pages/tabbar/mod.rs | 5 +++- thaw/Cargo.toml | 1 - thaw/src/button/mod.rs | 4 ++-- thaw/src/icon/mod.rs | 33 ++++++++++++--------------- thaw/src/lib.rs | 1 + thaw/src/message/mod.rs | 2 +- thaw/src/mobile/tabbar/tabbar_item.rs | 4 ++-- 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 28678257..abbc8e79 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -12,7 +12,6 @@ leptos_meta = { version = "0.5.7" } leptos_router = { version = "0.5.7" } leptos_devtools = { version = "0.0.1", optional = true} thaw = { path = "../thaw", default-features = false } -icondata = "0.3.0" demo_markdown = { path = "../demo_markdown" } [features] diff --git a/demo/src/pages/nav_bar/mod.rs b/demo/src/pages/nav_bar/mod.rs index 79709a72..222fef5d 100644 --- a/demo/src/pages/nav_bar/mod.rs +++ b/demo/src/pages/nav_bar/mod.rs @@ -2,7 +2,7 @@ use super::NavBarMdPage; use crate::pages::MobilePage; use leptos::*; use thaw::mobile::{NavBar, NavBarRight}; -use thaw::Icon; +use thaw::{icondata, Icon}; #[component] pub fn NavBarPage() -> impl IntoView { diff --git a/demo/src/pages/tabbar/mod.rs b/demo/src/pages/tabbar/mod.rs index 73302653..657f36db 100644 --- a/demo/src/pages/tabbar/mod.rs +++ b/demo/src/pages/tabbar/mod.rs @@ -1,7 +1,10 @@ use super::TabbarMdPage; use crate::pages::MobilePage; use leptos::*; -use thaw::mobile::{Tabbar, TabbarItem}; +use thaw::{ + icondata, + mobile::{Tabbar, TabbarItem}, +}; #[component] pub fn TabbarPage() -> impl IntoView { diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index 7cbe69a8..e973be85 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -23,7 +23,6 @@ web-sys = { version = "0.3.63", features = [ ] } wasm-bindgen = "0.2.89" icondata = "0.3.0" -icondata_core = "0.1.0" uuid = { version = "1.5.0", features = ["v4"] } cfg-if = "1.0.0" chrono = "0.4.31" diff --git a/thaw/src/button/mod.rs b/thaw/src/button/mod.rs index c4c776aa..af140eb8 100644 --- a/thaw/src/button/mod.rs +++ b/thaw/src/button/mod.rs @@ -3,7 +3,7 @@ mod theme; use crate::{ components::{OptionComp, Wave, WaveRef}, - icon::*, + icon::Icon, theme::*, utils::{class_list::class_list, mount_style, ComponentRef}, }; @@ -104,7 +104,7 @@ pub fn Button( #[prop(optional, into)] size: MaybeSignal, #[prop(optional, into)] round: MaybeSignal, #[prop(optional, into)] circle: MaybeSignal, - #[prop(optional, into)] icon: Option, + #[prop(optional, into)] icon: Option, #[prop(optional, into)] loading: MaybeSignal, #[prop(optional, into)] disabled: MaybeSignal, #[prop(optional, into)] on_click: Option>, diff --git a/thaw/src/icon/mod.rs b/thaw/src/icon/mod.rs index a11bb11c..4ef5c49c 100644 --- a/thaw/src/icon/mod.rs +++ b/thaw/src/icon/mod.rs @@ -1,14 +1,13 @@ // copy https://github.com/Carlosted/leptos-icons // leptos updated version causes leptos_icons error -pub(crate) use icondata::Icon; use leptos::*; /// The Icon component. #[component] pub fn Icon( - /// The icon to show. + /// The icon to render. #[prop(into)] - icon: MaybeSignal, + icon: MaybeSignal, /// The width of the icon (horizontal side length of the square surrounding the icon). Defaults to "1em". #[prop(into, optional)] width: Option>, @@ -25,12 +24,12 @@ pub fn Icon( let svg = move || { let icon = icon.get(); let mut svg = svg::svg(); - if let Some(classes) = class.clone() { - svg = svg.classes(classes.get()); + if let Some(class) = class.clone() { + svg = svg.attr("class", move || class.get()) } let mut svg = match (style.clone(), icon.style) { - (Some(a), Some(b)) => svg.attr("style", format!("{b} {}", a.get())), - (Some(a), None) => svg.attr("style", a.get()), + (Some(a), Some(b)) => svg.attr("style", move || format!("{b} {}", a.get())), + (Some(a), None) => svg.attr("style", move || a.get()), (None, Some(b)) => svg.attr("style", b), (None, None) => svg, }; @@ -45,21 +44,17 @@ pub fn Icon( // We ignore the width and height attributes of the icon, even if the user hasn't specified any. svg = svg.attr( "width", - Attribute::String(match (width.clone(), icon.width) { - (Some(a), Some(_b)) => Oco::from(a.get()), - (Some(a), None) => Oco::from(a.get()), - (None, Some(_b)) => Oco::from("1em"), - (None, None) => Oco::from("1em"), - }), + match (width.clone(), icon.width) { + (Some(a), _) => (move || a.get()).into_attribute(), + _ => "1em".into_attribute(), + }, ); svg = svg.attr( "height", - Attribute::String(match (height.clone(), icon.height) { - (Some(a), Some(_b)) => Oco::from(a.get()), - (Some(a), None) => Oco::from(a.get()), - (None, Some(_b)) => Oco::from("1em"), - (None, None) => Oco::from("1em"), - }), + match (height.clone(), icon.height) { + (Some(a), _) => (move || a.get()).into_attribute(), + _ => "1em".into_attribute(), + }, ); if let Some(view_box) = icon.view_box { svg = svg.attr("viewBox", view_box); diff --git a/thaw/src/lib.rs b/thaw/src/lib.rs index f2023ef7..cce89206 100644 --- a/thaw/src/lib.rs +++ b/thaw/src/lib.rs @@ -63,6 +63,7 @@ pub use drawer::*; pub use global_style::*; pub use grid::*; pub use icon::*; +pub use icondata; pub use image::*; pub use input::*; pub use input_number::*; diff --git a/thaw/src/message/mod.rs b/thaw/src/message/mod.rs index 02cc741b..fdcf0258 100644 --- a/thaw/src/message/mod.rs +++ b/thaw/src/message/mod.rs @@ -17,7 +17,7 @@ pub enum MessageVariant { } impl MessageVariant { - fn icon(&self) -> Icon { + fn icon(&self) -> icondata::Icon { match self { MessageVariant::Success => icondata::AiCloseCircleFilled, MessageVariant::Warning => icondata::AiExclamationCircleFilled, diff --git a/thaw/src/mobile/tabbar/tabbar_item.rs b/thaw/src/mobile/tabbar/tabbar_item.rs index ed4f06f3..02f5d461 100644 --- a/thaw/src/mobile/tabbar/tabbar_item.rs +++ b/thaw/src/mobile/tabbar/tabbar_item.rs @@ -1,13 +1,13 @@ use super::use_tabbar; use crate::components::*; use crate::utils::StoredMaybeSignal; -use crate::{icon::*, theme::use_theme, utils::mount_style, Theme}; +use crate::{icon::Icon, theme::use_theme, utils::mount_style, Theme}; use leptos::*; #[component] pub fn TabbarItem( #[prop(into)] key: MaybeSignal, - #[prop(optional, into)] icon: Option, + #[prop(optional, into)] icon: Option, children: Children, ) -> impl IntoView { mount_style("tabbar-item", include_str!("./tabbar-item.css")); From bf98313f35c5ebe38554888074702aaba846dd83 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Sat, 27 Jan 2024 00:06:07 +0800 Subject: [PATCH 03/26] feat: update dependencies and update leptos to v0.6.0-rc1 --- demo/Cargo.toml | 6 +-- demo_markdown/Cargo.toml | 8 ++-- demo_markdown/src/markdown/mod.rs | 1 + examples/ssr_axum/Cargo.toml | 20 ++++----- examples/ssr_axum/src/fileserv.rs | 72 ++++++++++++++++--------------- examples/ssr_axum/src/lib.rs | 21 ++++----- examples/ssr_axum/src/main.rs | 4 +- thaw/Cargo.toml | 12 +++--- 8 files changed, 72 insertions(+), 72 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index abbc8e79..de1810de 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -7,9 +7,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.5.7" } -leptos_meta = { version = "0.5.7" } -leptos_router = { version = "0.5.7" } +leptos = { version = "0.6.0-rc1" } +leptos_meta = { version = "0.6.0-rc1" } +leptos_router = { version = "0.6.0-rc1" } leptos_devtools = { version = "0.0.1", optional = true} thaw = { path = "../thaw", default-features = false } demo_markdown = { path = "../demo_markdown" } diff --git a/demo_markdown/Cargo.toml b/demo_markdown/Cargo.toml index b9e5a59d..34173da9 100644 --- a/demo_markdown/Cargo.toml +++ b/demo_markdown/Cargo.toml @@ -10,8 +10,8 @@ edition = "2021" proc-macro = true [dependencies] -quote = "1.0.33" -comrak = "0.20.0" -proc-macro2 = "1.0.71" -syn = "2.0.43" +quote = "1.0.35" +comrak = "0.21.0" +proc-macro2 = "1.0.78" +syn = "2.0.48" syntect = "5.1.0" \ No newline at end of file diff --git a/demo_markdown/src/markdown/mod.rs b/demo_markdown/src/markdown/mod.rs index 8e77e9b2..0379fc43 100644 --- a/demo_markdown/src/markdown/mod.rs +++ b/demo_markdown/src/markdown/mod.rs @@ -145,5 +145,6 @@ fn iter_nodes<'a>(node: &'a AstNode<'a>, demos: &mut Vec) -> TokenStream NodeValue::Link(_) => quote!("Link todo!!!"), NodeValue::Image(_) => quote!("Image todo!!!"), NodeValue::FootnoteReference(_) => quote!("FootnoteReference todo!!!"), + NodeValue::MultilineBlockQuote(_) => quote!("FootnoteReference todo!!!"), } } diff --git a/examples/ssr_axum/Cargo.toml b/examples/ssr_axum/Cargo.toml index cb2800da..6f861923 100644 --- a/examples/ssr_axum/Cargo.toml +++ b/examples/ssr_axum/Cargo.toml @@ -7,22 +7,22 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -axum = { version = "0.6.4", optional = true } +axum = { version = "0.7.4", optional = true } console_error_panic_hook = "0.1" console_log = "1" cfg-if = "1" -leptos = { version = "0.5" } -leptos_axum = { version = "0.5", optional = true } -leptos_meta = { version = "0.5" } -leptos_router = { version = "0.5" } +leptos = { version = "0.6.0-rc1" } +leptos_axum = { version = "0.6.0-rc1", optional = true } +leptos_meta = { version = "0.6.0-rc1" } +leptos_router = { version = "0.6.0-rc1" } log = "0.4" simple_logger = "4" -tokio = { version = "1.25.0", optional = true } +tokio = { version = "1.35.1", features = ["rt-multi-thread"], optional = true } tower = { version = "0.4.13", optional = true } -tower-http = { version = "0.4", features = ["fs"], optional = true } -wasm-bindgen = "=0.2.89" -thiserror = "1.0.38" -tracing = { version = "0.1.37", optional = true } +tower-http = { version = "0.5.1", features = ["fs"], optional = true } +wasm-bindgen = "=0.2.90" +thiserror = "1.0.56" +tracing = { version = "0.1.40", optional = true } http = "0.2.8" demo = { path = "../../demo", default-features = false } diff --git a/examples/ssr_axum/src/fileserv.rs b/examples/ssr_axum/src/fileserv.rs index eef7b716..a71b53a2 100644 --- a/examples/ssr_axum/src/fileserv.rs +++ b/examples/ssr_axum/src/fileserv.rs @@ -1,40 +1,42 @@ -use cfg_if::cfg_if; +use axum::{ + body::Body, + extract::State, + http::{Request, Response, StatusCode, Uri}, + response::{IntoResponse, Response as AxumResponse}, +}; +use demo::App; +use leptos::{view, LeptosOptions}; +use tower::ServiceExt; +use tower_http::services::ServeDir; -cfg_if! { if #[cfg(feature = "ssr")] { - use axum::{ - body::{boxed, Body, BoxBody}, - extract::State, - response::IntoResponse, - http::{Request, Response, StatusCode, Uri}, - }; - use axum::response::Response as AxumResponse; - use tower::ServiceExt; - use tower_http::services::ServeDir; - use leptos::*; - use demo::App; +pub async fn file_and_error_handler( + uri: Uri, + State(options): State, + req: Request, +) -> AxumResponse { + let root = options.site_root.clone(); + let res = get_static_file(uri.clone(), &root).await.unwrap(); - pub async fn file_and_error_handler(uri: Uri, State(options): State, req: Request) -> AxumResponse { - let root = options.site_root.clone(); - let res = get_static_file(uri.clone(), &root).await.unwrap(); - - if res.status() == StatusCode::OK { - res.into_response() - } else { - let handler = leptos_axum::render_app_to_stream(options.to_owned(), move || view!{}); - handler(req).await.into_response() - } + if res.status() == StatusCode::OK { + res.into_response() + } else { + let handler = leptos_axum::render_app_to_stream(options.to_owned(), move || view! {}); + handler(req).await.into_response() } +} - async fn get_static_file(uri: Uri, root: &str) -> Result, (StatusCode, String)> { - let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap(); - // `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot` - // This path is relative to the cargo root - match ServeDir::new(root).oneshot(req).await { - Ok(res) => Ok(res.map(boxed)), - Err(err) => Err(( - StatusCode::INTERNAL_SERVER_ERROR, - format!("Something went wrong: {err}"), - )), - } +async fn get_static_file(uri: Uri, root: &str) -> Result, (StatusCode, String)> { + let req = Request::builder() + .uri(uri.clone()) + .body(Body::empty()) + .unwrap(); + // `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot` + // This path is relative to the cargo root + match ServeDir::new(root).oneshot(req).await { + Ok(res) => Ok(res.into_response()), + Err(err) => Err(( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Something went wrong: {err}"), + )), } -}} +} diff --git a/examples/ssr_axum/src/lib.rs b/examples/ssr_axum/src/lib.rs index 1bae92b5..a1249d74 100644 --- a/examples/ssr_axum/src/lib.rs +++ b/examples/ssr_axum/src/lib.rs @@ -1,17 +1,14 @@ -use cfg_if::cfg_if; +#[cfg(feature = "ssr")] pub mod fileserv; -cfg_if! { if #[cfg(feature = "hydrate")] { - use leptos::*; - use wasm_bindgen::prelude::wasm_bindgen; +#[cfg(feature = "hydrate")] +#[wasm_bindgen::prelude::wasm_bindgen] +pub fn hydrate() { use demo::App; - #[wasm_bindgen] - pub fn hydrate() { - // initializes logging using the `log` crate - _ = console_log::init_with_level(log::Level::Debug); - console_error_panic_hook::set_once(); + // initializes logging using the `log` crate + _ = console_log::init_with_level(log::Level::Debug); + console_error_panic_hook::set_once(); - leptos::mount_to_body(App); - } -}} + leptos::mount_to_body(App); +} diff --git a/examples/ssr_axum/src/main.rs b/examples/ssr_axum/src/main.rs index 82224181..3647ee9b 100644 --- a/examples/ssr_axum/src/main.rs +++ b/examples/ssr_axum/src/main.rs @@ -29,8 +29,8 @@ async fn main() { // run our app with hyper // `axum::Server` is a re-export of `hyper::Server` log::info!("listening on http://{}", &addr); - axum::Server::bind(&addr) - .serve(app.into_make_service()) + let listener = tokio::net::TcpListener::bind(&addr).await.unwrap(); + axum::serve(listener, app.into_make_service()) .await .unwrap(); } diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index e973be85..77efb5f8 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -13,19 +13,19 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.5.7" } -leptos_meta = { version = "0.5.7", optional = true } -web-sys = { version = "0.3.63", features = [ +leptos = { version = "0.6.0-rc1" } +leptos_meta = { version = "0.6.0-rc1", optional = true } +web-sys = { version = "0.3.67", features = [ "DomRect", "File", "FileList", "DataTransfer", ] } -wasm-bindgen = "0.2.89" +wasm-bindgen = "0.2.90" icondata = "0.3.0" -uuid = { version = "1.5.0", features = ["v4"] } +uuid = { version = "1.7.0", features = ["v4"] } cfg-if = "1.0.0" -chrono = "0.4.31" +chrono = "0.4.33" [features] default = ["csr"] From e73a4095f3dd210bea9324ab9a3d8e707ec18666 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Sat, 27 Jan 2024 00:12:03 +0800 Subject: [PATCH 04/26] feat: remove the default feature of csr --- demo/Cargo.toml | 2 +- thaw/Cargo.toml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index de1810de..2dfc2ffd 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -11,7 +11,7 @@ leptos = { version = "0.6.0-rc1" } leptos_meta = { version = "0.6.0-rc1" } leptos_router = { version = "0.6.0-rc1" } leptos_devtools = { version = "0.0.1", optional = true} -thaw = { path = "../thaw", default-features = false } +thaw = { path = "../thaw" } demo_markdown = { path = "../demo_markdown" } [features] diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index 77efb5f8..4b941779 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -28,7 +28,6 @@ cfg-if = "1.0.0" chrono = "0.4.33" [features] -default = ["csr"] csr = ["leptos/csr"] ssr = ["leptos/ssr", "leptos_meta/ssr"] hydrate = ["leptos/hydrate"] From 6f5414d3a4053426efcdef836b4e884a02bdafd5 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Mon, 29 Jan 2024 09:48:42 +0800 Subject: [PATCH 05/26] feat: update leptos to v0.6.3 --- demo/Cargo.toml | 6 +++--- examples/ssr_axum/Cargo.toml | 8 ++++---- thaw/Cargo.toml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 2dfc2ffd..1b613a96 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -7,9 +7,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.6.0-rc1" } -leptos_meta = { version = "0.6.0-rc1" } -leptos_router = { version = "0.6.0-rc1" } +leptos = { version = "0.6.3" } +leptos_meta = { version = "0.6.3" } +leptos_router = { version = "0.6.3" } leptos_devtools = { version = "0.0.1", optional = true} thaw = { path = "../thaw" } demo_markdown = { path = "../demo_markdown" } diff --git a/examples/ssr_axum/Cargo.toml b/examples/ssr_axum/Cargo.toml index 6f861923..e545a414 100644 --- a/examples/ssr_axum/Cargo.toml +++ b/examples/ssr_axum/Cargo.toml @@ -11,10 +11,10 @@ axum = { version = "0.7.4", optional = true } console_error_panic_hook = "0.1" console_log = "1" cfg-if = "1" -leptos = { version = "0.6.0-rc1" } -leptos_axum = { version = "0.6.0-rc1", optional = true } -leptos_meta = { version = "0.6.0-rc1" } -leptos_router = { version = "0.6.0-rc1" } +leptos = { version = "0.6.3" } +leptos_axum = { version = "0.6.3", optional = true } +leptos_meta = { version = "0.6.3" } +leptos_router = { version = "0.6.3" } log = "0.4" simple_logger = "4" tokio = { version = "1.35.1", features = ["rt-multi-thread"], optional = true } diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index 4b941779..5c6e75f8 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -13,8 +13,8 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.6.0-rc1" } -leptos_meta = { version = "0.6.0-rc1", optional = true } +leptos = { version = "0.6.3" } +leptos_meta = { version = "0.6.3", optional = true } web-sys = { version = "0.3.67", features = [ "DomRect", "File", From 194387c520c71451a0485f98aa8152c0ac896139 Mon Sep 17 00:00:00 2001 From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Date: Mon, 29 Jan 2024 10:57:55 +0800 Subject: [PATCH 06/26] Feat/model (#92) * feat: add Model * feat: RwSignal is migrated to Model --- thaw/src/auto_complete/mod.rs | 4 +- thaw/src/calendar/mod.rs | 6 +- thaw/src/checkbox/checkbox_group.rs | 5 +- thaw/src/checkbox/mod.rs | 6 +- thaw/src/collapse/mod.rs | 6 +- thaw/src/color_picker/mod.rs | 4 +- thaw/src/date_picker/mod.rs | 4 +- thaw/src/drawer/mod.rs | 4 +- thaw/src/input/mod.rs | 4 +- thaw/src/input/text_area.rs | 4 +- thaw/src/input_number/mod.rs | 4 +- thaw/src/menu/mod.rs | 6 +- thaw/src/mobile/tabbar/mod.rs | 6 +- thaw/src/modal/mod.rs | 3 +- thaw/src/radio/mod.rs | 4 +- thaw/src/select/mod.rs | 4 +- thaw/src/slider/mod.rs | 4 +- thaw/src/switch/mod.rs | 4 +- thaw/src/tabs/mod.rs | 8 +- thaw/src/time_picker/mod.rs | 4 +- thaw/src/utils/mod.rs | 2 + thaw/src/utils/model.rs | 198 ++++++++++++++++++++++++++++ 22 files changed, 248 insertions(+), 46 deletions(-) create mode 100644 thaw/src/utils/model.rs diff --git a/thaw/src/auto_complete/mod.rs b/thaw/src/auto_complete/mod.rs index 80157d58..47d51545 100644 --- a/thaw/src/auto_complete/mod.rs +++ b/thaw/src/auto_complete/mod.rs @@ -3,7 +3,7 @@ mod theme; use crate::{ components::{Binder, Follower, FollowerPlacement, FollowerWidth}, use_theme, - utils::{class_list::class_list, mount_style, StoredMaybeSignal}, + utils::{class_list::class_list, mount_style, Model, StoredMaybeSignal}, ComponentRef, Input, InputPrefix, InputRef, InputSuffix, Theme, }; use leptos::*; @@ -27,7 +27,7 @@ pub struct AutoCompleteSuffix { #[component] pub fn AutoComplete( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] placeholder: MaybeSignal, #[prop(optional, into)] options: MaybeSignal>, #[prop(optional, into)] clear_after_select: MaybeSignal, diff --git a/thaw/src/calendar/mod.rs b/thaw/src/calendar/mod.rs index 78b3f6e8..1d60ff9a 100644 --- a/thaw/src/calendar/mod.rs +++ b/thaw/src/calendar/mod.rs @@ -3,7 +3,7 @@ mod theme; use crate::{ chrono::{Datelike, Days, Local, NaiveDate}, use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Button, ButtonGroup, ButtonVariant, Theme, }; use chrono::{Month, Months}; @@ -14,7 +14,7 @@ pub use theme::CalendarTheme; #[component] pub fn Calendar( #[prop(optional, into)] class: MaybeSignal, - #[prop(optional, into)] value: RwSignal>, + #[prop(optional, into)] value: Model>, ) -> impl IntoView { mount_style("calendar", include_str!("./calendar.css")); let theme = use_theme(Theme::light); @@ -170,7 +170,7 @@ pub fn Calendar( #[component] fn CalendarItem( - value: RwSignal>, + value: Model>, index: usize, date: CalendarItemDate, ) -> impl IntoView { diff --git a/thaw/src/checkbox/checkbox_group.rs b/thaw/src/checkbox/checkbox_group.rs index fda9c539..bc40798e 100644 --- a/thaw/src/checkbox/checkbox_group.rs +++ b/thaw/src/checkbox/checkbox_group.rs @@ -1,16 +1,17 @@ +use crate::utils::Model; use leptos::*; use std::collections::HashSet; #[component] pub fn CheckboxGroup( - #[prop(optional, into)] value: RwSignal>, + #[prop(optional, into)] value: Model>, children: Children, ) -> impl IntoView { view! { } } #[derive(Clone)] -pub(crate) struct CheckboxGroupInjection(pub RwSignal>); +pub(crate) struct CheckboxGroupInjection(pub Model>); pub(crate) fn use_checkbox_group() -> CheckboxGroupInjection { expect_context() diff --git a/thaw/src/checkbox/mod.rs b/thaw/src/checkbox/mod.rs index b607aab1..33b93267 100644 --- a/thaw/src/checkbox/mod.rs +++ b/thaw/src/checkbox/mod.rs @@ -5,7 +5,7 @@ use crate::{ components::*, icon::*, theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; pub use checkbox_group::CheckboxGroup; @@ -14,7 +14,7 @@ use leptos::*; #[component] pub fn Checkbox( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] class: MaybeSignal, children: Children, ) -> impl IntoView { @@ -44,7 +44,7 @@ pub fn Checkbox( >
- + diff --git a/thaw/src/collapse/mod.rs b/thaw/src/collapse/mod.rs index 15c693f0..54961a7f 100644 --- a/thaw/src/collapse/mod.rs +++ b/thaw/src/collapse/mod.rs @@ -6,7 +6,7 @@ pub use theme::CollapseTheme; use crate::{ use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; use leptos::*; @@ -15,7 +15,7 @@ use std::collections::HashSet; #[component] pub fn Collapse( #[prop(optional, into)] class: MaybeSignal, - #[prop(optional, into)] value: RwSignal>, + #[prop(optional, into)] value: Model>, #[prop(optional)] accordion: bool, children: Children, ) -> impl IntoView { @@ -42,7 +42,7 @@ pub fn Collapse( #[derive(Clone)] pub(crate) struct CollapseInjection { - pub value: RwSignal>, + pub value: Model>, pub accordion: bool, } diff --git a/thaw/src/color_picker/mod.rs b/thaw/src/color_picker/mod.rs index 5836f028..1f7f1c5d 100644 --- a/thaw/src/color_picker/mod.rs +++ b/thaw/src/color_picker/mod.rs @@ -4,7 +4,7 @@ mod theme; use crate::{ components::{Binder, Follower, FollowerPlacement}, use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; pub use color::*; @@ -14,7 +14,7 @@ pub use theme::ColorPickerTheme; #[component] pub fn ColorPicker( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] class: MaybeSignal, ) -> impl IntoView { mount_style("color-picker", include_str!("./color-picker.css")); diff --git a/thaw/src/date_picker/mod.rs b/thaw/src/date_picker/mod.rs index 639c8ce6..c97f9da3 100644 --- a/thaw/src/date_picker/mod.rs +++ b/thaw/src/date_picker/mod.rs @@ -4,7 +4,7 @@ mod theme; use crate::{ chrono::NaiveDate, components::{Binder, Follower, FollowerPlacement}, - utils::{mount_style, now_date, ComponentRef}, + utils::{mount_style, now_date, ComponentRef, Model}, Icon, Input, InputSuffix, SignalWatch, }; use leptos::*; @@ -13,7 +13,7 @@ pub use theme::DatePickerTheme; #[component] pub fn DatePicker( - #[prop(optional, into)] value: RwSignal>, + #[prop(optional, into)] value: Model>, #[prop(optional, into)] class: MaybeSignal, #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>, ) -> impl IntoView { diff --git a/thaw/src/drawer/mod.rs b/thaw/src/drawer/mod.rs index 2929619f..136106f5 100644 --- a/thaw/src/drawer/mod.rs +++ b/thaw/src/drawer/mod.rs @@ -1,13 +1,13 @@ use crate::{ components::Teleport, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Card, }; use leptos::*; #[component] pub fn Drawer( - #[prop(into)] show: RwSignal, + #[prop(into)] show: Model, #[prop(optional, into)] title: MaybeSignal, #[prop(optional, into)] placement: MaybeSignal, #[prop(default = MaybeSignal::Static("520px".to_string()), into)] width: MaybeSignal, diff --git a/thaw/src/input/mod.rs b/thaw/src/input/mod.rs index 41406291..1c1b4538 100644 --- a/thaw/src/input/mod.rs +++ b/thaw/src/input/mod.rs @@ -6,7 +6,7 @@ pub use theme::InputTheme; use crate::{ theme::{use_theme, Theme}, - utils::{class_list::class_list, mount_style, ComponentRef}, + utils::{class_list::class_list, mount_style, ComponentRef, Model}, }; use leptos::*; @@ -42,7 +42,7 @@ pub struct InputSuffix { #[component] pub fn Input( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] allow_value: Option>, #[prop(optional, into)] variant: MaybeSignal, #[prop(optional, into)] placeholder: MaybeSignal, diff --git a/thaw/src/input/text_area.rs b/thaw/src/input/text_area.rs index e476c431..51810cfc 100644 --- a/thaw/src/input/text_area.rs +++ b/thaw/src/input/text_area.rs @@ -1,12 +1,12 @@ use crate::{ theme::{use_theme, Theme}, - utils::{class_list::class_list, mount_style, ComponentRef}, + utils::{class_list::class_list, mount_style, ComponentRef, Model}, }; use leptos::*; #[component] pub fn TextArea( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] allow_value: Option>, #[prop(optional, into)] placeholder: MaybeSignal, #[prop(optional, into)] on_focus: Option>, diff --git a/thaw/src/input_number/mod.rs b/thaw/src/input_number/mod.rs index ef2e55e8..ec5b1843 100644 --- a/thaw/src/input_number/mod.rs +++ b/thaw/src/input_number/mod.rs @@ -1,4 +1,4 @@ -use crate::utils::StoredMaybeSignal; +use crate::utils::{Model, StoredMaybeSignal}; use crate::{Button, ButtonVariant, ComponentRef, Icon, Input, InputRef, InputSuffix}; use leptos::*; use std::ops::{Add, Sub}; @@ -6,7 +6,7 @@ use std::str::FromStr; #[component] pub fn InputNumber( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] placeholder: MaybeSignal, #[prop(into)] step: MaybeSignal, #[prop(optional, into)] disabled: MaybeSignal, diff --git a/thaw/src/menu/mod.rs b/thaw/src/menu/mod.rs index b4106c17..08a86939 100644 --- a/thaw/src/menu/mod.rs +++ b/thaw/src/menu/mod.rs @@ -2,7 +2,7 @@ mod menu_group; mod menu_item; mod theme; -use crate::utils::class_list::class_list; +use crate::utils::{class_list::class_list, Model}; use leptos::*; pub use menu_group::MenuGroup; pub use menu_item::*; @@ -10,7 +10,7 @@ pub use theme::MenuTheme; #[component] pub fn Menu( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] class: MaybeSignal, children: Children, ) -> impl IntoView { @@ -22,7 +22,7 @@ pub fn Menu( } #[derive(Clone)] -pub(crate) struct MenuInjection(pub RwSignal); +pub(crate) struct MenuInjection(pub Model); pub(crate) fn use_menu() -> MenuInjection { expect_context() diff --git a/thaw/src/mobile/tabbar/mod.rs b/thaw/src/mobile/tabbar/mod.rs index c21c082d..cb274de3 100644 --- a/thaw/src/mobile/tabbar/mod.rs +++ b/thaw/src/mobile/tabbar/mod.rs @@ -1,14 +1,14 @@ mod tabbar_item; mod theme; -use crate::{use_theme, utils::mount_style, Theme}; +use crate::{use_theme, utils::{mount_style, Model}, Theme}; use leptos::*; pub use tabbar_item::*; pub use theme::TabbarTheme; #[component] pub fn Tabbar( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, children: Children, ) -> impl IntoView { mount_style("tabbar", include_str!("./tabbar.css")); @@ -32,7 +32,7 @@ pub fn Tabbar( } #[derive(Clone)] -pub(crate) struct TabbarInjection(pub RwSignal); +pub(crate) struct TabbarInjection(pub Model); pub(crate) fn use_tabbar() -> TabbarInjection { expect_context() diff --git a/thaw/src/modal/mod.rs b/thaw/src/modal/mod.rs index f679931c..c571d4aa 100644 --- a/thaw/src/modal/mod.rs +++ b/thaw/src/modal/mod.rs @@ -1,4 +1,5 @@ use crate::icon::*; +use crate::utils::Model; use crate::{ components::{OptionComp, Teleport}, utils::{mount_style, StoredMaybeSignal}, @@ -13,7 +14,7 @@ pub struct ModalFooter { #[component] pub fn Modal( - #[prop(into)] show: RwSignal, + #[prop(into)] show: Model, #[prop(optional, into)] title: MaybeSignal, children: Children, #[prop(optional)] modal_footer: Option, diff --git a/thaw/src/radio/mod.rs b/thaw/src/radio/mod.rs index 82128eb2..03e87b71 100644 --- a/thaw/src/radio/mod.rs +++ b/thaw/src/radio/mod.rs @@ -1,13 +1,13 @@ use crate::{ theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; use leptos::*; #[component] pub fn Radio( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] class: MaybeSignal, children: Children, ) -> impl IntoView { diff --git a/thaw/src/select/mod.rs b/thaw/src/select/mod.rs index 267ae492..dfd04787 100644 --- a/thaw/src/select/mod.rs +++ b/thaw/src/select/mod.rs @@ -3,7 +3,7 @@ mod theme; use crate::{ components::{Binder, Follower, FollowerPlacement, FollowerWidth}, theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; use leptos::*; @@ -18,7 +18,7 @@ pub struct SelectOption { #[component] pub fn Select( - #[prop(optional, into)] value: RwSignal>, + #[prop(optional, into)] value: Model>, #[prop(optional, into)] options: MaybeSignal>>, #[prop(optional, into)] class: MaybeSignal, ) -> impl IntoView diff --git a/thaw/src/slider/mod.rs b/thaw/src/slider/mod.rs index dbbd1fca..f12d01c3 100644 --- a/thaw/src/slider/mod.rs +++ b/thaw/src/slider/mod.rs @@ -4,7 +4,7 @@ mod theme; use crate::{ components::OptionComp, theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; use leptos::*; @@ -15,7 +15,7 @@ pub use theme::SliderTheme; #[component] pub fn Slider( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(default = MaybeSignal::Static(100f64), into)] max: MaybeSignal, #[prop(optional, into)] step: MaybeSignal, #[prop(optional, into)] class: MaybeSignal, diff --git a/thaw/src/switch/mod.rs b/thaw/src/switch/mod.rs index 271344ed..0558836e 100644 --- a/thaw/src/switch/mod.rs +++ b/thaw/src/switch/mod.rs @@ -2,7 +2,7 @@ mod theme; use crate::{ theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; use leptos::*; @@ -10,7 +10,7 @@ pub use theme::SwitchTheme; #[component] pub fn Switch( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] class: MaybeSignal, ) -> impl IntoView { mount_style("switch", include_str!("./switch.css")); diff --git a/thaw/src/tabs/mod.rs b/thaw/src/tabs/mod.rs index 1fce5225..2e2b931a 100644 --- a/thaw/src/tabs/mod.rs +++ b/thaw/src/tabs/mod.rs @@ -2,7 +2,7 @@ mod tab; use crate::{ theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, Model}, Theme, }; use leptos::*; @@ -11,7 +11,7 @@ pub use tab::*; #[component] pub fn Tabs( - #[prop(optional, into)] value: RwSignal, + #[prop(optional, into)] value: Model, #[prop(optional, into)] class: MaybeSignal, children: Children, ) -> impl IntoView { @@ -30,7 +30,7 @@ pub fn Tabs( #[component] fn TabsInner( - value: RwSignal, + value: Model, tab_options_vec: RwSignal>, #[prop(optional, into)] class: MaybeSignal, children: Children, @@ -161,7 +161,7 @@ pub(crate) struct TabsLabelLine { #[derive(Clone)] pub(crate) struct TabsInjection { - active_key: RwSignal, + active_key: Model, tab_options_vec: RwSignal>, } diff --git a/thaw/src/time_picker/mod.rs b/thaw/src/time_picker/mod.rs index 5350d54f..b77be254 100644 --- a/thaw/src/time_picker/mod.rs +++ b/thaw/src/time_picker/mod.rs @@ -4,7 +4,7 @@ use crate::{ chrono::{Local, NaiveTime, Timelike}, components::{Binder, Follower, FollowerPlacement}, use_theme, - utils::{mount_style, ComponentRef}, + utils::{mount_style, ComponentRef, Model}, Button, ButtonSize, ButtonVariant, Icon, Input, InputSuffix, SignalWatch, Theme, }; use leptos::*; @@ -12,7 +12,7 @@ pub use theme::TimePickerTheme; #[component] pub fn TimePicker( - #[prop(optional, into)] value: RwSignal>, + #[prop(optional, into)] value: Model>, #[prop(optional, into)] class: MaybeSignal, #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>, ) -> impl IntoView { diff --git a/thaw/src/utils/mod.rs b/thaw/src/utils/mod.rs index 9662c96e..5b78c613 100644 --- a/thaw/src/utils/mod.rs +++ b/thaw/src/utils/mod.rs @@ -2,6 +2,7 @@ pub(crate) mod class_list; mod component_ref; mod event_listener; +mod model; mod mount_style; mod signal; mod stored_maybe_signal; @@ -10,6 +11,7 @@ mod time; // pub use callback::AsyncCallback; pub use component_ref::{create_component_ref, ComponentRef}; pub(crate) use event_listener::*; +pub(crate) use model::Model; pub(crate) use mount_style::mount_style; pub use signal::SignalWatch; pub(crate) use stored_maybe_signal::*; diff --git a/thaw/src/utils/model.rs b/thaw/src/utils/model.rs new file mode 100644 index 00000000..95411f55 --- /dev/null +++ b/thaw/src/utils/model.rs @@ -0,0 +1,198 @@ +use leptos::{ + Memo, ReadSignal, RwSignal, Signal, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate, + SignalWith, SignalWithUntracked, WriteSignal, +}; + +pub struct Model +where + T: 'static, +{ + read: Signal, + write: WriteSignal, + on_write: Option>, +} + +impl Default for Model { + fn default() -> Self { + RwSignal::new(Default::default()).into() + } +} + +impl Clone for Model { + fn clone(&self) -> Self { + Self { + read: self.read.clone(), + write: self.write.clone(), + on_write: self.on_write.clone(), + } + } +} + +impl Copy for Model {} + +impl Model { + fn new(value: T) -> Self { + let rw_signal = RwSignal::new(value); + rw_signal.into() + } + + pub fn signal(&self) -> Signal { + self.read.clone() + } +} + +impl SignalGet for Model { + type Value = T; + + fn get(&self) -> Self::Value { + self.read.get() + } + + fn try_get(&self) -> Option { + self.read.try_get() + } +} + +impl SignalGetUntracked for Model { + type Value = T; + + fn get_untracked(&self) -> Self::Value { + self.read.get_untracked() + } + + fn try_get_untracked(&self) -> Option { + self.read.try_get_untracked() + } +} + +impl SignalSet for Model { + type Value = T; + + fn set(&self, new_value: Self::Value) { + if let Some(on_write) = self.on_write.as_ref() { + on_write.set(new_value.clone()); + } + self.write.set(new_value); + } + + fn try_set(&self, new_value: Self::Value) -> Option { + if let Some(on_write) = self.on_write.as_ref() { + on_write.try_set(new_value.clone()); + } + self.write.try_set(new_value) + } +} + +impl SignalWith for Model { + type Value = T; + + fn with(&self, f: impl FnOnce(&Self::Value) -> O) -> O { + self.read.with(f) + } + + fn try_with(&self, f: impl FnOnce(&Self::Value) -> O) -> Option { + self.read.try_with(f) + } +} + +impl SignalWithUntracked for Model { + type Value = T; + + fn with_untracked(&self, f: impl FnOnce(&Self::Value) -> O) -> O { + self.read.with_untracked(f) + } + + fn try_with_untracked(&self, f: impl FnOnce(&Self::Value) -> O) -> Option { + self.read.try_with_untracked(f) + } +} + +impl SignalUpdate for Model { + type Value = T; + + fn update(&self, f: impl FnOnce(&mut Self::Value)) { + self.write.update(f); + } + + fn try_update(&self, f: impl FnOnce(&mut Self::Value) -> O) -> Option { + self.write.try_update(f) + } +} + +impl From for Model { + fn from(value: T) -> Self { + Self::new(value) + } +} + +impl From> for Model { + fn from(rw_signal: RwSignal) -> Self { + let (read, write) = rw_signal.split(); + Self { + read: read.into(), + write, + on_write: None, + } + } +} + +impl From<(ReadSignal, WriteSignal)> for Model { + fn from((read, write): (ReadSignal, WriteSignal)) -> Self { + Self { + read: read.into(), + write, + on_write: None, + } + } +} + +impl From<(Memo, WriteSignal)> for Model { + fn from((read, write): (Memo, WriteSignal)) -> Self { + Self { + read: read.into(), + write, + on_write: None, + } + } +} + +impl From<(Option, WriteSignal)> for Model { + fn from((read, write): (Option, WriteSignal)) -> Self { + let mut modal = Self::new(read.unwrap_or_default()); + modal.on_write = Some(write.into()); + modal + } +} + +#[cfg(test)] +mod test { + use super::Model; + use leptos::*; + + #[test] + fn from() { + let runtime = create_runtime(); + + // T + let modal: Model = 0.into(); + assert_eq!(modal.get_untracked(), 0); + modal.set(1); + assert_eq!(modal.get_untracked(), 1); + + // RwSignal + let rw_signal = RwSignal::new(0); + let modal: Model = rw_signal.into(); + assert_eq!(modal.get_untracked(), 0); + modal.set(1); + assert_eq!(modal.get_untracked(), 1); + + // Read Write + let (read, write) = create_signal(0); + let modal: Model = (read, write).into(); + assert_eq!(modal.get_untracked(), 0); + modal.set(1); + assert_eq!(modal.get_untracked(), 1); + + runtime.dispose(); + } +} From 4946b99e22f66286e1d40519d1b4ab22e1804055 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Mon, 29 Jan 2024 11:23:51 +0800 Subject: [PATCH 07/26] fix: model word --- thaw/src/utils/model.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/thaw/src/utils/model.rs b/thaw/src/utils/model.rs index 95411f55..1731161d 100644 --- a/thaw/src/utils/model.rs +++ b/thaw/src/utils/model.rs @@ -158,9 +158,9 @@ impl From<(Memo, WriteSignal)> for Model { impl From<(Option, WriteSignal)> for Model { fn from((read, write): (Option, WriteSignal)) -> Self { - let mut modal = Self::new(read.unwrap_or_default()); - modal.on_write = Some(write.into()); - modal + let mut model = Self::new(read.unwrap_or_default()); + model.on_write = Some(write.into()); + model } } @@ -174,24 +174,24 @@ mod test { let runtime = create_runtime(); // T - let modal: Model = 0.into(); - assert_eq!(modal.get_untracked(), 0); - modal.set(1); - assert_eq!(modal.get_untracked(), 1); + let model: Model = 0.into(); + assert_eq!(model.get_untracked(), 0); + model.set(1); + assert_eq!(model.get_untracked(), 1); // RwSignal let rw_signal = RwSignal::new(0); - let modal: Model = rw_signal.into(); - assert_eq!(modal.get_untracked(), 0); - modal.set(1); - assert_eq!(modal.get_untracked(), 1); + let model: Model = rw_signal.into(); + assert_eq!(model.get_untracked(), 0); + model.set(1); + assert_eq!(model.get_untracked(), 1); // Read Write let (read, write) = create_signal(0); - let modal: Model = (read, write).into(); - assert_eq!(modal.get_untracked(), 0); - modal.set(1); - assert_eq!(modal.get_untracked(), 1); + let model: Model = (read, write).into(); + assert_eq!(model.get_untracked(), 0); + model.set(1); + assert_eq!(model.get_untracked(), 1); runtime.dispose(); } From eb50458d858b9c8cece543172b9abacb68019f37 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Mon, 29 Jan 2024 16:18:01 +0800 Subject: [PATCH 08/26] feat: ButtonVariant Solid is changed to Outlined --- demo_markdown/docs/button/mod.md | 18 +++++++++--------- thaw/src/button/button.css | 6 +++--- thaw/src/button/mod.rs | 10 +++++----- thaw/src/button/theme.rs | 6 +++--- thaw/src/calendar/mod.rs | 6 +++--- thaw/src/date_picker/panel/date_panel.rs | 2 +- thaw/src/time_picker/mod.rs | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/demo_markdown/docs/button/mod.md b/demo_markdown/docs/button/mod.md index 81e737e2..ae8c087f 100644 --- a/demo_markdown/docs/button/mod.md +++ b/demo_markdown/docs/button/mod.md @@ -4,7 +4,7 @@ view! { - + @@ -80,8 +80,8 @@ view! { - - - + + + - - - + + + } diff --git a/thaw/src/button/button.css b/thaw/src/button/button.css index db77053c..4afa9f1f 100644 --- a/thaw/src/button/button.css +++ b/thaw/src/button/button.css @@ -13,7 +13,7 @@ user-select: none; } -.thaw-button:hover:not(.thaw-button--disabled, .thaw-button--solid) { +.thaw-button:hover:not(.thaw-button--disabled, .thaw-button--outlined) { border-color: var(--thaw-border-color-hover); background-color: var(--thaw-background-color-hover); cursor: pointer; @@ -37,13 +37,13 @@ background-color: var(--thaw-background-color-active); } -.thaw-button--solid { +.thaw-button--outlined { background-color: transparent; color: inherit; transition: all 0.3s; } -.thaw-button--solid:hover:not(.thaw-button--disabled) { +.thaw-button--outlined:hover:not(.thaw-button--disabled) { cursor: pointer; color: var(--thaw-font-color-hover); border-color: var(--thaw-border-color-hover); diff --git a/thaw/src/button/mod.rs b/thaw/src/button/mod.rs index af140eb8..4c1b6455 100644 --- a/thaw/src/button/mod.rs +++ b/thaw/src/button/mod.rs @@ -15,7 +15,7 @@ pub use theme::ButtonTheme; pub enum ButtonVariant { #[default] Primary, - Solid, + Outlined, Text, Link, } @@ -155,11 +155,11 @@ pub fn Button( theme.button.color_border_disabled )); } - ButtonVariant::Solid => { + ButtonVariant::Outlined => { css_vars.push_str(&format!("--thaw-font-color-hover: {bg_color};")); css_vars.push_str(&format!( "--thaw-border-color: {};", - theme.button.border_color_solid + theme.button.border_color_outlined )); css_vars.push_str(&format!("--thaw-border-color-hover: {bg_color};")); css_vars.push_str(&format!("--thaw-ripple-color: {bg_color};")); @@ -223,8 +223,8 @@ pub fn Button( view! {
diff --git a/thaw/src/time_picker/mod.rs b/thaw/src/time_picker/mod.rs index b77be254..2fde7ed4 100644 --- a/thaw/src/time_picker/mod.rs +++ b/thaw/src/time_picker/mod.rs @@ -257,7 +257,7 @@ fn Panel( -
{children()}
+ +
{children()}
+
} } From dccf0858a0753e7d021ce13b64da02d17da0efbc Mon Sep 17 00:00:00 2001 From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:13:26 +0800 Subject: [PATCH 10/26] Feat/option (#93) * feat: alert, avatar, badge option * feat: some component option * feat: add OptionalProp * feat: some component option * feat: some component option --- thaw/src/alert/mod.rs | 24 +++--- thaw/src/auto_complete/mod.rs | 8 +- thaw/src/avatar/mod.rs | 20 +++-- thaw/src/badge/mod.rs | 7 +- thaw/src/breadcrumb/breadcrumb_item.rs | 6 +- thaw/src/breadcrumb/mod.rs | 6 +- thaw/src/button/mod.rs | 10 +-- thaw/src/calendar/mod.rs | 6 +- thaw/src/card/mod.rs | 55 ++++++------ thaw/src/checkbox/checkbox_item.rs | 3 +- thaw/src/checkbox/mod.rs | 7 +- thaw/src/collapse/collapse_item.rs | 6 +- thaw/src/collapse/mod.rs | 6 +- thaw/src/color_picker/mod.rs | 6 +- thaw/src/components/option_comp.rs | 2 +- thaw/src/date_picker/mod.rs | 4 +- thaw/src/divider/mod.rs | 7 +- thaw/src/drawer/mod.rs | 8 +- thaw/src/grid/grid_item.rs | 6 +- thaw/src/grid/mod.rs | 6 +- thaw/src/image/mod.rs | 17 ++-- thaw/src/input/mod.rs | 10 +-- thaw/src/input/text_area.rs | 10 +-- thaw/src/input_number/mod.rs | 6 +- thaw/src/layout/layout_header.rs | 8 +- thaw/src/layout/layout_sider.rs | 8 +- thaw/src/layout/mod.rs | 20 +++-- thaw/src/menu/menu_group.rs | 6 +- thaw/src/menu/menu_item.rs | 6 +- thaw/src/menu/mod.rs | 6 +- thaw/src/mobile/nav_bar/mod.rs | 71 ++++++++-------- thaw/src/mobile/toast/mod.rs | 2 +- thaw/src/modal/mod.rs | 3 +- thaw/src/popover/mod.rs | 10 +-- thaw/src/radio/mod.rs | 6 +- thaw/src/select/mod.rs | 6 +- thaw/src/slider/mod.rs | 6 +- thaw/src/space/mod.rs | 6 +- thaw/src/spinner/mod.rs | 6 +- thaw/src/switch/mod.rs | 6 +- thaw/src/table/mod.rs | 6 +- thaw/src/tabs/mod.rs | 10 +-- thaw/src/tabs/tab.rs | 10 +-- thaw/src/tag/mod.rs | 6 +- thaw/src/time_picker/mod.rs | 4 +- thaw/src/typography/text.rs | 10 +-- thaw/src/utils/class_list.rs | 16 ++++ thaw/src/utils/mod.rs | 2 + thaw/src/utils/optional_prop.rs | 113 +++++++++++++++++++++++++ 49 files changed, 370 insertions(+), 229 deletions(-) create mode 100644 thaw/src/utils/optional_prop.rs diff --git a/thaw/src/alert/mod.rs b/thaw/src/alert/mod.rs index 694f546e..cf3bdf42 100644 --- a/thaw/src/alert/mod.rs +++ b/thaw/src/alert/mod.rs @@ -1,8 +1,9 @@ mod theme; use crate::{ + components::OptionComp, theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, OptionalProp}, Icon, Theme, }; use leptos::*; @@ -41,8 +42,8 @@ impl AlertVariant { #[component] pub fn Alert( - #[prop(optional, into)] class: MaybeSignal, - #[prop(optional, into)] title: MaybeSignal, + #[prop(optional, into)] class: OptionalProp>, + #[prop(optional, into)] title: Option>, #[prop(into)] variant: MaybeSignal, children: Children, ) -> impl IntoView { @@ -84,18 +85,15 @@ pub fn Alert( }); view! { -
+
- - {move || { - let title = title.get(); - if title.is_empty() { - None - } else { - view! {
{title}
}.into() - } - }} + +
{move || title.get()}
+
{children()}
diff --git a/thaw/src/auto_complete/mod.rs b/thaw/src/auto_complete/mod.rs index 47d51545..c006016d 100644 --- a/thaw/src/auto_complete/mod.rs +++ b/thaw/src/auto_complete/mod.rs @@ -3,7 +3,7 @@ mod theme; use crate::{ components::{Binder, Follower, FollowerPlacement, FollowerWidth}, use_theme, - utils::{class_list::class_list, mount_style, Model, StoredMaybeSignal}, + utils::{class_list::class_list, mount_style, Model, OptionalProp, StoredMaybeSignal}, ComponentRef, Input, InputPrefix, InputRef, InputSuffix, Theme, }; use leptos::*; @@ -28,13 +28,13 @@ pub struct AutoCompleteSuffix { #[component] pub fn AutoComplete( #[prop(optional, into)] value: Model, - #[prop(optional, into)] placeholder: MaybeSignal, + #[prop(optional, into)] placeholder: OptionalProp>, #[prop(optional, into)] options: MaybeSignal>, #[prop(optional, into)] clear_after_select: MaybeSignal, #[prop(optional, into)] on_select: Option>, #[prop(optional, into)] disabled: MaybeSignal, #[prop(optional, into)] invalid: MaybeSignal, - #[prop(optional, into)] class: MaybeSignal, + #[prop(optional, into)] class: OptionalProp>, #[prop(optional)] auto_complete_prefix: Option, #[prop(optional)] auto_complete_suffix: Option, #[prop(optional)] comp_ref: ComponentRef, @@ -130,7 +130,7 @@ pub fn AutoComplete( view! {
diff --git a/thaw/src/avatar/mod.rs b/thaw/src/avatar/mod.rs index 1d3f19d6..07fba1d8 100644 --- a/thaw/src/avatar/mod.rs +++ b/thaw/src/avatar/mod.rs @@ -1,8 +1,9 @@ mod theme; use crate::{ + components::OptionComp, use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, OptionalProp}, Theme, }; use leptos::*; @@ -10,10 +11,10 @@ pub use theme::AvatarTheme; #[component] pub fn Avatar( - #[prop(optional, into)] src: MaybeSignal, + #[prop(optional, into)] src: Option>, #[prop(optional, into)] round: MaybeSignal, #[prop(default = MaybeSignal::Static(30), into)] size: MaybeSignal, - #[prop(optional, into)] class: MaybeSignal, + #[prop(optional, into)] class: OptionalProp>, ) -> impl IntoView { let theme = use_theme(Theme::light); let css_vars = create_memo(move |_| { @@ -34,12 +35,13 @@ pub fn Avatar( mount_style("avatar", include_str!("./avatar.css")); view! { - - {move || { - let src = src.get(); - (!src.is_empty()).then(|| view! { }) - }} - + + + + } } diff --git a/thaw/src/badge/mod.rs b/thaw/src/badge/mod.rs index b9e1391b..491fda0c 100644 --- a/thaw/src/badge/mod.rs +++ b/thaw/src/badge/mod.rs @@ -1,6 +1,6 @@ use crate::{ theme::use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, OptionalProp}, Theme, }; use leptos::*; @@ -29,7 +29,7 @@ pub fn Badge( #[prop(default = MaybeSignal::Static(u32::MAX), into)] max: MaybeSignal, #[prop(optional, into)] variant: MaybeSignal, #[prop(optional, into)] dot: MaybeSignal, - #[prop(optional, into)] class: MaybeSignal, + #[prop(optional, into)] class: OptionalProp>, children: Children, ) -> impl IntoView { let theme = use_theme(Theme::light); @@ -61,7 +61,8 @@ pub fn Badge(
{move || value.get()}
{children()}
diff --git a/thaw/src/breadcrumb/breadcrumb_item.rs b/thaw/src/breadcrumb/breadcrumb_item.rs index f3d16f09..bec75eef 100644 --- a/thaw/src/breadcrumb/breadcrumb_item.rs +++ b/thaw/src/breadcrumb/breadcrumb_item.rs @@ -1,10 +1,10 @@ use super::use_breadcrumb_separator; -use crate::utils::class_list::class_list; +use crate::utils::{class_list::class_list, OptionalProp}; use leptos::*; #[component] pub fn BreadcrumbItem( - #[prop(optional, into)] class: MaybeSignal, + #[prop(optional, into)] class: OptionalProp>, children: Children, ) -> impl IntoView { let breadcrumb_separator = use_breadcrumb_separator(); @@ -12,7 +12,7 @@ pub fn BreadcrumbItem( view! {
  • {children()} {move || breadcrumb_separator.0.get()} diff --git a/thaw/src/breadcrumb/mod.rs b/thaw/src/breadcrumb/mod.rs index e576700c..60fa681c 100644 --- a/thaw/src/breadcrumb/mod.rs +++ b/thaw/src/breadcrumb/mod.rs @@ -3,7 +3,7 @@ mod theme; use crate::{ use_theme, - utils::{class_list::class_list, mount_style}, + utils::{class_list::class_list, mount_style, OptionalProp}, Theme, }; pub use breadcrumb_item::BreadcrumbItem; @@ -13,7 +13,7 @@ pub use theme::BreadcrumbTheme; #[component] pub fn Breadcrumb( #[prop(default = MaybeSignal::Static("/".to_string()),into)] separator: MaybeSignal, - #[prop(optional, into)] class: MaybeSignal, + #[prop(optional, into)] class: OptionalProp>, children: Children, ) -> impl IntoView { mount_style("breadcrumb", include_str!("./breadcrumb.css")); @@ -40,7 +40,7 @@ pub fn Breadcrumb( view! {