Edit Component
Adding Accordion RS to your project is simple:
-
Make sure your project is set up with Yew. Refer to their Getting Started Guide for setup instructions.
-
Add the Accordion component to your dependencies by including it in your Cargo.toml
file.
cargo add accordion-rs --features=yew
-
Import the Accordion
component into your Yew component and start using it in your app.
Incorporating Yew Accordion into your application is easy. Follow these steps:
-
Import the Accordion component into your Yew project:
use yew::prelude::*;
use accordion_rs::yew::Accordion;
-
Define the accordion sections and use the Accordion component in your Yew component:
use accordion_rs::yew::{Accordion, Item, List};
use accordion_rs::{Size, Align};
use yew::prelude::*;
#[function_component(App)]
pub fn app() -> Html {
let on_will_open = Callback::from(|_| log::info!("Accordion will open!"));
let on_did_open = Callback::from(|_| log::info!("Accordion did open!"));
let on_will_close = Callback::from(|_| log::info!("Accordion will close!"));
let on_did_close = Callback::from(|_| log::info!("Accordion did close!"));
html! {
<Accordion
size={Size::XLarge}
expanded={html! { <h3>{ "Accordion Expanded" }</h3> }}
collapsed={html! { <h3>{ "Accordion Collapsed" }</h3> }}
class="bg-gray-900 text-gray-300 border border-gray-700 p-4 rounded-lg"
expanded_class="text-white bg-gray-800"
collapsed_class="text-gray-400 bg-gray-800"
did_open={on_did_open.clone()}
will_open={on_will_open.clone()}
did_close={on_did_close.clone()}
will_close={on_will_close.clone()}
>
<List>
<Item align={Align::Left}>{ "Item 1 - Left" }</Item>
<Item align={Align::Right}>{ "Item 2 - Right" }</Item>
</List>
</Accordion>
}
}
Property | Type | Description | Default |
expand | UseStateHandle<bool> | State handle managing whether the accordion is initially expanded or collapsed. | false |
expanded | Html | Content to display when the accordion is expanded. | "" |
collapsed | Html | Content to display when the accordion is collapsed. | "" |
children | Html | Child elements displayed within the accordion container. | "" |
size | Size | Size of the accordion ("small" , "medium" , "large" , etc.). | Size::XXLarge |
duration | u64 | Animation duration for expand/collapse transitions, in milliseconds. | 600 |
+-----------------------------------------------------------+
| [Accordion Container] | <-- `class` & `style`
| |
| +-----------------------------------------------+ | <-- `collapsed_class` & `collapsed_style`
| | [Collapsed Content] | | <-- `collapsed`
| +-----------------------------------------------+ |
| |
| +-----------------------------------------------+ | <-- `expanded_class` & `expanded_style`
| | [Expanded Content] | | <-- `expanded`
| +-----------------------------------------------+ |
| |
| +-----------------------------------------------+ | <-- `content_class` & `content_style`
| | [Accordion Content] | | <-- `children`
| +-----------------------------------------------+ |
| |
+-----------------------------------------------------------+
Property | Type | Description | Default |
class | &'static str | CSS class for the accordion container. | "" |
expanded_class | &'static str | CSS class for the expanded content. | "" |
collapsed_class | &'static str | CSS class for the collapsed content. | "" |
content_class | &'static str | CSS class for the content section. | "" |
style | &'static str | Custom inline styles for the accordion container. | "" |
expanded_style | &'static str | Custom inline styles for the expanded element. | "" |
collapsed_style | &'static str | Custom inline styles for the collapsed element. | "" |
content_style | &'static str | Custom inline styles for the accordion content. | "" |
Property | Type | Description | Default |
will_open | Callback<()> | Callback triggered before the accordion opens. | No-op |
did_open | Callback<()> | Callback triggered after the accordion opens. | No-op |
will_close | Callback<()> | Callback triggered before the accordion closes. | No-op |
did_close | Callback<()> | Callback triggered after the accordion closes. | No-op |
Property | Type | Description | Default |
aria_controls | &'static str | ARIA controls attribute for accessibility. | "" |
aria_enabled | bool | Whether ARIA attributes are enabled for screen reader accessibility. | true |
- Use the
expand
prop to control the open/close state of the accordion programmatically.
- The
size
prop can be customized to adjust the width of the accordion.
- Callback props like
will_open
and did_close
provide hooks to perform actions during the accordion's lifecycle.
- Custom classes and styles allow for extensive customization of the accordion's appearance and behavior.
- ARIA attributes can be enabled/disabled using the
aria_enabled
prop for better screen reader compatibility.
You can import Accordion RS directly into your project to customize and modify it using the opensass cli:
os add accordion-rs yew
Edit Component
Adding Accordion RS to your project is simple:
-
Make sure your project is set up with Dioxus. Refer to the Dioxus Getting Started Guide for setup instructions.
-
Add the Accordion component to your dependencies by including it in your Cargo.toml
file.
cargo add accordion-rs --features=dio
-
Import the Accordion
component into your Dioxus component and start using it in your app.
Incorporating the Accordion component into your application is easy. Follow these steps:
-
Import the Accordion component into your Dioxus project:
use dioxus::prelude::*;
use accordion_rs::dioxus::Accordion;
-
Define the accordion sections and use the Accordion component in your Dioxus app:
use accordion_rs::dioxus::{Accordion, Item, List};
use accordion_rs::{Size, Align};
use dioxus::prelude::*;
pub fn app() -> Element {
let expand = use_signal(|| false);
rsx!(
Accordion {
expand: expand,
size: Size::XLarge,
expanded: rsx!(div { "Accordion Expanded" }),
collapsed: rsx!(div { "Accordion Collapsed" }),
class: "bg-gray-900 text-gray-300 border border-gray-700 p-4 rounded-lg",
expanded_class: "text-white bg-gray-800",
collapsed_class: "text-gray-400 bg-gray-800",
List {
Item { align: Align::Left, "Item 1 - Left" }
Item { align: Align::Right, "Item 2 - Right" }
}
}
)
}
Property | Type | Description | Default |
expand | Signal<bool> | Signal managing whether the accordion is initially expanded or collapsed. | false |
expanded | Element | Content to display when the accordion is expanded. | "" |
collapsed | Element | Content to display when the accordion is collapsed. | "" |
children | Element | Child elements displayed within the accordion container. | "" |
size | Size | Size of the accordion ("small" , "medium" , "large" , etc.). | Size::XXLarge |
duration | u64 | Animation duration for expand/collapse transitions, in milliseconds. | 600 |
+-----------------------------------------------------------+
| [Accordion Container] | <-- `class` & `style`
| |
| +-----------------------------------------------+ | <-- `collapsed_class` & `collapsed_style`
| | [Collapsed Content] | | <-- `collapsed`
| +-----------------------------------------------+ |
| |
| +-----------------------------------------------+ | <-- `expanded_class` & `expanded_style`
| | [Expanded Content] | | <-- `expanded`
| +-----------------------------------------------+ |
| |
| +-----------------------------------------------+ | <-- `content_class` & `content_style`
| | [Accordion Content] | | <-- `children`
| +-----------------------------------------------+ |
| |
+-----------------------------------------------------------+
Property | Type | Description | Default |
class | &'static str | CSS class for the accordion container. | "" |
expanded_class | &'static str | CSS class for the expanded content. | "" |
collapsed_class | &'static str | CSS class for the collapsed content. | "" |
content_class | &'static str | CSS class for the content section. | "" |
style | &'static str | Custom inline styles for the accordion container. | "" |
expanded_style | &'static str | Custom inline styles for the expanded element. | "" |
collapsed_style | &'static str | Custom inline styles for the collapsed element. | "" |
content_style | &'static str | Custom inline styles for the accordion content. | "" |
Property | Type | Description | Default |
will_open | Callback<()> | Callback triggered before the accordion opens. | No-op |
did_open | Callback<()> | Callback triggered after the accordion opens. | No-op |
will_close | Callback<()> | Callback triggered before the accordion closes. | No-op |
did_close | Callback<()> | Callback triggered after the accordion closes. | No-op |
Property | Type | Description | Default |
aria_controls | &'static str | ARIA controls attribute for accessibility. | "" |
aria_enabled | bool | Whether ARIA attributes are enabled for screen reader accessibility. | true |
- Use the
expand
prop to control the open/close state of the accordion programmatically.
- The
size
prop can be customized to adjust the width of the accordion.
- Callback props like
will_open
and did_close
provide hooks to perform actions during the accordion's lifecycle.
- Custom classes and styles allow for extensive customization of the accordion's appearance and behavior.
- ARIA attributes can be enabled/disabled using the
aria_enabled
prop for better screen reader compatibility.
You can import Accordion RS directly into your project to customize and modify it using the opensass cli:
os add accordion-rs dio
Edit Component
Adding Accordion RS to your Leptos project is simple:
-
Make sure your project is set up with Leptos. Refer to their Getting Started Guide for setup instructions.
-
Add accordion-rs
to your dependencies:
cargo add accordion-rs --features=lep
-
Import the Accordion
component into your Leptos component and start using it in your app.
The following is an example of using the Accordion in a Leptos project:
use leptos::prelude::*;
use accordion_rs::leptos::{Accordion, List, Item};
use accordion_rs::Align;
#[component]
pub fn App() -> impl IntoView {
let expanded = signal(false);
view! {
<Accordion
expand={expanded}
expanded={Box::new(|| view! { <h3>{ "Accordion Expanded" }</h3> }.into_any())}
collapsed={Box::new(|| view! { <h3>{ "Accordion Collapsed" }</h3> }.into_any())}
>
<List>
<Item align={Align::Left}>{ "Item 1 - Left" }</Item>
<Item align={Align::Right}>{ "Item 2 - Right" }</Item>
</List>
</Accordion>
}
}
You can also attach lifecycle callbacks to handle events during the accordion's state changes.
use leptos::prelude::*;
use leptos::logging::log;
use accordion_rs::leptos::{Accordion, List, Item};
#[component]
pub fn App() -> impl IntoView {
let expanded = signal(false);
let will_open = move || log!("Accordion will open.");
let did_open = move || log!("Accordion has opened.");
let will_close = move || log!("Accordion will close.");
let did_close = move || log!("Accordion has closed.");
view! {
<Accordion
expand={expanded}
expanded={Box::new(|| view! { <p>"Expanded Content"</p> }.into_any())}
collapsed={Box::new(|| view! { <p>"Collapsed Content"</p> }.into_any())}
will_open={Callback::from(will_open)}
did_open={Callback::from(did_open)}
will_close={Callback::from(will_close)}
did_close={Callback::from(did_close)}
>
<List>
<Item>{ "Logging Accordion Lifecycle Events" }</Item>
</List>
</Accordion>
}
}
Property | Type | Description | Default |
expand | (ReadSignal<bool>, WriteSignal<bool>) | Tracks and updates the accordion's open/close state. | false |
expanded | Box<dyn Fn() -> AnyView> | Content to render when the accordion is expanded. | None |
collapsed | Box<dyn Fn() -> AnyView> | Content to render when the accordion is collapsed. | None |
children | Children | Additional elements to display within the accordion. | None |
size | Size | Defines the size of the accordion (Small , Medium , Large , etc.). | Size::XXLarge |
duration | u64 | Animation duration for expand/collapse transitions (in milliseconds). | 600 |
Property | Type | Description | Default |
class | &'static str | CSS class for the accordion container. | "" |
expanded_class | &'static str | CSS class for the expanded accordion state. | "" |
collapsed_class | &'static str | CSS class for the collapsed accordion state. | "" |
content_class | &'static str | CSS class for the accordion's content container. | "" |
style | &'static str | Inline styles for the accordion container. | "" |
expanded_style | &'static str | Inline styles for the expanded accordion state. | "" |
collapsed_style | &'static str | Inline styles for the collapsed accordion state. | "" |
Property | Type | Description | Default |
will_open | Callback<()> | Invoked when the accordion begins opening. | No-op |
did_open | Callback<()> | Invoked after the accordion has opened. | No-op |
will_close | Callback<()> | Invoked when the accordion begins closing. | No-op |
did_close | Callback<()> | Invoked after the accordion has closed. | No-op |
Property | Type | Description | Default |
aria_controls | &'static str | ARIA controls attribute for accessibility. | "" |
aria_enabled | bool | Whether ARIA attributes are enabled for screen readers. | true |
- Use the
expand
prop signal to control the open/close state of the accordion programmatically.
- The
size
prop can be customized to adjust the width of the accordion.
- Callback props like
will_open
and did_close
provide hooks to perform actions during the accordion's lifecycle.
- Custom classes and styles allow for extensive customization of the accordion's appearance and behavior.
- ARIA attributes can be enabled/disabled using the
aria_enabled
prop for better screen reader compatibility.
You can import Accordion RS directly into your project to customize and modify it using the opensass cli:
os add accordion-rs lep