() else { return };
+ if disabled {
+ let _ = el.set_attribute("aria-disabled", "true");
+ } else {
+ let _ = el.remove_attribute("aria-disabled");
+ }
+}
diff --git a/app_crates/registry/src/ui/card_carousel.rs b/app_crates/registry/src/ui/card_carousel.rs
index 6be26f6..71ca3e4 100644
--- a/app_crates/registry/src/ui/card_carousel.rs
+++ b/app_crates/registry/src/ui/card_carousel.rs
@@ -1,6 +1,9 @@
use leptos::prelude::*;
use leptos_ui::{clx, void};
+#[cfg(target_arch = "wasm32")]
+use crate::hooks::use_card_carousel;
+
mod components {
use super::*;
clx! {CardCarousel, div, "group rounded-[20px] overflow-hidden relative w-[320px] h-[320px] bg-gray-200"}
@@ -21,6 +24,9 @@ pub use components::*;
#[component]
pub fn CardCarouselTrack(children: Children) -> impl IntoView {
+ #[cfg(target_arch = "wasm32")]
+ use_card_carousel::init();
+
view! {
{
- const btn = e.target.closest('[data-name="CardCarouselNavButton"]');
- if (!btn) return;
-
- // Allows to wrap in a `a` tag and prevent the navigation when clicking NavButton.
- e.stopPropagation();
- e.preventDefault();
-
- const root = btn.closest('[data-name="CardCarousel"]');
- const carousel = root.querySelector('[data-name="CardCarouselTrack"]');
- const buttons = root.querySelectorAll('[data-name="CardCarouselNavButton"]');
- const isPrev = btn === buttons[0];
-
- carousel.scrollBy({ left: carousel.clientWidth * (isPrev ? -1 : 1) });
-});
-
-// * Event delegation for all carousel scroll events (using capture phase)
-document.addEventListener(
- "scroll",
- (e) => {
- const carousel = e.target.closest('[data-name="CardCarouselTrack"]');
- if (!carousel) return;
-
- const root = carousel.closest('[data-name="CardCarousel"]');
- const indicators = root.querySelectorAll('[data-name="CardCarouselIndicator"]');
- const buttons = root.querySelectorAll('[data-name="CardCarouselNavButton"]');
-
- const index = Math.round(carousel.scrollLeft / carousel.clientWidth);
- indicators.forEach((dot, i) => dot.toggleAttribute("aria-current", i === index));
- buttons[0].toggleAttribute("aria-disabled", index === 0);
- buttons[1].toggleAttribute("aria-disabled", index === indicators.length - 1);
- },
- true,
-);
diff --git a/public/registry/styles/default/demo_card_carousel.md b/public/registry/styles/default/demo_card_carousel.md
index cba9af9..8e7b8b6 100644
--- a/public/registry/styles/default/demo_card_carousel.md
+++ b/public/registry/styles/default/demo_card_carousel.md
@@ -81,8 +81,6 @@ pub fn DemoCardCarousel() -> impl IntoView {
"$685 per night"
-
-
}
}
diff --git a/public/registry/tree.md b/public/registry/tree.md
index ffed3d6..731c559 100644
--- a/public/registry/tree.md
+++ b/public/registry/tree.md
@@ -347,7 +347,6 @@ Each dependency level is shown with progressive bullet points: * for components,
** card (ui)
* demo_card_carousel (demos)
** cargo: icons/leptos
- ** js: /components/card_carousel.js
** card (ui)
** card_carousel (ui)
* demo_card_group (demos)