ftml_viewer_components/components/
paragraphs.rs1use flams_ontology::{
2 narration::paragraphs::ParagraphKind,
3 uris::{DocumentElementURI, Name},
4};
5use flams_web_utils::inject_css;
6use leptos::{context::Provider, prelude::*};
7
8use crate::{components::counters::SectionCounters, ts::FragmentContinuation, FragmentKind};
9
10pub(super) fn paragraph<V: IntoView + 'static>(
11 kind: ParagraphKind,
12 uri: DocumentElementURI,
13 styles: Box<[Name]>,
14 children: impl FnOnce() -> V + Send + 'static,
15) -> impl IntoView {
16 inject_css("ftml-sections", include_str!("sections.css"));
17 let mut counters: SectionCounters = expect_context();
18 let style = counters.get_para(kind, &styles);
19 let prefix = match kind {
20 ParagraphKind::Assertion => Some("ftml-assertion"),
21 ParagraphKind::Definition => Some("ftml-definition"),
22 ParagraphKind::Example => Some("ftml-example"),
23 ParagraphKind::Paragraph => Some("ftml-paragraph"),
24 _ => None,
25 };
26 let cls = prefix.map(|p| {
27 let mut s = String::new();
28 s.push_str(p);
29 for style in styles {
30 s.push(' ');
31 s.push_str(p);
32 s.push('-');
33 s.push_str(style.first_name().as_ref());
34 }
35 s
36 });
37
38 view! {
39 <Provider value=counters>
40 <div class=cls style=style>{FragmentContinuation::wrap(&(uri,kind.into()) ,children())}</div>
41 </Provider>
42 }
43}
44
45pub(super) fn slide<V: IntoView + 'static>(
46 uri: DocumentElementURI,
47 children: impl FnOnce() -> V + Send + 'static,
48) -> impl IntoView {
49 inject_css("ftml-slide", include_str!("slides.css"));
50 let counters = SectionCounters::slide_inc();
51 view!(<Provider value=counters>
52 <div class="ftml-slide">{FragmentContinuation::wrap(&(uri,FragmentKind::Slide) ,children())}</div>
53 </Provider>)
54}
55
56pub(super) fn slide_number() -> impl IntoView {
57 let v = SectionCounters::get_slide();
58 move || v.get()
59}
60