impulse_thaw/text/
mod.rs

1use leptos::{prelude::*, tachys::view::any_view::IntoAny};
2use thaw_utils::{class_list, mount_style};
3
4#[component]
5pub fn Caption1(
6    #[prop(optional, into)] class: MaybeProp<String>,
7    #[prop(optional, into)] style: MaybeProp<String>,
8    #[prop(optional)] tag: TextTag,
9    children: Children,
10) -> impl IntoView {
11    let class =
12        Signal::derive(move || format!("thaw-caption-1 {}", class.get().unwrap_or_default()));
13
14    view! { <Text tag children class style /> }
15}
16
17#[component]
18pub fn Caption1Strong(
19    #[prop(optional, into)] class: MaybeProp<String>,
20    #[prop(optional, into)] style: MaybeProp<String>,
21    #[prop(optional)] tag: TextTag,
22    children: Children,
23) -> impl IntoView {
24    let class = Signal::derive(move || {
25        format!("thaw-caption-1-strong {}", class.get().unwrap_or_default())
26    });
27
28    view! { <Text tag children class style /> }
29}
30
31#[component]
32pub fn Body1(
33    #[prop(optional, into)] class: MaybeProp<String>,
34    #[prop(optional, into)] style: MaybeProp<String>,
35    #[prop(optional)] tag: TextTag,
36    children: Children,
37) -> impl IntoView {
38    let class = Signal::derive(move || format!("thaw-body-1 {}", class.get().unwrap_or_default()));
39
40    view! { <Text tag children class style /> }
41}
42
43#[component]
44pub fn Text(
45    #[prop(optional, into)] class: MaybeProp<String>,
46    #[prop(optional, into)] style: MaybeProp<String>,
47    #[prop(optional)] tag: TextTag,
48    children: Children,
49) -> impl IntoView {
50    mount_style("text", include_str!("./text.css"));
51    let class = class_list!["thaw-text", class];
52    let style = move || style.get().unwrap_or_default();
53
54    match tag {
55        TextTag::B => view! {
56            <b class=class style=style>
57                {children()}
58            </b>
59        }
60        .into_any(),
61        TextTag::Code => view! {
62            <code class=class style=style>
63                {children()}
64            </code>
65        }
66        .into_any(),
67        TextTag::Em => view! {
68            <em class=class style=style>
69                {children()}
70            </em>
71        }
72        .into_any(),
73        TextTag::H1 => view! {
74            <h1 class=class style=style>
75                {children()}
76            </h1>
77        }
78        .into_any(),
79        TextTag::H2 => view! {
80            <h2 class=class style=style>
81                {children()}
82            </h2>
83        }
84        .into_any(),
85        TextTag::H3 => view! {
86            <h3 class=class style=style>
87                {children()}
88            </h3>
89        }
90        .into_any(),
91        TextTag::H4 => view! {
92            <h4 class=class style=style>
93                {children()}
94            </h4>
95        }
96        .into_any(),
97        TextTag::H5 => view! {
98            <h5 class=class style=style>
99                {children()}
100            </h5>
101        }
102        .into_any(),
103        TextTag::H6 => view! {
104            <h6 class=class style=style>
105                {children()}
106            </h6>
107        }
108        .into_any(),
109        TextTag::I => view! {
110            <i class=class style=style>
111                {children()}
112            </i>
113        }
114        .into_any(),
115        TextTag::P => view! {
116            <p class=class style=style>
117                {children()}
118            </p>
119        }
120        .into_any(),
121        TextTag::Pre => view! {
122            <pre class=class style=style>
123                {children()}
124            </pre>
125        }
126        .into_any(),
127        TextTag::Span => view! {
128            <span class=class style=style>
129                {children()}
130            </span>
131        }
132        .into_any(),
133        TextTag::Strong => view! {
134            <strong class=class style=style>
135                {children()}
136            </strong>
137        }
138        .into_any(),
139    }
140}
141
142#[derive(Default, PartialEq)]
143pub enum TextTag {
144    B,
145    Code,
146    Em,
147    H1,
148    H2,
149    H3,
150    H4,
151    H5,
152    H6,
153    I,
154    P,
155    Pre,
156    #[default]
157    Span,
158    Strong,
159}