From 5dc62c8244053dc0305ba57ebda38a1f0f5c6527 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Thu, 18 Jul 2024 21:54:13 +0800 Subject: [PATCH] feat: AccordionItem adds icon --- demo_markdown/docs/accordion/mod.md | 47 ++++++++++++++++++++++++++- thaw/src/accordion/accordion-item.css | 17 ++++++++-- thaw/src/accordion/accordion_item.rs | 22 ++++++++++++- thaw/src/accordion/mod.rs | 2 +- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/demo_markdown/docs/accordion/mod.md b/demo_markdown/docs/accordion/mod.md index 79a89ba..9def26c 100644 --- a/demo_markdown/docs/accordion/mod.md +++ b/demo_markdown/docs/accordion/mod.md @@ -1,7 +1,6 @@ # Accordion ```rust demo - view! { @@ -18,4 +17,50 @@ view! { } +``` + +### Collapsible + +An accordion can have multiple panels collapsed at the same time. + +```rust demo +view! { + + + + "Leptos" + + "Build fast web applications with Rust." + + + + "Thaw" + + "An easy to use leptos component library" + + +} +``` + +### Multiple + +An accordion supports multiple panels expanded simultaneously. Since it's not simple to determine which panel will be opened by default, multiple will also be collapsed by default on the first render. + +```rust demo +view! { + + + + "Leptos" + + "Build fast web applications with Rust." + + + + "Thaw" + + "An easy to use leptos component library" + + +} ``` \ No newline at end of file diff --git a/thaw/src/accordion/accordion-item.css b/thaw/src/accordion/accordion-item.css index e9c7b69..5ce6ccf 100644 --- a/thaw/src/accordion/accordion-item.css +++ b/thaw/src/accordion/accordion-item.css @@ -29,11 +29,24 @@ cursor: pointer; } +.thaw-accordion-header__expand-icon { + display: flex; + align-items: center; + height: 100%; + padding-right: var(--spacingHorizontalS); + font-size: var(--fontSizeBase500); + line-height: var(--lineHeightBase500); +} + +.thaw-accordion-header__expand-icon > svg { + display: inline; + line-height: 0; +} + .thaw-accordion-panel { margin: 0 var(--spacingHorizontalM); } - .thaw-accordion-panel-enter-from, .thaw-accordion-panel-enter-to { opacity: 1; @@ -57,4 +70,4 @@ transition: max-height 0.15s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.15s cubic-bezier(0.4, 0, 1, 1), padding-top 0.15s cubic-bezier(0.4, 0, 0.2, 1); -} \ No newline at end of file +} diff --git a/thaw/src/accordion/accordion_item.rs b/thaw/src/accordion/accordion_item.rs index cfe0325..412c5ef 100644 --- a/thaw/src/accordion/accordion_item.rs +++ b/thaw/src/accordion/accordion_item.rs @@ -5,6 +5,7 @@ use thaw_utils::{mount_style, update, with, StoredMaybeSignal}; #[component] pub fn AccordionItem( + /// Required value that identifies this item inside an Accordion component. #[prop(into)] value: MaybeSignal, accordion_header: AccordionHeader, children: Children, @@ -14,7 +15,7 @@ pub fn AccordionItem( open_items, multiple, collapsible, - } = AccordionInjection::use_(); + } = AccordionInjection::expect_context(); let panel_ref = NodeRef::::new(); let value: StoredMaybeSignal<_> = value.into(); @@ -47,6 +48,25 @@ pub fn AccordionItem( type="button" on:click=on_click > + {(accordion_header.children)()} diff --git a/thaw/src/accordion/mod.rs b/thaw/src/accordion/mod.rs index 2a3f188..4839dae 100644 --- a/thaw/src/accordion/mod.rs +++ b/thaw/src/accordion/mod.rs @@ -40,7 +40,7 @@ pub(crate) struct AccordionInjection { } impl AccordionInjection { - pub fn use_() -> AccordionInjection { + pub fn expect_context() -> AccordionInjection { expect_context() } }