use topcoat::{
Result,
view::{Attributes, PromotedStr, StaticClass, View, class, component, view},
};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum SeparatorOrientation {
#[default]
Horizontal,
Vertical,
}
impl SeparatorOrientation {
fn classes(self) -> StaticClass {
match self {
Self::Horizontal => class!("h-px w-full"),
Self::Vertical => class!("h-full w-px"),
}
}
fn aria(self) -> Option<PromotedStr> {
match self {
Self::Horizontal => None,
Self::Vertical => Some(PromotedStr(&"vertical")),
}
}
}
const SEPARATOR: StaticClass = class!("shrink-0 border-0 bg-border");
#[component]
pub async fn separator(
#[default]
orientation: SeparatorOrientation,
#[default]
mut attrs: Attributes,
) -> Result<impl View> {
Ok(view! {
<hr
class=(class!(SEPARATOR, orientation.classes(), attrs.remove("class")))
aria-orientation=(orientation.aria())
(attrs)
>
})
}