Add static components, change error design
Some checks failed
Build Crate / build (push) Failing after 1m45s
Some checks failed
Build Crate / build (push) Failing after 1m45s
This commit is contained in:
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::components::error_block::ErrorBlock;
|
||||
use crate::components::sub_components::error_block::ErrorBlock;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::components::error_block::{ErrorBlock, ErrorBlockProps};
|
||||
use crate::components::sub_components::error_block::ErrorBlock;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::components::error_block::ErrorBlock;
|
||||
use crate::components::sub_components::error_block::ErrorBlock;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::{
|
||||
state_enums::OpenState,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Prop, Debug, Clone)]
|
||||
pub struct ErrorBlockProps {
|
||||
error: RcSignal<String>,
|
||||
}
|
||||
|
||||
#[component(inline_props)]
|
||||
pub fn ErrorBlock<'a, G: Html>(cx: Scope<'a>, error: RcSignal<String>) -> View<G> {
|
||||
let error = create_ref(cx, error);
|
||||
let is_empty = create_selector(cx, || error.get().is_empty());
|
||||
view! { cx,
|
||||
(match !(*is_empty.get()) {
|
||||
true => { view!{cx,
|
||||
div (role="alert") {
|
||||
div (class="bg-red-500 text-white font-bold rounded-t px-4 py-2") {
|
||||
"Error"
|
||||
}
|
||||
div (class="border border-t-0 border-red-400 rounded-b bg-red-100 px-4 py-3 text-red-700"){
|
||||
p {(*error.get())}
|
||||
}
|
||||
}
|
||||
}},
|
||||
false => {view!{cx,}},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod error_block;
|
||||
mod header;
|
||||
pub mod layout;
|
||||
pub mod static_components;
|
||||
pub mod sub_components;
|
||||
|
||||
9
src/components/static_components/close_button_path.rs
Normal file
9
src/components/static_components/close_button_path.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn CloseButtonPath<G: Html>(cx: Scope) -> View<G> {
|
||||
view! { cx,
|
||||
path (d="M14.348 14.849a1.2 1.2 0 0 1-1.697 0L10 11.819l-2.651 3.029a1.2 1.2 0 1 1-1.697-1.697l2.758-3.15-2.759-3.152a1.2 1.2 0 1 1 1.697-1.697L10 8.183l2.651-3.031a1.2 1.2 0 1 1 1.697 1.697l-2.758 3.152 2.758 3.15a1.2 1.2 0 0 1 0 1.698z"){}
|
||||
}
|
||||
}
|
||||
1
src/components/static_components/mod.rs
Normal file
1
src/components/static_components/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod close_button_path;
|
||||
38
src/components/sub_components/error_block.rs
Normal file
38
src/components/sub_components/error_block.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::components::static_components::close_button_path::CloseButtonPath;
|
||||
|
||||
#[component(inline_props)]
|
||||
pub fn ErrorBlock<'a, G: Html>(cx: Scope<'a>, error: RcSignal<String>) -> View<G> {
|
||||
let error = create_ref(cx, error);
|
||||
let is_empty = create_selector(cx, || error.get().is_empty());
|
||||
|
||||
let close_block = move |_event: Event| {
|
||||
#[cfg(client)]
|
||||
{
|
||||
spawn_local_scoped(cx, async move { error.set(String::new()) });
|
||||
}
|
||||
};
|
||||
|
||||
view! { cx,
|
||||
(match !(*is_empty.get()) {
|
||||
true => { view!{cx,
|
||||
|
||||
div (class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative", role="alert") {
|
||||
span (class="block sm:inline"){
|
||||
p {(*error.get())}
|
||||
}
|
||||
span (class="absolute top-0 bottom-0 right-0 px-4 py-3"){
|
||||
svg (on:click = close_block, class="fill-current h-6 w-6 text-red-500", role="button", viewBox="0 0 20 20") {
|
||||
title {"Close"}
|
||||
CloseButtonPath {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
false => {view!{cx,}},
|
||||
})
|
||||
}
|
||||
}
|
||||
1
src/components/sub_components/mod.rs
Normal file
1
src/components/sub_components/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod error_block;
|
||||
Reference in New Issue
Block a user