File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed
pgml-dashboard/src/components Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 11div [data-controller = " inputs-text-input" ] {
2+ --bs-danger : #{$peach-shade-100 } ;
3+
24 span .material-symbols-outlined {
35 margin-left : -40px ;
46 color : #{$slate-shade-100 } ;
7+
8+ & .is-invalid {
9+ color : var (--bs-danger );
10+ }
511 }
612
713 input .form-control {
@@ -12,4 +18,10 @@ div[data-controller="inputs-text-input"] {
1218 label .form-label {
1319 font-weight : #{$font-weight-normal } ;
1420 }
21+
22+ p {
23+ small {
24+ color : var (--bs-danger );
25+ }
26+ }
1527}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ pub struct Input {
1616 autocomplete : bool ,
1717 value : String ,
1818 required : bool ,
19+ error : Option < String > ,
1920}
2021
2122impl Input {
@@ -38,6 +39,7 @@ impl Input {
3839 autocomplete : false ,
3940 value : "" . to_string ( ) ,
4041 required : false ,
42+ error : None ,
4143 }
4244 }
4345
@@ -90,6 +92,11 @@ impl Input {
9092 self . required = true ;
9193 self
9294 }
95+
96+ pub fn error ( mut self , error : Option < impl ToString > ) -> Self {
97+ self . error = error. map ( |e| e. to_string ( ) ) ;
98+ self
99+ }
93100}
94101
95102component ! ( Input ) ;
Original file line number Diff line number Diff line change 1+ < % let (input_classes, icon_classes) = if error.is_some() {
2+ ("form-control is-invalid", "material-symbols-outlined is-invalid")
3+ } else {
4+ ("form-control", "material-symbols-outlined")
5+ };
6+ %>
17< div data-controller ="inputs-text-input ">
28 < % if let Some(label) = label { %>
39 < label class ="form-label " for ="<%= id %> "> < %+ label %> </ label >
814 id ="<%= id %> "
915 type ="<%= type_ %> "
1016 name ="<%= name %> "
11- class ="form-control "
17+ class ="<%= input_classes %> "
1218 placeholder ="<%= placeholder %> "
1319 data-action ="<%= input_actions %> "
1420 autocomplete ="<%= autocomplete %> "
2026
2127 < % if let Some(icon) = icon { %>
2228 < span
23- class ="material-symbols-outlined "
29+ class ="<%= icon_classes %> "
2430 data-action ="<%= icon_actions %> ">
2531 < %= icon %>
2632 </ span >
2733 < % } %>
2834 </ div >
35+ < % if let Some(error) = error { %>
36+ < p class ="mt-1 mb-0 ">
37+ < small > < %= error %> </ small >
38+ </ p >
39+ < % } %>
2940</ div >
Original file line number Diff line number Diff line change 5858 .type_("text") %>
5959 </ div >
6060
61+ < div class ="py-5 ">
62+ < %+ Input::new()
63+ .label("What is your name?".into())
64+ .icon("person")
65+ .placeholder("Enter your name")
66+ .name("name")
67+ .type_("text")
68+ .error(Some("Your name is not valid.")) %>
69+ </ div >
70+
6171 < div class ="py-5 ">
6272 < %+ Search::new(SearchOptions {
6373 name: "Model search".into(),
You can’t perform that action at this time.
0 commit comments