use leptos::{either::EitherOf3, prelude::*};
use orbital_macros::component_doc;
use orbital_style::inject_style;
const CODE_CSS: &str = include_str!("code.css");
#[component_doc(
category = "Typography",
preview_slug = "code",
preview_label = "Code",
preview_icon = icondata::AiCodeOutlined,
)]
#[component]
pub fn Code(
#[prop(optional, into)]
class: MaybeProp<String>,
#[prop(optional, into)]
text: Option<String>,
#[prop(optional, into)]
inner_html: Option<String>,
) -> impl IntoView {
inject_style("orbital-code", CODE_CSS);
let root_class = Memo::new(move |_| {
let extra = class.get().unwrap_or_default();
if extra.is_empty() {
"orbital-code".to_string()
} else {
format!("orbital-code {extra}")
}
});
view! {
<code class=root_class>
{if let Some(inner_html) = inner_html {
EitherOf3::A(view! { <pre inner_html=inner_html></pre> })
} else if let Some(text) = text {
EitherOf3::B(view! { <pre>{text}</pre> })
} else {
EitherOf3::C(())
}}
</code>
}
}