@@ -4,58 +4,57 @@ import type { InputSchema } from '@object-ui/types';
44import { Input , Label } from '../../ui' ;
55import { cn } from '../../lib/utils' ;
66
7- ComponentRegistry . register ( 'input' ,
8- ( { schema, className, onChange, value, ...props } : { schema : InputSchema ; className ?: string ; onChange ?: ( val : any ) => void ; value ?: any ; [ key : string ] : any } ) => {
9-
10- // Handle change for both raw inputs and form-bound inputs
11- const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
12- if ( onChange ) {
13- onChange ( e . target . value ) ;
14- }
15- } ;
7+ const InputRenderer = ( { schema, className, onChange, value, ...props } : { schema : InputSchema ; className ?: string ; onChange ?: ( val : any ) => void ; value ?: any ; [ key : string ] : any } ) => {
8+ // Handle change for both raw inputs and form-bound inputs
9+ const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
10+ if ( onChange ) {
11+ onChange ( e . target . value ) ;
12+ }
13+ } ;
1614
17- // Extract designer-related props to apply to the wrapper
18- // These props are injected by SchemaRenderer for designer interaction
19- const {
20- 'data-obj-id' : dataObjId ,
21- 'data-obj-type' : dataObjType ,
22- style,
23- ...inputProps
24- } = props ;
15+ // Extract designer-related props to apply to the wrapper
16+ // These props are injected by SchemaRenderer for designer interaction
17+ const {
18+ 'data-obj-id' : dataObjId ,
19+ 'data-obj-type' : dataObjType ,
20+ style,
21+ ...inputProps
22+ } = props ;
2523
26- return (
27- < div
28- className = { cn ( "grid w-full items-center gap-1.5" , schema . wrapperClass ) }
29- data-obj-id = { dataObjId }
30- data-obj-type = { dataObjType }
31- style = { style }
32- >
33- { schema . label && < Label htmlFor = { schema . id } className = { cn ( schema . required && "text-destructive after:content-['*'] after:ml-0.5" ) } > { schema . label } </ Label > }
34- < Input
35- type = { schema . inputType || 'text' }
36- id = { schema . id }
37- name = { schema . name }
38- placeholder = { schema . placeholder }
39- className = { className }
40- required = { schema . required }
41- disabled = { schema . disabled }
42- readOnly = { schema . readOnly }
43- value = { value ?? schema . value ?? '' } // Controlled if value provided
44- defaultValue = { value === undefined ? schema . defaultValue : undefined }
45- onChange = { handleChange }
46- min = { schema . min }
47- max = { schema . max }
48- step = { schema . step }
49- maxLength = { schema . maxLength }
50- pattern = { schema . pattern }
51- { ...inputProps }
52- />
53- { schema . description && < p className = "text-sm text-muted-foreground" > { schema . description } </ p > }
54- { schema . error && < p className = "text-sm font-medium text-destructive" > { schema . error } </ p > }
55- </ div >
56- ) ;
57- } ,
58- {
24+ return (
25+ < div
26+ className = { cn ( "grid w-full items-center gap-1.5" , schema . wrapperClass ) }
27+ data-obj-id = { dataObjId }
28+ data-obj-type = { dataObjType }
29+ style = { style }
30+ >
31+ { schema . label && < Label htmlFor = { schema . id } className = { cn ( schema . required && "text-destructive after:content-['*'] after:ml-0.5" ) } > { schema . label } </ Label > }
32+ < Input
33+ type = { schema . inputType || 'text' }
34+ id = { schema . id }
35+ name = { schema . name }
36+ placeholder = { schema . placeholder }
37+ className = { className }
38+ required = { schema . required }
39+ disabled = { schema . disabled }
40+ readOnly = { schema . readOnly }
41+ value = { value ?? schema . value ?? '' } // Controlled if value provided
42+ defaultValue = { value === undefined ? schema . defaultValue : undefined }
43+ onChange = { handleChange }
44+ min = { schema . min }
45+ max = { schema . max }
46+ step = { schema . step }
47+ maxLength = { schema . maxLength }
48+ pattern = { schema . pattern }
49+ { ...inputProps }
50+ />
51+ { schema . description && < p className = "text-sm text-muted-foreground" > { schema . description } </ p > }
52+ { schema . error && < p className = "text-sm font-medium text-destructive" > { schema . error } </ p > }
53+ </ div >
54+ ) ;
55+ } ;
56+
57+ ComponentRegistry . register ( 'input' , InputRenderer , {
5958 label : 'Input Field' ,
6059 inputs : [
6160 { name : 'label' , type : 'string' , label : 'Label' } ,
@@ -77,3 +76,35 @@ ComponentRegistry.register('input',
7776 }
7877 }
7978) ;
79+
80+ ComponentRegistry . register ( 'email' ,
81+ ( props : any ) => < InputRenderer { ...props } schema = { { ...props . schema , inputType : 'email' } } /> ,
82+ {
83+ label : 'Email Input' ,
84+ icon : 'mail' ,
85+ inputs : [
86+ { name : 'label' , type : 'string' , label : 'Label' } ,
87+ { name : 'name' , type : 'string' , label : 'Field Name' } ,
88+ { name : 'placeholder' , type : 'string' , label : 'Placeholder' } ,
89+ { name : 'required' , type : 'boolean' , label : 'Required' } ,
90+ { name : 'disabled' , type : 'boolean' , label : 'Disabled' } ,
91+ { name : 'description' , type : 'string' , label : 'Description' }
92+ ]
93+ }
94+ ) ;
95+
96+ ComponentRegistry . register ( 'password' ,
97+ ( props : any ) => < InputRenderer { ...props } schema = { { ...props . schema , inputType : 'password' } } /> ,
98+ {
99+ label : 'Password Input' ,
100+ icon : 'lock' ,
101+ inputs : [
102+ { name : 'label' , type : 'string' , label : 'Label' } ,
103+ { name : 'name' , type : 'string' , label : 'Field Name' } ,
104+ { name : 'placeholder' , type : 'string' , label : 'Placeholder' } ,
105+ { name : 'required' , type : 'boolean' , label : 'Required' } ,
106+ { name : 'disabled' , type : 'boolean' , label : 'Disabled' } ,
107+ { name : 'description' , type : 'string' , label : 'Description' }
108+ ]
109+ }
110+ ) ;
0 commit comments