Skip to main content

orbital_base_components/code/
base.rs

1use leptos::{either::EitherOf3, prelude::*};
2
3#[component]
4pub fn BaseCode(
5    #[prop(optional, into)] class: MaybeProp<String>,
6    #[prop(optional)] text: Option<String>,
7    #[prop(optional)] inner_html: Option<String>,
8) -> impl IntoView {
9    let root_class = Memo::new(move |_| {
10        let extra = class.get().unwrap_or_default();
11        if extra.is_empty() {
12            "orbital-code".to_string()
13        } else {
14            format!("orbital-code {extra}")
15        }
16    });
17
18    view! {
19        <code class=root_class>
20            {if let Some(inner_html) = inner_html {
21                EitherOf3::A(view! { <pre inner_html=inner_html></pre> })
22            } else if let Some(text) = text {
23                EitherOf3::B(view! { <pre>{text}</pre> })
24            } else {
25                EitherOf3::C(())
26            }}
27        </code>
28    }
29}