From 24df111b4b7ea5e685d00cbe3c1827784ae8a7ee Mon Sep 17 00:00:00 2001 From: luoxiao Date: Fri, 26 Jan 2024 23:26:56 +0800 Subject: [PATCH] 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 2867825..abbc8e7 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 79709a7..222fef5 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 7330265..657f36d 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 fa56b66..7d1e02b 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 c4c776a..af140eb 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 a11bb11..4ef5c49 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 f2023ef..cce8920 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 02cc741..fdcf025 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 ed4f06f..02f5d46 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"));