use super::*;
#[component]
pub fn euv_notification(node: VirtualNode<EuvNotificationProps>) -> VirtualNode {
let EuvNotificationProps { items }: EuvNotificationProps =
node.try_get_props().unwrap_or_default();
let notifications: Vec<VirtualNode> = items
.into_iter()
.enumerate()
.map(
|(index, item): (usize, notification::view::r#struct::EuvNotificationItem)| {
euv_notification_item(index, item)
},
)
.collect();
html! {
div {
role: "status"
aria-live: "polite"
class: c_euv_notification_stack()
notifications
}
}
}
fn euv_notification_item(index: usize, item: EuvNotificationItem) -> VirtualNode {
let EuvNotificationItem {
title,
text,
on_close,
dismissible,
}: EuvNotificationItem = item;
let is_dismissible: bool = dismissible || on_close.is_some();
let close_handler: Option<Rc<dyn Fn(Event)>> = notification_callback_handler(on_close);
html! {
div {
key: index.to_string()
class: c_euv_notification()
div {
class: c_euv_notification_body()
div {
class: c_euv_notification_title()
title
}
div {
class: c_euv_notification_text()
text
}
}
if is_dismissible {
button {
type: "button"
class: c_euv_notification_close()
onclick: close_handler
"×"
}
}
}
}
}
pub fn notification_callback_handler<E: 'static>(
callback: Option<Rc<dyn Fn()>>,
) -> Option<Rc<dyn Fn(E)>> {
callback.map(|handler: Rc<dyn Fn()>| -> Rc<dyn Fn(E)> {
Rc::new(move |_: E| {
handler();
})
})
}
#[component]
pub fn euv_toast(node: VirtualNode<EuvToastProps>) -> VirtualNode {
let EuvToastProps {
variant,
title,
description,
action_label,
dismissible,
on_action,
on_close,
}: EuvToastProps = node.try_get_props().unwrap_or_default();
let toast_class: fn() -> &'static Css = match variant {
EuvToastVariant::Destructive => c_euv_toast_destructive,
EuvToastVariant::Default => c_euv_toast,
};
let mut children: Vec<VirtualNode> = Vec::new();
if !title.is_empty() {
children.push(html! {
div {
"data-slot": "toast-title"
class: c_euv_toast_title()
{
title
}
}
});
}
if !description.is_empty() {
children.push(html! {
div {
"data-slot": "toast-description"
class: c_euv_toast_description()
{
description
}
}
});
}
if !action_label.is_empty() {
let on_click: Option<Rc<dyn Fn(Event)>> = Some(Rc::new(move |_: Event| {
if let Some(callback) = &on_action {
callback();
}
}));
children.push(html! {
button {
type: "button"
"data-slot": "toast-action"
class: c_euv_toast_action()
onclick: on_click
{
action_label
}
}
});
}
if dismissible || on_close.is_some() {
let on_click: Option<Rc<dyn Fn(Event)>> = Some(Rc::new(move |_: Event| {
if let Some(callback) = &on_close {
callback();
}
}));
children.push(html! {
button {
type: "button"
"data-slot": "toast-close"
class: c_euv_toast_close()
"aria-label": "Dismiss"
onclick: on_click
}
});
}
html! {
div {
role: "status"
"aria-live": "polite"
"data-slot": "toast"
class: toast_class()
children
}
}
}
#[component]
pub fn euv_toast_card(node: VirtualNode<EuvToastCardProps>) -> VirtualNode {
let EuvToastCardProps {}: EuvToastCardProps = node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
html! {
div {
role: "status"
"aria-live": "polite"
"data-slot": "toast"
class: c_euv_toast()
children
}
}
}
#[component]
pub fn euv_toast_title(node: VirtualNode<EuvToastTitleProps>) -> VirtualNode {
let EuvToastTitleProps { text }: EuvToastTitleProps = node.try_get_props().unwrap_or_default();
html! {
div {
"data-slot": "toast-title"
class: c_euv_toast_title()
{
text
}
}
}
}
#[component]
pub fn euv_toast_description(node: VirtualNode<EuvToastDescriptionProps>) -> VirtualNode {
let EuvToastDescriptionProps { text }: EuvToastDescriptionProps =
node.try_get_props().unwrap_or_default();
html! {
div {
"data-slot": "toast-description"
class: c_euv_toast_description()
{
text
}
}
}
}
#[component]
pub fn euv_toast_action(node: VirtualNode<EuvToastActionProps>) -> VirtualNode {
let EuvToastActionProps { label, on_click }: EuvToastActionProps =
node.try_get_props().unwrap_or_default();
let handler: Option<Rc<dyn Fn(Event)>> = Some(Rc::new(move |_: Event| {
if let Some(callback) = &on_click {
callback();
}
}));
html! {
button {
type: "button"
"data-slot": "toast-action"
class: c_euv_toast_action()
onclick: handler
{
label
}
}
}
}
#[component]
pub fn euv_toast_provider(node: VirtualNode<EuvToastProviderProps>) -> VirtualNode {
let EuvToastProviderProps {}: EuvToastProviderProps = node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
html! {
div {
"data-slot": "toast-provider"
class: c_euv_toast_provider()
children
}
}
}
#[component]
pub fn euv_toast_viewport(node: VirtualNode<EuvToastViewportProps>) -> VirtualNode {
let EuvToastViewportProps {}: EuvToastViewportProps = node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
html! {
div {
"data-slot": "toast-viewport"
class: c_euv_toast_viewport()
children
}
}
}
#[component]
pub fn euv_toast_close(node: VirtualNode<EuvToastCloseProps>) -> VirtualNode {
let EuvToastCloseProps { on_click }: EuvToastCloseProps =
node.try_get_props().unwrap_or_default();
let handler: Option<Rc<dyn Fn(Event)>> = Some(Rc::new(move |_: Event| {
if let Some(callback) = &on_click {
callback();
}
}));
let children: VirtualNode = node.get_children().into();
html! {
button {
type: "button"
"data-slot": "toast-close"
"aria-label": "Dismiss"
class: c_euv_toast_close()
onclick: handler
children
}
}
}