mirror of
https://github.com/adoyle0/thaw.git
synced 2025-03-12 05:32:55 -04:00
feat: rewrite code component
This commit is contained in:
parent
80d190e15d
commit
9c7c24b102
4 changed files with 36 additions and 16 deletions
|
@ -42,7 +42,7 @@ pub fn Demo(demo_code: DemoCode, children: Children) -> impl IntoView {
|
||||||
let content_class = create_memo(move |_| {
|
let content_class = create_memo(move |_| {
|
||||||
theme.with(|theme| {
|
theme.with(|theme| {
|
||||||
format!(
|
format!(
|
||||||
"thaw-demo__content color-scheme--{}",
|
"color-scheme--{}",
|
||||||
theme.common.color_scheme
|
theme.common.color_scheme
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -66,21 +66,17 @@ pub fn Demo(demo_code: DemoCode, children: Children) -> impl IntoView {
|
||||||
</Style>
|
</Style>
|
||||||
<div style=move || style.get()>{children()}</div>
|
<div style=move || style.get()>{children()}</div>
|
||||||
<div style=move || code_style.get() class=move || content_class.get()>
|
<div style=move || code_style.get() class=move || content_class.get()>
|
||||||
<Code>
|
|
||||||
{
|
{
|
||||||
if is_highlight {
|
if is_highlight {
|
||||||
view! {
|
view! {
|
||||||
<pre style="margin: 0" inner_html=html></pre>
|
<Code inner_html=html />
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
view! {
|
view! {
|
||||||
<pre style="margin: 0">
|
<Code text=html />
|
||||||
{html}
|
|
||||||
</pre>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</Code>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
.thaw-demo__content pre {
|
|
||||||
font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas,
|
|
||||||
Liberation Mono, monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** https://github.com/AmjadHD/sublime_one_theme */
|
/** https://github.com/AmjadHD/sublime_one_theme */
|
||||||
|
|
||||||
/** light */
|
/** light */
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
.thaw-code {
|
.thaw-code {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas,
|
||||||
|
Liberation Mono, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thaw-code pre {
|
||||||
|
margin: 0;
|
||||||
|
line-height: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
}
|
}
|
|
@ -1,8 +1,28 @@
|
||||||
use crate::utils::mount_style;
|
use crate::utils::{class_list::class_list, mount_style, OptionalProp};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Code(children: Children) -> impl IntoView {
|
pub fn Code(
|
||||||
|
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
||||||
|
#[prop(optional, into)] text: Option<String>,
|
||||||
|
#[prop(optional, into)] inner_html: Option<String>,
|
||||||
|
) -> impl IntoView {
|
||||||
mount_style("code", include_str!("./code.css"));
|
mount_style("code", include_str!("./code.css"));
|
||||||
view! { <code class="thaw-code">{children()}</code> }
|
view! {
|
||||||
|
<code class=class_list!["thaw-code", class.map(|c| move || c.get())]>
|
||||||
|
{
|
||||||
|
if let Some(inner_html) = inner_html {
|
||||||
|
view! {
|
||||||
|
<pre inner_html=inner_html></pre>
|
||||||
|
}.into()
|
||||||
|
} else if let Some(text) = text {
|
||||||
|
view! {
|
||||||
|
<pre>{text}</pre>
|
||||||
|
}.into()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</code>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue