1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-25 08:31:10 +00:00

Reactive editor with side by side preview (fixes #69)

This commit is contained in:
Felix Ableitner 2024-11-06 11:01:00 +01:00
parent b0f12a6908
commit 1093cbf67e
3 changed files with 40 additions and 32 deletions

View file

@ -13,36 +13,44 @@ pub fn EditorView(
let (show_preview, set_show_preview) = create_signal(false); let (show_preview, set_show_preview) = create_signal(false);
view! { view! {
<div class="my-4"> <div>
<textarea <div class="my-4 w-full flex max-sm:flex-col">
prop:value=content <textarea
placeholder="Article text..." prop:value=content
class="textarea textarea-primary min-w-full min-h-80 resize-none text-base" placeholder="Article text..."
on:input=move |evt| { class="grow textarea textarea-primary min-h-80 resize-none text-base text-base"
let val = event_target_value(&evt); on:input=move |evt| {
set_preview.set(render_markdown(&val)); let val = event_target_value(&evt);
set_content.set(val); set_preview.set(render_markdown(&val));
} set_content.set(val);
node_ref=textarea_ref }
></textarea> node_ref=textarea_ref
<button ></textarea>
class="btn btn-secondary my-4" <Show when=move || { show_preview.get() }>
on:click=move |_| { set_show_preview.update(|s| *s = !*s) } <div class="divider md:hidden"></div>
> <div
Preview class="prose prose-slate basis-6/12 md:ms-4 text-base py-2 max-sm:px-2"
</button> inner_html=move || preview.get()
<Show when=move || { show_preview.get() }> ></div>
<div class="prose prose-slate" inner_html=move || preview.get()></div> </Show>
</Show> </div>
<div> <div class="flex h-min items-center mb-4">
<a <button
class="link link-secondary" class="btn btn-secondary"
href="https://ibis.wiki/article/Markdown_Guide" on:click=move |_| { set_show_preview.update(|s| *s = !*s) }
target="blank_"
> >
Markdown Preview
</a> </button>
" formatting is supported" <p class="mx-4">
<a
class="link link-secondary"
href="https://ibis.wiki/article/Markdown_Guide"
target="blank_"
>
Markdown
</a>
" formatting is supported"
</p>
</div> </div>
</div> </div>
} }

View file

@ -80,7 +80,7 @@ pub fn CreateArticle() -> impl IntoView {
<div class="flex flex-row"> <div class="flex flex-row">
<input <input
class="input input-primary grow mr-2" class="input input-primary grow mr-4"
type="text" type="text"
placeholder="Edit summary" placeholder="Edit summary"
on:keyup=move |ev| { on:keyup=move |ev| {

View file

@ -140,7 +140,7 @@ pub fn EditArticle() -> impl IntoView {
<div class="flex flex-row mr-2"> <div class="flex flex-row mr-2">
<input <input
type="text" type="text"
class="input input-secondary grow" class="input input-primary grow me-4"
placeholder="Edit summary" placeholder="Edit summary"
value=summary.get_untracked() value=summary.get_untracked()
on:keyup=move |ev| { on:keyup=move |ev| {
@ -150,7 +150,7 @@ pub fn EditArticle() -> impl IntoView {
/> />
<button <button
class="btn btn-secondary" class="btn btn-primary"
prop:disabled=move || button_is_disabled.get() prop:disabled=move || button_is_disabled.get()
on:click=move |_| { on:click=move |_| {
submit_action submit_action