feat: sync upstream Icon

This commit is contained in:
luoxiao 2024-01-26 23:26:56 +08:00 committed by luoxiaozero
parent 3ea0afa7af
commit 24df111b4b
9 changed files with 25 additions and 28 deletions

View file

@ -12,7 +12,6 @@ leptos_meta = { version = "0.5.7" }
leptos_router = { version = "0.5.7" } leptos_router = { version = "0.5.7" }
leptos_devtools = { version = "0.0.1", optional = true} leptos_devtools = { version = "0.0.1", optional = true}
thaw = { path = "../thaw", default-features = false } thaw = { path = "../thaw", default-features = false }
icondata = "0.3.0"
demo_markdown = { path = "../demo_markdown" } demo_markdown = { path = "../demo_markdown" }
[features] [features]

View file

@ -2,7 +2,7 @@ use super::NavBarMdPage;
use crate::pages::MobilePage; use crate::pages::MobilePage;
use leptos::*; use leptos::*;
use thaw::mobile::{NavBar, NavBarRight}; use thaw::mobile::{NavBar, NavBarRight};
use thaw::Icon; use thaw::{icondata, Icon};
#[component] #[component]
pub fn NavBarPage() -> impl IntoView { pub fn NavBarPage() -> impl IntoView {

View file

@ -1,7 +1,10 @@
use super::TabbarMdPage; use super::TabbarMdPage;
use crate::pages::MobilePage; use crate::pages::MobilePage;
use leptos::*; use leptos::*;
use thaw::mobile::{Tabbar, TabbarItem}; use thaw::{
icondata,
mobile::{Tabbar, TabbarItem},
};
#[component] #[component]
pub fn TabbarPage() -> impl IntoView { pub fn TabbarPage() -> impl IntoView {

View file

@ -23,7 +23,6 @@ web-sys = { version = "0.3.63", features = [
] } ] }
wasm-bindgen = "0.2.89" wasm-bindgen = "0.2.89"
icondata = "0.3.0" icondata = "0.3.0"
icondata_core = "0.1.0"
uuid = { version = "1.5.0", features = ["v4"] } uuid = { version = "1.5.0", features = ["v4"] }
cfg-if = "1.0.0" cfg-if = "1.0.0"
chrono = "0.4.31" chrono = "0.4.31"

View file

@ -3,7 +3,7 @@ mod theme;
use crate::{ use crate::{
components::{OptionComp, Wave, WaveRef}, components::{OptionComp, Wave, WaveRef},
icon::*, icon::Icon,
theme::*, theme::*,
utils::{class_list::class_list, mount_style, ComponentRef}, utils::{class_list::class_list, mount_style, ComponentRef},
}; };
@ -104,7 +104,7 @@ pub fn Button(
#[prop(optional, into)] size: MaybeSignal<ButtonSize>, #[prop(optional, into)] size: MaybeSignal<ButtonSize>,
#[prop(optional, into)] round: MaybeSignal<bool>, #[prop(optional, into)] round: MaybeSignal<bool>,
#[prop(optional, into)] circle: MaybeSignal<bool>, #[prop(optional, into)] circle: MaybeSignal<bool>,
#[prop(optional, into)] icon: Option<Icon>, #[prop(optional, into)] icon: Option<icondata::Icon>,
#[prop(optional, into)] loading: MaybeSignal<bool>, #[prop(optional, into)] loading: MaybeSignal<bool>,
#[prop(optional, into)] disabled: MaybeSignal<bool>, #[prop(optional, into)] disabled: MaybeSignal<bool>,
#[prop(optional, into)] on_click: Option<Callback<ev::MouseEvent>>, #[prop(optional, into)] on_click: Option<Callback<ev::MouseEvent>>,

View file

@ -1,14 +1,13 @@
// copy https://github.com/Carlosted/leptos-icons // copy https://github.com/Carlosted/leptos-icons
// leptos updated version causes leptos_icons error // leptos updated version causes leptos_icons error
pub(crate) use icondata::Icon;
use leptos::*; use leptos::*;
/// The Icon component. /// The Icon component.
#[component] #[component]
pub fn Icon( pub fn Icon(
/// The icon to show. /// The icon to render.
#[prop(into)] #[prop(into)]
icon: MaybeSignal<Icon>, icon: MaybeSignal<icondata::Icon>,
/// The width of the icon (horizontal side length of the square surrounding the icon). Defaults to "1em". /// The width of the icon (horizontal side length of the square surrounding the icon). Defaults to "1em".
#[prop(into, optional)] #[prop(into, optional)]
width: Option<MaybeSignal<String>>, width: Option<MaybeSignal<String>>,
@ -25,12 +24,12 @@ pub fn Icon(
let svg = move || { let svg = move || {
let icon = icon.get(); let icon = icon.get();
let mut svg = svg::svg(); let mut svg = svg::svg();
if let Some(classes) = class.clone() { if let Some(class) = class.clone() {
svg = svg.classes(classes.get()); svg = svg.attr("class", move || class.get())
} }
let mut svg = match (style.clone(), icon.style) { let mut svg = match (style.clone(), icon.style) {
(Some(a), Some(b)) => svg.attr("style", format!("{b} {}", a.get())), (Some(a), Some(b)) => svg.attr("style", move || format!("{b} {}", a.get())),
(Some(a), None) => svg.attr("style", a.get()), (Some(a), None) => svg.attr("style", move || a.get()),
(None, Some(b)) => svg.attr("style", b), (None, Some(b)) => svg.attr("style", b),
(None, None) => svg, (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. // We ignore the width and height attributes of the icon, even if the user hasn't specified any.
svg = svg.attr( svg = svg.attr(
"width", "width",
Attribute::String(match (width.clone(), icon.width) { match (width.clone(), icon.width) {
(Some(a), Some(_b)) => Oco::from(a.get()), (Some(a), _) => (move || a.get()).into_attribute(),
(Some(a), None) => Oco::from(a.get()), _ => "1em".into_attribute(),
(None, Some(_b)) => Oco::from("1em"), },
(None, None) => Oco::from("1em"),
}),
); );
svg = svg.attr( svg = svg.attr(
"height", "height",
Attribute::String(match (height.clone(), icon.height) { match (height.clone(), icon.height) {
(Some(a), Some(_b)) => Oco::from(a.get()), (Some(a), _) => (move || a.get()).into_attribute(),
(Some(a), None) => Oco::from(a.get()), _ => "1em".into_attribute(),
(None, Some(_b)) => Oco::from("1em"), },
(None, None) => Oco::from("1em"),
}),
); );
if let Some(view_box) = icon.view_box { if let Some(view_box) = icon.view_box {
svg = svg.attr("viewBox", view_box); svg = svg.attr("viewBox", view_box);

View file

@ -63,6 +63,7 @@ pub use drawer::*;
pub use global_style::*; pub use global_style::*;
pub use grid::*; pub use grid::*;
pub use icon::*; pub use icon::*;
pub use icondata;
pub use image::*; pub use image::*;
pub use input::*; pub use input::*;
pub use input_number::*; pub use input_number::*;

View file

@ -17,7 +17,7 @@ pub enum MessageVariant {
} }
impl MessageVariant { impl MessageVariant {
fn icon(&self) -> Icon { fn icon(&self) -> icondata::Icon {
match self { match self {
MessageVariant::Success => icondata::AiCloseCircleFilled, MessageVariant::Success => icondata::AiCloseCircleFilled,
MessageVariant::Warning => icondata::AiExclamationCircleFilled, MessageVariant::Warning => icondata::AiExclamationCircleFilled,

View file

@ -1,13 +1,13 @@
use super::use_tabbar; use super::use_tabbar;
use crate::components::*; use crate::components::*;
use crate::utils::StoredMaybeSignal; 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::*; use leptos::*;
#[component] #[component]
pub fn TabbarItem( pub fn TabbarItem(
#[prop(into)] key: MaybeSignal<String>, #[prop(into)] key: MaybeSignal<String>,
#[prop(optional, into)] icon: Option<Icon>, #[prop(optional, into)] icon: Option<icondata::Icon>,
children: Children, children: Children,
) -> impl IntoView { ) -> impl IntoView {
mount_style("tabbar-item", include_str!("./tabbar-item.css")); mount_style("tabbar-item", include_str!("./tabbar-item.css"));