Skip to content

Commit ff0008a

Browse files
Add Leptos Alert (#196)
* Add alert crate to leptos * add default implementation of alert * add new york implementation of alert * Initial example implementaion * Work with book-examples and make tests * Fix wrong html for description * Add book example destructive icon * Fix and Add class change to Alert * Fix path book-examples/leptos/button default==new-york * Update packages/leptos/alert/src/lib.rs comment * Change into regular Leptos elements * Fix examples for default * Fix examples for new-york * Fix book-examples alphabetical order * Fix book-examples components ui.rs alphabetical order * Fix book-examples cargo.toml alphabetical order * Fix book-examples cargo.toml dependencies
1 parent cb9383e commit ff0008a

File tree

17 files changed

+369
-3
lines changed

17 files changed

+369
-3
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book-examples/leptos/Cargo.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@ lucide-leptos = { version = "1.0.0", optional = true }
1818
log.workspace = true
1919
radix-leptos-icons = { workspace = true, optional = true }
2020
shadcn-ui-leptos-button = { path = "../../packages/leptos/button", optional = true }
21+
shadcn-ui-leptos-alert = { path = "../../packages/leptos/alert" , optional = true }
2122
shadcn-ui-leptos-card = { path = "../../packages/leptos/card", optional = true }
2223

2324
[features]
2425
default = [
26+
"alert",
2527
"button",
26-
"card"
28+
"card",
2729
]
30+
31+
alert = [
32+
"dep:lucide-leptos",
33+
"dep:radix-leptos-icons",
34+
"dep:shadcn-ui-leptos-alert",
35+
"radix-leptos-icons/exclamation-triangle",
36+
"radix-leptos-icons/rocket",
37+
]
38+
2839
button = [
2940
"dep:lucide-leptos",
3041
"dep:radix-leptos-icons",
@@ -37,4 +48,4 @@ card = [
3748
"dep:lucide-leptos",
3849
"dep:shadcn-ui-leptos-button",
3950
"dep:shadcn-ui-leptos-card",
40-
]
51+
]

book-examples/leptos/src/default.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
mod components;
22

3+
#[cfg(feature = "alert")]
4+
mod alert;
5+
36
#[cfg(feature = "button")]
47
mod button;
8+
59
#[cfg(feature = "card")]
610
mod card;
711

@@ -14,6 +18,10 @@ use leptos_router::{
1418
#[component(transparent)]
1519
pub fn Default() -> impl MatchNestedRoutes + Clone {
1620
let children = (
21+
#[cfg(feature = "alert")]
22+
{
23+
component_view(self::alert::AlertRoutes, ())
24+
},
1725
#[cfg(feature = "button")]
1826
{
1927
component_view(self::button::ButtonRoutes, ())
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#[allow(clippy::module_inception)]
2+
mod alert;
3+
mod alert_destructive;
4+
5+
use leptos::prelude::*;
6+
use leptos_router::{
7+
components::{Outlet, ParentRoute, Route},
8+
path, MatchNestedRoutes,
9+
};
10+
11+
#[component(transparent)]
12+
pub fn AlertRoutes() -> impl MatchNestedRoutes + Clone {
13+
view! {
14+
<ParentRoute path=path!("/alert") view=Outlet>
15+
<Route path=path!("/") view=alert::AlertDemo />
16+
<Route path=path!("/destructive") view=alert_destructive::AlertDestructive />
17+
</ParentRoute>
18+
}
19+
.into_inner()
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use leptos::prelude::*;
2+
use lucide_leptos::Terminal;
3+
4+
use crate::default::components::ui::alert::{Alert, AlertDescription, AlertTitle};
5+
6+
#[component]
7+
pub fn AlertDemo() -> impl IntoView {
8+
view! {
9+
<Alert>
10+
<Terminal attr:class="h-4 w-4" />
11+
<AlertTitle>"Heads up!"</AlertTitle>
12+
<AlertDescription>
13+
"You can add components to your app using the cli."
14+
</AlertDescription>
15+
</Alert>
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use leptos::prelude::*;
2+
use lucide_leptos::CircleAlert;
3+
4+
use crate::default::components::ui::alert::{Alert, AlertDescription, AlertTitle, AlertVariant};
5+
6+
#[component]
7+
pub fn AlertDestructive() -> impl IntoView {
8+
view! {
9+
<Alert variant={AlertVariant::Destructive}>
10+
<CircleAlert attr:class="h-4 w-4" />
11+
<AlertTitle>"Error"</AlertTitle>
12+
<AlertDescription>
13+
"Your session has expired. Please log in again."
14+
</AlertDescription>
15+
</Alert>
16+
}
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// In actual projects this module would contain the copied components, but this example uses the local workspace packages.
22

3+
#[cfg(feature = "alert")]
4+
pub use shadcn_ui_leptos_alert::default as alert;
5+
36
#[cfg(any(feature = "button", feature = "card"))]
47
pub use shadcn_ui_leptos_button::default as button;
8+
59
#[cfg(feature = "card")]
610
pub use shadcn_ui_leptos_card::default as card;

book-examples/leptos/src/new_york.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
mod components;
22

3+
#[cfg(feature = "alert")]
4+
mod alert;
5+
36
#[cfg(feature = "button")]
47
mod button;
8+
59
#[cfg(feature = "card")]
610
mod card;
711

@@ -14,6 +18,10 @@ use leptos_router::{
1418
#[component(transparent)]
1519
pub fn NewYork() -> impl MatchNestedRoutes + Clone {
1620
let children = (
21+
#[cfg(feature = "alert")]
22+
{
23+
component_view(self::alert::AlertRoutes, ())
24+
},
1725
#[cfg(feature = "button")]
1826
{
1927
component_view(self::button::ButtonRoutes, ())
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#[allow(clippy::module_inception)]
2+
mod alert;
3+
mod alert_destructive;
4+
5+
use leptos::prelude::*;
6+
use leptos_router::{
7+
components::{Outlet, ParentRoute, Route},
8+
path, MatchNestedRoutes,
9+
};
10+
11+
#[component(transparent)]
12+
pub fn AlertRoutes() -> impl MatchNestedRoutes + Clone {
13+
view! {
14+
<ParentRoute path=path!("/alert") view=Outlet>
15+
<Route path=path!("/") view=alert::AlertDemo />
16+
<Route path=path!("/destructive") view=alert_destructive::AlertDestructive />
17+
</ParentRoute>
18+
}
19+
.into_inner()
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use leptos::prelude::*;
2+
use lucide_leptos::Terminal;
3+
4+
use crate::new_york::components::ui::alert::{Alert, AlertDescription, AlertTitle};
5+
6+
#[component]
7+
pub fn AlertDemo() -> impl IntoView {
8+
view! {
9+
<Alert>
10+
<Terminal attr:class="h-4 w-4" />
11+
<AlertTitle>"Heads up!"</AlertTitle>
12+
<AlertDescription>
13+
"You can add components to your app using the cli."
14+
</AlertDescription>
15+
</Alert>
16+
}
17+
}

0 commit comments

Comments
 (0)