1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use leptos::{context::Provider, either::EitherOf4, prelude::*};
use thaw_utils::{class_list, mount_style};
/// Communicates important information about the state of the entire application or surface.
/// For example, the status of a page, panel, dialog or card.
/// The information shouldn't require someone to take immediate action,
/// but should persist until the user performs one of the required actions.
#[component]
pub fn MessageBar(
#[prop(optional, into)] class: MaybeProp<String>,
#[prop(optional, into)] layout: MessageBarLayout,
/// Default designs announcement presets.
#[prop(optional, into)]
intent: Signal<MessageBarIntent>,
children: Children,
) -> impl IntoView {
mount_style("message-bar", include_str!("./message-bar.css"));
view! {
<div
class=class_list![
"thaw-message-bar",
move || format!("thaw-message-bar--{}", intent.get().as_str()),
move || format!("thaw-message-bar--{}", layout.as_str()),
class
]
role="group"
>
<div class="thaw-message-bar__icon">
{move || match intent.get() {
MessageBarIntent::Info => {
EitherOf4::A(
view! {
<svg
fill="currentColor"
aria-hidden="true"
width="1em"
height="1em"
viewBox="0 0 20 20"
>
<path
d="M18 10a8 8 0 1 0-16 0 8 8 0 0 0 16 0ZM9.5 8.91a.5.5 0 0 1 1 0V13.6a.5.5 0 0 1-1 0V8.9Zm-.25-2.16a.75.75 0 1 1 1.5 0 .75.75 0 0 1-1.5 0Z"
fill="currentColor"
></path>
</svg>
},
)
}
MessageBarIntent::Success => {
EitherOf4::B(
view! {
<svg
fill="currentColor"
aria-hidden="true"
width="1em"
height="1em"
viewBox="0 0 20 20"
>
<path
d="M10 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16Zm3.36 5.65a.5.5 0 0 0-.64-.06l-.07.06L9 11.3 7.35 9.65l-.07-.06a.5.5 0 0 0-.7.7l.07.07 2 2 .07.06c.17.11.4.11.56 0l.07-.06 4-4 .07-.08a.5.5 0 0 0-.06-.63Z"
fill="currentColor"
></path>
</svg>
},
)
}
MessageBarIntent::Warning => {
EitherOf4::C(
view! {
<svg
fill="currentColor"
aria-hidden="true"
width="1em"
height="1em"
viewBox="0 0 20 20"
>
<path
d="M8.68 2.79a1.5 1.5 0 0 1 2.64 0l6.5 12A1.5 1.5 0 0 1 16.5 17h-13a1.5 1.5 0 0 1-1.32-2.21l6.5-12ZM10.5 7.5a.5.5 0 0 0-1 0v4a.5.5 0 0 0 1 0v-4Zm.25 6.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"
fill="currentColor"
></path>
</svg>
},
)
}
MessageBarIntent::Error => {
EitherOf4::D(
view! {
<svg
fill="currentColor"
aria-hidden="true"
width="1em"
height="1em"
viewBox="0 0 20 20"
>
<path
d="M10 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16ZM7.8 7.11a.5.5 0 0 0-.63.06l-.06.07a.5.5 0 0 0 .06.64L9.3 10l-2.12 2.12-.06.07a.5.5 0 0 0 .06.64l.07.06c.2.13.47.11.64-.06L10 10.7l2.12 2.12.07.06c.2.13.46.11.64-.06l.06-.07a.5.5 0 0 0-.06-.64L10.7 10l2.12-2.12.06-.07a.5.5 0 0 0-.06-.64l-.07-.06a.5.5 0 0 0-.64.06L10 9.3 7.88 7.17l-.07-.06Z"
fill="currentColor"
></path>
</svg>
},
)
}
}}
</div>
<Provider value=MessageBarInjection { layout }>{children()}</Provider>
</div>
}
}
#[derive(Debug, Clone)]
pub(crate) struct MessageBarInjection {
pub layout: MessageBarLayout,
}
impl MessageBarInjection {
pub fn expect_context() -> Self {
expect_context()
}
}
#[derive(Default, Clone)]
pub enum MessageBarIntent {
#[default]
Info,
Success,
Warning,
Error,
}
impl MessageBarIntent {
pub fn as_str(&self) -> &'static str {
match self {
MessageBarIntent::Info => "into",
MessageBarIntent::Success => "success",
MessageBarIntent::Warning => "warning",
MessageBarIntent::Error => "error",
}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub enum MessageBarLayout {
#[default]
Singleline,
Multiline,
}
impl MessageBarLayout {
pub fn as_str(&self) -> &'static str {
match self {
MessageBarLayout::Singleline => "singleline",
MessageBarLayout::Multiline => "multiline",
}
}
}