use crate::{
core::{assets, attrs::component_attributes},
prelude::*,
theme::use_stylesheets,
};
const CITE: Bem = Bem::new("fc-cite");
const SOURCES: Bem = Bem::new("fc-sources");
const SOURCE: Bem = Bem::new("fc-source");
#[component]
pub fn Cite(index: u32, title: AccessibleName, source: Id) -> Element {
rsx! {
if use_stylesheets() { document::Stylesheet { href: assets::COMPONENTS_CITATION_CSS } }
a { class: CITE.block(), href: "#{source}", aria_label: "Source {index}: {title}", "{index}" }
}
}
#[component]
pub fn Sources(
#[props(default)]
label: Option<AccessibleName>,
#[props(default)] class: Option<String>,
#[props(extends = GlobalAttributes)] attributes: Vec<Attribute>,
children: Element,
) -> Element {
let attributes = component_attributes(
attributes,
ClassList::new(SOURCES.block()).extend(class.as_deref()),
&["aria-label"],
);
let label = label.map_or_else(|| "Sources".to_owned(), |l| l.to_string());
rsx! {
if use_stylesheets() { document::Stylesheet { href: assets::COMPONENTS_CITATION_CSS } }
ol { aria_label: label, ..attributes, {children} }
}
}
#[component]
pub fn Source(
id: Id,
index: u32,
href: String,
title: Element,
#[props(default)] domain: Option<Element>,
#[props(default)]
icon: Option<Element>,
) -> Element {
let link = crate::core::link::use_link(Some(href));
rsx! {
li { class: SOURCE.block(), id: "{id}",
a { class: SOURCE.element("link"), href: link.href.clone(), onclick: move |event| { link.follow(&event); },
if let Some(icon) = icon { span { class: SOURCE.element("icon"), aria_hidden: "true", {icon} } }
span { class: SOURCE.element("index"), "{index}" }
span { class: SOURCE.element("title"), {title} }
if let Some(domain) = domain { span { class: SOURCE.element("domain"), {domain} } }
}
}
}
}