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_devtools = { version = "0.0.1", optional = true}
thaw = { path = "../thaw", default-features = false }
icondata = "0.3.0"
demo_markdown = { path = "../demo_markdown" }
[features]

View file

@ -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 {

View file

@ -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 {

View file

@ -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"

View file

@ -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<ButtonSize>,
#[prop(optional, into)] round: 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)] disabled: MaybeSignal<bool>,
#[prop(optional, into)] on_click: Option<Callback<ev::MouseEvent>>,

View file

@ -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>,
icon: MaybeSignal<icondata::Icon>,
/// The width of the icon (horizontal side length of the square surrounding the icon). Defaults to "1em".
#[prop(into, optional)]
width: Option<MaybeSignal<String>>,
@ -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);

View file

@ -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::*;

View file

@ -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,

View file

@ -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<String>,
#[prop(optional, into)] icon: Option<Icon>,
#[prop(optional, into)] icon: Option<icondata::Icon>,
children: Children,
) -> impl IntoView {
mount_style("tabbar-item", include_str!("./tabbar-item.css"));