11use dioxus:: prelude:: * ;
2- use shield:: { Input , InputValue } ;
2+ use shield:: { Input , InputType , InputValue } ;
33use shield_dioxus:: Query ;
44
5+ use crate :: dioxus:: input_addon:: FormInputAddon ;
6+
57#[ derive( Clone , PartialEq , Props ) ]
68pub struct FormInputProps {
79 input : Input ,
@@ -19,6 +21,83 @@ pub fn FormInput(props: FormInputProps) -> Element {
1921 origin. set ( web_sys:: window ( ) . and_then ( |window| window. location ( ) . origin ( ) . ok ( ) ) )
2022 } ) ;
2123
24+ let value = props. input . value . and_then ( |value| match value {
25+ InputValue :: Origin => origin ( ) ,
26+ InputValue :: Query { key } => query. get ( & key) . cloned ( ) ,
27+ InputValue :: String { value } => Some ( value. clone ( ) ) ,
28+ } ) ;
29+
30+ let mut element = match props. input . r#type {
31+ InputType :: Button ( _) | InputType :: Reset ( _) | InputType :: Submit ( _) => {
32+ return rsx ! {
33+ button {
34+ class: "btn btn-outline-primary d-flex align-items-center justify-content-center gap-1" ,
35+ name: props. input. name,
36+ type : match props. input. r#type {
37+ InputType :: Reset ( _) => "reset" ,
38+ InputType :: Submit ( _) => "submit" ,
39+ _ => "button"
40+ } ,
41+
42+ if let Some ( addon) = props. input. addon_start {
43+ FormInputAddon {
44+ addon,
45+ group: false ,
46+ }
47+ }
48+
49+ { value}
50+
51+ if let Some ( addon) = props. input. addon_end {
52+ FormInputAddon {
53+ addon,
54+ group: false ,
55+ }
56+ }
57+ }
58+ } ;
59+ }
60+ _ => {
61+ rsx ! {
62+ input {
63+ class: "form-control" ,
64+ name: props. input. name,
65+ type : props. input. r#type. as_str( ) ,
66+ value,
67+ placeholder: props. input. label. clone( ) ,
68+ }
69+ }
70+ }
71+ } ;
72+
73+ if matches ! ( props. input. r#type, InputType :: Hidden ( _) ) {
74+ return element;
75+ }
76+
77+ if props. input . addon_start . is_some ( ) || props. input . addon_end . is_some ( ) {
78+ element = rsx ! {
79+ div {
80+ class: "input-group" ,
81+
82+ if let Some ( addon) = props. input. addon_start {
83+ FormInputAddon {
84+ addon,
85+ group: true ,
86+ }
87+ }
88+
89+ { element }
90+
91+ if let Some ( addon) = props. input. addon_end {
92+ FormInputAddon {
93+ addon,
94+ group: true ,
95+ }
96+ }
97+ }
98+ }
99+ }
100+
22101 rsx ! {
23102 div {
24103 class: "mb-3" ,
@@ -33,19 +112,7 @@ pub fn FormInput(props: FormInputProps) -> Element {
33112 }
34113 }
35114
36- input {
37- class: "form-control" ,
38- name: props. input. name,
39- type : props. input. r#type. as_str( ) ,
40- value: props. input. value. map( |value| match value {
41- InputValue :: Origin => origin( ) ,
42- InputValue :: Query { key } => {
43- query. get( & key) . cloned( )
44- } ,
45- InputValue :: String { value } => Some ( value. clone( ) ) ,
46- } ) ,
47- placeholder: props. input. label,
48- }
115+ { element}
49116 }
50117 }
51118}
0 commit comments