From 9bf0f7da1a2f9443efbce45d92a011dd5423e0f3 Mon Sep 17 00:00:00 2001 From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:02:43 +0800 Subject: [PATCH] Feat/thaw utils (#145) * feat: extract utils as the library * refactor: thaw_utils directory * style: fmt --- Cargo.toml | 6 +- thaw/Cargo.toml | 8 +- thaw/src/alert/mod.rs | 11 +-- thaw/src/auto_complete/mod.rs | 16 ++-- thaw/src/avatar/mod.rs | 11 +-- thaw/src/badge/mod.rs | 7 +- thaw/src/breadcrumb/breadcrumb_item.rs | 2 +- thaw/src/breadcrumb/mod.rs | 10 +-- thaw/src/button/button_group.rs | 7 +- thaw/src/button/mod.rs | 17 ++-- thaw/src/calendar/mod.rs | 10 +-- thaw/src/card/mod.rs | 8 +- thaw/src/checkbox/checkbox_group.rs | 2 +- thaw/src/checkbox/checkbox_item.rs | 2 +- thaw/src/checkbox/mod.rs | 10 +-- thaw/src/code/mod.rs | 2 +- thaw/src/collapse/collapse_item.rs | 7 +- thaw/src/collapse/mod.rs | 7 +- thaw/src/color_picker/mod.rs | 15 ++-- thaw/src/components/binder/mod.rs | 8 +- thaw/src/components/css_transition/mod.rs | 2 +- thaw/src/components/teleport/mod.rs | 2 +- thaw/src/components/wave/mod.rs | 2 +- thaw/src/date_picker/mod.rs | 2 +- thaw/src/date_picker/panel/date_panel.rs | 3 +- thaw/src/date_picker/panel/mod.rs | 8 +- thaw/src/divider/mod.rs | 2 +- thaw/src/drawer/mod.rs | 2 +- thaw/src/grid/grid_item.rs | 2 +- thaw/src/grid/mod.rs | 2 +- thaw/src/image/mod.rs | 2 +- thaw/src/input/mod.rs | 6 +- thaw/src/input/text_area.rs | 6 +- thaw/src/input_number/mod.rs | 2 +- thaw/src/layout/layout_header.rs | 2 +- thaw/src/layout/layout_sider.rs | 2 +- thaw/src/layout/mod.rs | 3 +- thaw/src/lib.rs | 3 +- thaw/src/loading_bar/loading_bar_provider.rs | 3 +- thaw/src/loading_bar/mod.rs | 6 +- thaw/src/menu/menu_group.rs | 7 +- thaw/src/menu/menu_item.rs | 7 +- thaw/src/menu/mod.rs | 5 +- thaw/src/message/message_provider.rs | 6 +- thaw/src/message/mod.rs | 5 +- thaw/src/mobile/nav_bar/mod.rs | 12 +-- thaw/src/mobile/tabbar/mod.rs | 10 +-- thaw/src/mobile/tabbar/tabbar_item.rs | 4 +- thaw/src/mobile/toast/mod.rs | 2 +- thaw/src/modal/mod.rs | 16 +++- thaw/src/popover/mod.rs | 13 +-- thaw/src/progress/mod.rs | 3 +- thaw/src/progress/progress_circle.rs | 35 +++----- thaw/src/radio/mod.rs | 7 +- thaw/src/radio/radio_group.rs | 2 +- thaw/src/radio/radio_item.rs | 6 +- thaw/src/select/mod.rs | 16 +++- thaw/src/skeleton/mod.rs | 6 +- thaw/src/slider/mod.rs | 14 ++- thaw/src/slider/slider_label.rs | 2 +- thaw/src/space/mod.rs | 2 +- thaw/src/spinner/mod.rs | 10 +-- thaw/src/switch/mod.rs | 10 +-- thaw/src/table/mod.rs | 10 +-- thaw/src/tabs/mod.rs | 11 +-- thaw/src/tabs/tab.rs | 2 +- thaw/src/tag/mod.rs | 30 +++---- thaw/src/time_picker/mod.rs | 26 ++++-- thaw/src/typography/text.rs | 7 +- thaw/src/upload/mod.rs | 5 +- thaw/src/upload/upload_dragger.rs | 3 +- thaw/src/utils/callback.rs | 89 ------------------- thaw/src/utils/mod.rs | 38 -------- thaw_utils/Cargo.toml | 25 ++++++ .../utils => thaw_utils/src}/class_list.rs | 4 +- .../src}/event_listener.rs | 0 thaw_utils/src/hooks/mod.rs | 5 ++ .../src/hooks}/use_click_position.rs | 0 .../src/hooks}/use_lock_html_scroll.rs | 0 thaw_utils/src/lib.rs | 28 ++++++ .../utils => thaw_utils/src}/mount_style.rs | 0 .../utils => thaw_utils/src}/optional_prop.rs | 0 .../src/signals}/component_ref.rs | 0 thaw_utils/src/signals/mod.rs | 11 +++ .../utils => thaw_utils/src/signals}/model.rs | 0 .../src/signals}/optional_maybe_signal.rs | 0 .../src/signals/signal_watch.rs | 0 .../src/signals}/stored_maybe_signal.rs | 0 {thaw/src/utils => thaw_utils/src}/time.rs | 0 89 files changed, 324 insertions(+), 398 deletions(-) delete mode 100644 thaw/src/utils/callback.rs delete mode 100644 thaw/src/utils/mod.rs create mode 100644 thaw_utils/Cargo.toml rename {thaw/src/utils => thaw_utils/src}/class_list.rs (98%) rename {thaw/src/utils => thaw_utils/src}/event_listener.rs (100%) create mode 100644 thaw_utils/src/hooks/mod.rs rename {thaw/src/utils => thaw_utils/src/hooks}/use_click_position.rs (100%) rename {thaw/src/utils => thaw_utils/src/hooks}/use_lock_html_scroll.rs (100%) create mode 100644 thaw_utils/src/lib.rs rename {thaw/src/utils => thaw_utils/src}/mount_style.rs (100%) rename {thaw/src/utils => thaw_utils/src}/optional_prop.rs (100%) rename {thaw/src/utils => thaw_utils/src/signals}/component_ref.rs (100%) create mode 100644 thaw_utils/src/signals/mod.rs rename {thaw/src/utils => thaw_utils/src/signals}/model.rs (100%) rename {thaw/src/utils => thaw_utils/src/signals}/optional_maybe_signal.rs (100%) rename thaw/src/utils/signal.rs => thaw_utils/src/signals/signal_watch.rs (100%) rename {thaw/src/utils => thaw_utils/src/signals}/stored_maybe_signal.rs (100%) rename {thaw/src/utils => thaw_utils/src}/time.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index f6862f6..ede66e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,8 @@ [workspace] resolver = "2" -members = ["thaw", "demo", "demo_markdown"] +members = ["thaw", "thaw_utils", "demo", "demo_markdown"] exclude = ["examples"] + +[workspace.dependencies] +thaw = { version = "0.2.3", path = "./thaw" } +thaw_utils = { version = "0.0.1", path = "./thaw_utils" } diff --git a/thaw/Cargo.toml b/thaw/Cargo.toml index 846f115..0f8812a 100644 --- a/thaw/Cargo.toml +++ b/thaw/Cargo.toml @@ -14,7 +14,7 @@ license = "MIT" [dependencies] leptos = { version = "0.6.9" } -leptos_meta = { version = "0.6.9", optional = true } +thaw_utils = { workspace = true } web-sys = { version = "0.3.69", features = [ "DomRect", "File", @@ -30,6 +30,6 @@ chrono = "0.4.35" palette = "0.7.5" [features] -csr = ["leptos/csr"] -ssr = ["leptos/ssr", "leptos_meta/ssr"] -hydrate = ["leptos/hydrate"] +csr = ["leptos/csr", "thaw_utils/csr"] +ssr = ["leptos/ssr", "thaw_utils/ssr"] +hydrate = ["leptos/hydrate", "thaw_utils/hydrate"] diff --git a/thaw/src/alert/mod.rs b/thaw/src/alert/mod.rs index d33920e..75cbb98 100644 --- a/thaw/src/alert/mod.rs +++ b/thaw/src/alert/mod.rs @@ -1,14 +1,11 @@ mod theme; -use crate::{ - components::OptionComp, - theme::use_theme, - utils::{class_list::class_list, mount_style, OptionalProp}, - Icon, Theme, -}; -use leptos::*; pub use theme::AlertTheme; +use crate::{components::OptionComp, theme::use_theme, Icon, Theme}; +use leptos::*; +use thaw_utils::{class_list, mount_style, OptionalProp}; + #[derive(Clone)] pub enum AlertVariant { Success, diff --git a/thaw/src/auto_complete/mod.rs b/thaw/src/auto_complete/mod.rs index 15d0fba..c613aa6 100644 --- a/thaw/src/auto_complete/mod.rs +++ b/thaw/src/auto_complete/mod.rs @@ -1,13 +1,13 @@ mod theme; +pub use theme::AutoCompleteTheme; + use crate::{ components::{Binder, CSSTransition, Follower, FollowerPlacement, FollowerWidth}, - use_theme, - utils::{class_list::class_list, mount_style, Model, OptionalProp, StoredMaybeSignal}, - ComponentRef, Input, InputPrefix, InputRef, InputSuffix, Theme, + use_theme, ComponentRef, Input, InputPrefix, InputRef, InputSuffix, Theme, }; use leptos::*; -pub use theme::AutoCompleteTheme; +use thaw_utils::{class_list, mount_style, Model, OptionalProp, StoredMaybeSignal}; #[derive(Clone, PartialEq)] pub struct AutoCompleteOption { @@ -211,7 +211,13 @@ pub fn AutoComplete( >