From bacda05edc3d99d5ac89b8708383e5f968360cc3 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Mon, 3 Jun 2024 16:31:32 +0800 Subject: [PATCH] feat: text adds style prop --- demo/src/app.rs | 2 +- demo/src/pages/components.rs | 45 ++------ demo_markdown/docs/card/mod.md | 2 +- .../docs/{typography => text}/mod.md | 3 + demo_markdown/src/lib.rs | 2 +- thaw/src/text/mod.rs | 108 ++++++++++++++---- 6 files changed, 102 insertions(+), 60 deletions(-) rename demo_markdown/docs/{typography => text}/mod.md (84%) diff --git a/demo/src/app.rs b/demo/src/app.rs index 2257723..37d666f 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -85,8 +85,8 @@ fn TheRouter(is_routing: RwSignal) -> impl IntoView { + - diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index 1577307..2a6a35f 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -75,10 +75,9 @@ pub(crate) struct MenuGroupOption { impl IntoView for MenuGroupOption { fn into_view(self) -> View { let Self { label, children } = self; - let children_len = children.len(); view! { - - {format!("{label} ({children_len})")} + + {label} {children.into_iter().map(|v| v.into_view()).collect_view()} } @@ -169,18 +168,13 @@ pub(crate) fn gen_menu_data() -> Vec { label: "Tag".into(), }, MenuItemOption { - value: "/components/typography".into(), - label: "Typography".into(), + value: "/components/text".into(), + label: "Text".into(), }, MenuItemOption { value: "/components/spin-button".into(), label: "Spin Button".into(), }, - ], - }, - MenuGroupOption { - label: "Data Input Components".into(), - children: vec![ MenuItemOption { value: "/components/auto-complete".into(), label: "Auto Complete".into(), @@ -225,11 +219,6 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/upload".into(), label: "Upload".into(), }, - ], - }, - MenuGroupOption { - label: "Data Display Components".into(), - children: vec![ MenuItemOption { value: "/components/calendar".into(), label: "Calendar".into(), @@ -242,11 +231,6 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/table".into(), label: "Table".into(), }, - ], - }, - MenuGroupOption { - label: "Navigation Components".into(), - children: vec![ MenuItemOption { value: "/components/anchor".into(), label: "Anchor".into(), @@ -267,11 +251,6 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/tabs".into(), label: "Tabs".into(), }, - ], - }, - MenuGroupOption { - label: "Feedback Components".into(), - children: vec![ MenuItemOption { value: "/components/alert".into(), label: "Alert".into(), @@ -308,11 +287,6 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/skeleton".into(), label: "Skeleton".into(), }, - ], - }, - MenuGroupOption { - label: "Layout Components".into(), - children: vec![ MenuItemOption { value: "/components/layout".into(), label: "Layout".into(), @@ -325,15 +299,12 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/space".into(), label: "Space".into(), }, + MenuItemOption { + value: "/components/scrollbar".into(), + label: "Scrollbar".into(), + }, ], }, - MenuGroupOption { - label: "Utility Components".into(), - children: vec![MenuItemOption { - value: "/components/scrollbar".into(), - label: "Scrollbar".into(), - }], - }, MenuGroupOption { label: "Mobile Components".into(), children: vec![ diff --git a/demo_markdown/docs/card/mod.md b/demo_markdown/docs/card/mod.md index ba6962f..c00115a 100644 --- a/demo_markdown/docs/card/mod.md +++ b/demo_markdown/docs/card/mod.md @@ -5,7 +5,7 @@ view! { - "Header""2022-02-22" + "Header"" 2022-02-22" "Description" diff --git a/demo_markdown/docs/typography/mod.md b/demo_markdown/docs/text/mod.md similarity index 84% rename from demo_markdown/docs/typography/mod.md rename to demo_markdown/docs/text/mod.md index 2f4f6c2..8af48bf 100644 --- a/demo_markdown/docs/typography/mod.md +++ b/demo_markdown/docs/text/mod.md @@ -5,6 +5,9 @@ view! { "text" "code" + "Caption1" + "Caption1Strong" + "Body1" } ``` diff --git a/demo_markdown/src/lib.rs b/demo_markdown/src/lib.rs index 6b3329e..9a4b6cb 100644 --- a/demo_markdown/src/lib.rs +++ b/demo_markdown/src/lib.rs @@ -68,7 +68,7 @@ pub fn include_md(_token_stream: proc_macro::TokenStream) -> proc_macro::TokenSt "TabsMdPage" => "../docs/tabs/mod.md", "TagMdPage" => "../docs/tag/mod.md", "TimePickerMdPage" => "../docs/time_picker/mod.md", - "TypographyMdPage" => "../docs/typography/mod.md", + "TextMdPage" => "../docs/text/mod.md", "UploadMdPage" => "../docs/upload/mod.md" }; diff --git a/thaw/src/text/mod.rs b/thaw/src/text/mod.rs index da1605f..7861e52 100644 --- a/thaw/src/text/mod.rs +++ b/thaw/src/text/mod.rs @@ -4,45 +4,52 @@ use thaw_utils::{class_list, mount_style}; #[component] pub fn Caption1( #[prop(optional, into)] class: MaybeProp, + #[prop(optional, into)] style: MaybeProp, #[prop(optional)] tag: TextTag, children: Children, ) -> impl IntoView { - let class = Signal::derive(move || format!("thaw-caption-1 {:?}", class.get())); + let class = + Signal::derive(move || format!("thaw-caption-1 {}", class.get().unwrap_or_default())); view! { - + } } #[component] pub fn Caption1Strong( #[prop(optional, into)] class: MaybeProp, + #[prop(optional, into)] style: MaybeProp, #[prop(optional)] tag: TextTag, children: Children, ) -> impl IntoView { - let class = Signal::derive(move || format!("thaw-caption-1-strong {:?}", class.get())); + let class = Signal::derive(move || { + format!("thaw-caption-1-strong {}", class.get().unwrap_or_default()) + }); view! { - + } } #[component] pub fn Body1( #[prop(optional, into)] class: MaybeProp, + #[prop(optional, into)] style: MaybeProp, #[prop(optional)] tag: TextTag, children: Children, ) -> impl IntoView { - let class = Signal::derive(move || format!("thaw-body-1 {:?}", class.get())); + let class = Signal::derive(move || format!("thaw-body-1 {}", class.get().unwrap_or_default())); view! { - + } } #[component] pub fn Text( #[prop(optional, into)] class: MaybeProp, + #[prop(optional, into)] style: MaybeProp, #[prop(optional)] tag: TextTag, #[prop(optional)] code: bool, children: Children, @@ -50,23 +57,84 @@ pub fn Text( mount_style("text", include_str!("./text.css")); match tag { - TextTag::B => todo!(), - TextTag::Em => todo!(), - TextTag::H1 => todo!(), - TextTag::H2 => todo!(), - TextTag::H3 => todo!(), - TextTag::H4 => todo!(), - TextTag::H5 => todo!(), - TextTag::H6 => todo!(), - TextTag::I => todo!(), - TextTag::P => todo!(), - TextTag::Pre => todo!(), + TextTag::B => view! { + + {children()} + + } + .into_view(), + TextTag::Em => view! { + + {children()} + + } + .into_view(), + TextTag::H1 => view! { +

+ {children()} +

+ } + .into_view(), + TextTag::H2 => view! { +

+ {children()} +

+ } + .into_view(), + TextTag::H3 => view! { +

+ {children()} +

+ } + .into_view(), + TextTag::H4 => view! { +

+ {children()} +

+ } + .into_view(), + TextTag::H5 => view! { +
+ {children()} +
+ } + .into_view(), + TextTag::H6 => view! { +
+ {children()} +
+ } + .into_view(), + TextTag::I => view! { + + {children()} + + } + .into_view(), + TextTag::P => view! { +

+ {children()} +

+ } + .into_view(), + TextTag::Pre => view! { +
+                {children()}
+            
+ } + .into_view(), TextTag::Span => view! { - + {children()} - }, - TextTag::Strong => todo!(), + } + .into_view(), + TextTag::Strong => view! { + + {children()} + + } + .into_view(), } }