diff --git a/Cargo.lock b/Cargo.lock index 0fa3bafc..b74d7be6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3117,6 +3117,7 @@ dependencies = [ "log", "radix-leptos-aspect-ratio", "radix-leptos-label", + "radix-leptos-separator", ] [[package]] @@ -3175,6 +3176,15 @@ dependencies = [ "leptos-typed-fallback-show", ] +[[package]] +name = "radix-leptos-separator" +version = "0.0.2" +dependencies = [ + "leptos", + "leptos-node-ref", + "radix-leptos-primitive", +] + [[package]] name = "radix-leptos-stories" version = "0.0.2" @@ -3188,6 +3198,7 @@ dependencies = [ "radix-leptos-arrow", "radix-leptos-aspect-ratio", "radix-leptos-label", + "radix-leptos-separator", "radix-leptos-visually-hidden", "tailwind_fuse", "web-sys", diff --git a/Cargo.toml b/Cargo.toml index 2a1a59fc..3ad5732c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ members = [ "packages/primitives/leptos/id", "packages/primitives/leptos/label", "packages/primitives/leptos/primitive", + "packages/primitives/leptos/separator", "packages/primitives/leptos/use-controllable-state", "packages/primitives/leptos/use-escape-keydown", "packages/primitives/leptos/use-previous", diff --git a/book-examples/leptos/primitives/Cargo.toml b/book-examples/leptos/primitives/Cargo.toml index 97255b70..c2853e5b 100644 --- a/book-examples/leptos/primitives/Cargo.toml +++ b/book-examples/leptos/primitives/Cargo.toml @@ -20,7 +20,7 @@ radix-leptos-aspect-ratio = { path = "../../../packages/primitives/leptos/aspect # radix-leptos-icons = { path = "../../../packages/icons/leptos", optional = true } radix-leptos-label = { path = "../../../packages/primitives/leptos/label", optional = true } # radix-leptos-progress = { path = "../../../packages/primitives/leptos/progress", optional = true } -# radix-leptos-separator = { path = "../../../packages/primitives/leptos/separator", optional = true } +radix-leptos-separator = { path = "../../../packages/primitives/leptos/separator", optional = true } # radix-leptos-switch = { path = "../../../packages/primitives/leptos/switch", optional = true } # radix-leptos-toggle = { path = "../../../packages/primitives/leptos/toggle", optional = true } @@ -40,12 +40,11 @@ avatar = [] checkbox = [] label = ["dep:radix-leptos-label"] progress = [] -separator = [] +separator = ["dep:radix-leptos-separator"] switch = [] toggle = [] # avatar = ["dep:radix-leptos-avatar"] # checkbox = ["dep:radix-leptos-checkbox", "dep:radix-leptos-icons"] # progress = ["dep:radix-leptos-progress"] -# separator = ["dep:radix-leptos-separator"] # switch = ["dep:radix-leptos-switch"] # toggle = ["dep:radix-leptos-toggle", "dep:radix-leptos-icons"] diff --git a/book-examples/leptos/primitives/src/main.rs b/book-examples/leptos/primitives/src/main.rs index 43c1a85c..dc7c8c0b 100644 --- a/book-examples/leptos/primitives/src/main.rs +++ b/book-examples/leptos/primitives/src/main.rs @@ -10,8 +10,8 @@ mod aspect_ratio; mod label; // #[cfg(feature = "progress")] // mod progress; -// #[cfg(feature = "separator")] -// mod separator; +#[cfg(feature = "separator")] +mod separator; // #[cfg(feature = "switch")] // mod switch; // #[cfg(feature = "toggle")] diff --git a/book-examples/leptos/primitives/src/separator.rs b/book-examples/leptos/primitives/src/separator.rs index 5f37e8b8..0631b048 100644 --- a/book-examples/leptos/primitives/src/separator.rs +++ b/book-examples/leptos/primitives/src/separator.rs @@ -1,4 +1,4 @@ -use leptos::*; +use leptos::prelude::*; use radix_leptos_separator::*; #[component] diff --git a/packages/primitives/leptos/separator/Cargo.toml b/packages/primitives/leptos/separator/Cargo.toml index 2a5ba5f5..b4d5cdef 100644 --- a/packages/primitives/leptos/separator/Cargo.toml +++ b/packages/primitives/leptos/separator/Cargo.toml @@ -11,3 +11,5 @@ version.workspace = true [dependencies] leptos.workspace = true +leptos-node-ref.workspace = true +radix-leptos-primitive = { path = "../primitive", version = "0.0.2" } diff --git a/packages/primitives/leptos/separator/src/separator.rs b/packages/primitives/leptos/separator/src/separator.rs index de12af6f..ce5e2574 100644 --- a/packages/primitives/leptos/separator/src/separator.rs +++ b/packages/primitives/leptos/separator/src/separator.rs @@ -1,6 +1,8 @@ use std::fmt::{Display, Formatter}; -use leptos::{html::AnyElement, *}; +use leptos::{html, prelude::*}; +use leptos_node_ref::AnyNodeRef; +use radix_leptos_primitive::Primitive; #[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] pub enum Orientation { @@ -22,61 +24,36 @@ impl Display for Orientation { } } -impl IntoAttribute for Orientation { - fn into_attribute(self) -> Attribute { - Attribute::String(self.to_string().into()) - } - - fn into_attribute_boxed(self: Box) -> Attribute { - self.into_attribute() - } -} - #[component] pub fn Separator( #[prop(into, optional)] orientation: MaybeProp, #[prop(into, optional)] decorative: MaybeProp, #[prop(into, optional)] as_child: MaybeProp, - #[prop(optional)] node_ref: NodeRef, - #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>, + #[prop(into, optional)] node_ref: AnyNodeRef, #[prop(optional)] children: Option, ) -> impl IntoView { let children = StoredValue::new(children); let orientation = Signal::derive(move || orientation.get().unwrap_or_default()); - let aria_orientation = Signal::derive(move || match orientation.get() { - Orientation::Horizontal => None, - Orientation::Vertical => Some("vertical".to_string()), - }); let decorative = Signal::derive(move || decorative.get().unwrap_or_default()); - let mut attrs = attrs.clone(); - attrs.extend([ - ("data-orientation", orientation.into_attribute()), - ( - "aria-orientation", - (match decorative.get() { - true => aria_orientation.get(), - false => None, - }) - .into_attribute(), - ), - ( - "role", - (match decorative.get() { - true => "none", - false => "separator", - }) - .into_attribute(), - ), - ]); - view! { Some("vertical".to_owned()), + Orientation::Horizontal => None, + } + } + } + attr:role=move || if decorative.get() { "none" } else { "separator" } > {children.with_value(|children| children.as_ref().map(|children| children()))} diff --git a/stories/leptos/Cargo.toml b/stories/leptos/Cargo.toml index b56a152e..d8dea39f 100644 --- a/stories/leptos/Cargo.toml +++ b/stories/leptos/Cargo.toml @@ -30,7 +30,7 @@ radix-leptos-label = { path = "../../packages/primitives/leptos/label" } # ] } # radix-leptos-presence = { path = "../../packages/primitives/leptos/presence" } # radix-leptos-progress = { path = "../../packages/primitives/leptos/progress" } -# radix-leptos-separator = { path = "../../packages/primitives/leptos/separator" } +radix-leptos-separator = { path = "../../packages/primitives/leptos/separator" } # radix-leptos-switch = { path = "../../packages/primitives/leptos/switch" } # radix-leptos-toggle = { path = "../../packages/primitives/leptos/toggle" } radix-leptos-visually-hidden = { path = "../../packages/primitives/leptos/visually-hidden" } diff --git a/stories/leptos/src/app.rs b/stories/leptos/src/app.rs index 7d0b1dc3..b4320c4d 100644 --- a/stories/leptos/src/app.rs +++ b/stories/leptos/src/app.rs @@ -4,7 +4,7 @@ use leptos_router::{ path, }; -use crate::primitives::{accessible_icon, arrow, aspect_ratio, label, visually_hidden}; +use crate::primitives::{accessible_icon, arrow, aspect_ratio, label, separator, visually_hidden}; #[component] fn NavLink(href: H, children: Children) -> impl IntoView @@ -160,13 +160,13 @@ pub fn App() -> impl IntoView { //
  • Chromatic
  • // // - //
  • - // Separator +
  • + Separator - //
      - //
    • Styled
    • - //
    - //
  • +
      +
    • Styled
    • +
    + //
  • // Slot @@ -267,7 +267,7 @@ pub fn App() -> impl IntoView { // // - // + // // diff --git a/stories/leptos/src/primitives.rs b/stories/leptos/src/primitives.rs index 4af00626..43a1e6cd 100644 --- a/stories/leptos/src/primitives.rs +++ b/stories/leptos/src/primitives.rs @@ -12,7 +12,7 @@ pub mod label; // pub mod portal; // pub mod presence; // pub mod progress; -// pub mod separator; +pub mod separator; // pub mod slot; // pub mod switch; // pub mod toggle; diff --git a/stories/leptos/src/primitives/separator.rs b/stories/leptos/src/primitives/separator.rs index 536431ee..5242e2e0 100644 --- a/stories/leptos/src/primitives/separator.rs +++ b/stories/leptos/src/primitives/separator.rs @@ -1,4 +1,4 @@ -use leptos::*; +use leptos::prelude::*; use radix_leptos_separator::*; use tailwind_fuse::*;