From 0bf842536fefaa5832177be07823a8657046fc38 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Sun, 23 Jun 2024 23:33:09 +0800 Subject: [PATCH] refactor: Textarea --- demo/src/app.rs | 1 + demo/src/pages/components.rs | 4 ++ demo_markdown/docs/input/mod.md | 3 - demo_markdown/docs/textarea/mod.md | 26 +++++++ demo_markdown/src/lib.rs | 1 + thaw/src/input/mod.rs | 6 -- thaw/src/input/theme.rs | 35 ---------- thaw/src/lib.rs | 6 +- thaw/src/textarea/mod.rs | 106 +++++++++++++++++++++++++++++ thaw/src/textarea/textarea.css | 95 ++++++++++++++++++++++++++ thaw/src/theme/mod.rs | 8 +-- 11 files changed, 239 insertions(+), 52 deletions(-) create mode 100644 demo_markdown/docs/textarea/mod.md delete mode 100644 thaw/src/input/theme.rs create mode 100644 thaw/src/textarea/mod.rs create mode 100644 thaw/src/textarea/textarea.css diff --git a/demo/src/app.rs b/demo/src/app.rs index 5b8b81d..01c5978 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -86,6 +86,7 @@ fn TheRouter(is_routing: RwSignal) -> impl IntoView { + diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index d5fb3a3..72f4338 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -199,6 +199,10 @@ pub(crate) fn gen_menu_data() -> Vec { value: "/components/text".into(), label: "Text".into(), }, + MenuItemOption { + value: "/components/textarea".into(), + label: "Textarea".into(), + }, MenuItemOption { value: "/components/auto-complete".into(), label: "Auto Complete".into(), diff --git a/demo_markdown/docs/input/mod.md b/demo_markdown/docs/input/mod.md index 2115557..da8d71f 100644 --- a/demo_markdown/docs/input/mod.md +++ b/demo_markdown/docs/input/mod.md @@ -7,7 +7,6 @@ view! { - + + } +} + +#[derive(Clone)] +pub struct TextAreaRef { + textarea_ref: NodeRef, +} + +impl TextAreaRef { + pub fn focus(&self) { + if let Some(textarea_el) = self.textarea_ref.get_untracked() { + _ = textarea_el.focus(); + } + } + + pub fn blur(&self) { + if let Some(textarea_el) = self.textarea_ref.get_untracked() { + _ = textarea_el.blur(); + } + } +} diff --git a/thaw/src/textarea/textarea.css b/thaw/src/textarea/textarea.css new file mode 100644 index 0000000..c2341e0 --- /dev/null +++ b/thaw/src/textarea/textarea.css @@ -0,0 +1,95 @@ +.thaw-textarea { + position: relative; + display: inline-flex; + margin: 0px; + padding: 0 0 var(--strokeWidthThick) 0; + background-color: var(--colorNeutralBackground1); + border-radius: var(--borderRadiusMedium); + border-bottom-color: var(--colorNeutralStrokeAccessible); + border: var(--strokeWidthThin) solid var(--colorNeutralStroke1); + box-sizing: border-box; +} + +.thaw-textarea:focus-within { + border-bottom-color: var(--colorCompoundBrandStroke); + outline-width: var(--strokeWidthThick); + outline-color: transparent; + outline-style: solid; + border: var(--strokeWidthThin) solid var(--colorNeutralStroke1); +} + +.thaw-textarea:hover { + border: var(--strokeWidthThin) solid var(--colorNeutralStroke1Hover); + border-bottom-color: var(--colorNeutralStrokeAccessibleHover); +} + +.thaw-textarea:active { + border: var(--strokeWidthThin) solid var(--colorNeutralStroke1Pressed); + border-bottom-color: var(--colorNeutralStrokeAccessiblePressed); +} + +/* .thaw-textarea--focus, +.thaw-textarea:hover:not(.thaw-textarea--disabled, .thaw-textarea--invalid) { + border-color: var(--thaw-border-color-hover); +} + +.thaw-textarea--disabled, +.thaw-textarea--disabled .thaw-textarea__textarea-el { + cursor: not-allowed; + background-color: var(--thaw-background-color-disabled); + color: var(--thaw-font-color-disabled); +} */ + +.thaw-textarea::after { + content: ""; + position: absolute; + bottom: -1px; + right: -1px; + left: -1px; + height: max(var(--strokeWidthThick), var(--borderRadiusMedium)); + border-bottom-right-radius: var(--borderRadiusMedium); + border-bottom-left-radius: var(--borderRadiusMedium); + box-sizing: border-box; + border-bottom: var(--strokeWidthThick) solid var(--colorCompoundBrandStroke); + transition-delay: var(--curveAccelerateMid); + transition-duration: var(--durationUltraFast); + transition-property: transform; + transform: scaleX(0); + clip-path: inset(calc(100% - var(--strokeWidthThick)) 0 0 0); +} + +.thaw-textarea:focus-within::after { + transition-delay: var(--curveDecelerateMid); + transition-duration: var(--durationNormal); + transition-property: transform; + transform: scaleX(1); +} + +.thaw-textarea:focus-within:active::after { + border-bottom-color: var(--colorCompoundBrandStrokePressed); +} + +.thaw-textarea__textarea { + flex-grow: 1; + height: 100%; + max-height: 260px; + min-height: 52px; + + margin: 0px; + padding: var(--spacingVerticalSNudge) + calc(var(--spacingHorizontalMNudge) + var(--spacingHorizontalXXS)); + outline-style: none; + background-color: transparent; + color: var(--colorNeutralForeground1); + line-height: var(--lineHeightBase300); + font-weight: var(--fontWeightRegular); + font-size: var(--fontSizeBase300); + font-family: var(--fontFamilyBase); + border-style: none; + box-sizing: border-box; + resize: none; +} + +.thaw-textarea__textarea-el::placeholder { + color: var(--thaw-placeholder-color); +} diff --git a/thaw/src/theme/mod.rs b/thaw/src/theme/mod.rs index cb21dd8..11a7d63 100644 --- a/thaw/src/theme/mod.rs +++ b/thaw/src/theme/mod.rs @@ -4,9 +4,8 @@ mod common; use self::common::CommonTheme; use crate::{ mobile::{NavBarTheme, TabbarTheme}, - AlertTheme, AnchorTheme, BackTopTheme, CalendarTheme, DatePickerTheme, - InputTheme, MessageTheme, ProgressTheme, ScrollbarTheme, SelectTheme, TimePickerTheme, - UploadTheme, + AlertTheme, AnchorTheme, BackTopTheme, CalendarTheme, DatePickerTheme, MessageTheme, + ProgressTheme, ScrollbarTheme, SelectTheme, TimePickerTheme, UploadTheme, }; pub use color::ColorTheme; use leptos::*; @@ -21,7 +20,6 @@ pub struct Theme { pub name: String, pub common: CommonTheme, pub color: ColorTheme, - pub input: InputTheme, pub alert: AlertTheme, pub message: MessageTheme, pub select: SelectTheme, @@ -43,7 +41,6 @@ impl Theme { name: "light".into(), common: CommonTheme::light(), color: ColorTheme::light(), - input: InputTheme::light(), alert: AlertTheme::light(), message: MessageTheme::light(), select: SelectTheme::light(), @@ -64,7 +61,6 @@ impl Theme { name: "dark".into(), common: CommonTheme::dark(), color: ColorTheme::dark(), - input: InputTheme::dark(), alert: AlertTheme::dark(), message: MessageTheme::dark(), select: SelectTheme::dark(),