dioxus_ui_system/molecules/
separator.rs1use crate::styles::Style;
6use crate::theme::{use_style, use_theme};
7use dioxus::prelude::*;
8
9#[derive(Default, Clone, PartialEq)]
11pub enum SeparatorOrientation {
12 #[default]
14 Horizontal,
15 Vertical,
17}
18
19#[derive(Props, Clone, PartialEq)]
21pub struct SeparatorProps {
22 #[props(default)]
24 pub orientation: SeparatorOrientation,
25 #[props(default = true)]
27 pub decorative: bool,
28 #[props(default)]
30 pub style: Option<String>,
31 #[props(default)]
33 pub class: Option<String>,
34}
35
36#[component]
38pub fn Separator(props: SeparatorProps) -> Element {
39 let _theme = use_theme();
40
41 let is_horizontal = props.orientation == SeparatorOrientation::Horizontal;
42
43 let separator_style = use_style(move |t| {
44 if is_horizontal {
45 Style::new()
46 .w_full()
47 .h_px(1)
48 .bg(&t.colors.border)
49 .my(&t.spacing, "md")
50 .build()
51 } else {
52 Style::new()
53 .w_px(1)
54 .h_full()
55 .bg(&t.colors.border)
56 .mx(&t.spacing, "md")
57 .build()
58 }
59 });
60
61 let aria_props = if props.decorative {
62 "aria-hidden: true;"
63 } else {
64 "role: separator;"
65 };
66
67 let orientation_attr = if is_horizontal {
68 "horizontal"
69 } else {
70 "vertical"
71 };
72
73 rsx! {
74 div {
75 style: "{separator_style} {props.style.clone().unwrap_or_default()} {aria_props}",
76 class: "{props.class.clone().unwrap_or_default()}",
77 aria_orientation: "{orientation_attr}",
78 }
79 }
80}