Skip to content

Commit 3ea9b45

Browse files
committed
feat(leptos): add input component
1 parent 4b0bd5e commit 3ea9b45

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

crates/leptos/src/input.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use components_core::{BASE_CLASS, concat};
2+
use leptos::prelude::*;
3+
use leptos::{IntoView, component, view};
4+
5+
#[component]
6+
pub fn Input(
7+
#[prop(into)] has_error: ReadSignal<bool>,
8+
#[prop(into)] disabled: ReadSignal<bool>,
9+
#[prop(into, optional)] class: String,
10+
#[prop(into, optional)] error_message: String,
11+
#[prop(into)] icon: Option<Children>,
12+
) -> impl IntoView {
13+
let input_class = crate::tw!(
14+
concat!(BASE_CLASS, "-input"),
15+
has_error
16+
.get()
17+
.then_some(concat!(BASE_CLASS, "-input--error")),
18+
class
19+
);
20+
21+
view! {
22+
<div class={concat!(BASE_CLASS, "-input__container")}>
23+
<div class=input_class>
24+
{icon.map(|icon| view! { <span class={concat!(BASE_CLASS, "-input__icon")}>{icon()}</span> })}
25+
<input
26+
class={concat!(BASE_CLASS, "-input__inner")}
27+
disabled=disabled
28+
/>
29+
</div>
30+
{has_error.get().then_some(
31+
view! { <span class={concat!(BASE_CLASS, "-input__error")}>{error_message}</span> }
32+
)}
33+
</div>
34+
}
35+
}

crates/leptos/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod card;
77
pub mod chip;
88
pub mod flap;
99
pub mod icons;
10+
pub mod input;
1011
pub mod level;
1112
pub mod progress_bar;
1213
pub mod radio;
@@ -23,6 +24,7 @@ pub mod prelude {
2324
pub use crate::card::Card;
2425
pub use crate::chip::{Chip, Variant as ChipVariant};
2526
pub use crate::flap::Flap;
27+
pub use crate::input::Input;
2628
pub use crate::level::{Level, Variant as LevelVariant};
2729
pub use crate::progress_bar::ProgressBar;
2830
pub use crate::tag::Tag;

0 commit comments

Comments
 (0)