@@ -55,16 +55,20 @@ export type Code0Input = Omit<
55
55
56
56
// Input component props definition
57
57
export interface InputProps < T > extends Code0Input , ValidationProps < T > {
58
- suggestions ?: InputSuggestion [ ] ; // Optional suggestions shown in dropdown
59
- suggestionsHeader ?: React . ReactNode ; // Custom header above suggestions
60
- suggestionsFooter ?: React . ReactNode ; // Custom footer below suggestions
61
- wrapperComponent ?: Code0Component < HTMLDivElement > ; // Props for the wrapping div
62
- right ?: React . ReactNode ; // Right-side icon or element
63
- left ?: React . ReactNode ; // Left-side icon or element
64
- leftType ?: "action" | "placeholder" | "icon" ; // Visual type for left slot
65
- rightType ?: "action" | "placeholder" | "icon" ; // Visual type for right slot
66
- title ?: React . ReactNode ; // Input label
67
- description ?: React . ReactNode ; // Label description below title
58
+
59
+ suggestions ?: InputSuggestion [ ] // Optional suggestions shown in dropdown
60
+ suggestionsHeader ?: React . ReactNode // Custom header above suggestions
61
+ suggestionsFooter ?: React . ReactNode // Custom footer below suggestions
62
+ transformValue ?: ( value : T ) => React . ReactNode | T // Optional value transformation function
63
+
64
+ wrapperComponent ?: Code0Component < HTMLDivElement > // Props for the wrapping div
65
+ right ?: React . ReactNode // Right-side icon or element
66
+ left ?: React . ReactNode // Left-side icon or element
67
+ leftType ?: "action" | "placeholder" | "icon" // Visual type for left slot
68
+ rightType ?: "action" | "placeholder" | "icon" // Visual type for right slot
69
+ title ?: React . ReactNode // Input label
70
+ description ?: React . ReactNode // Label description below title
71
+
68
72
}
69
73
70
74
const Input : ForwardRefExoticComponent < InputProps < any > > = React . forwardRef (
@@ -137,7 +141,7 @@ const Input: ForwardRefExoticComponent<InputProps<any>> = React.forwardRef(
137
141
< MenuTrigger asChild >
138
142
< input
139
143
ref = { inputRef as LegacyRef < HTMLInputElement > } // Cast for TS compatibility
140
- { ...mergeCode0Props ( "input__control" , rest ) } // Merge styling and native props
144
+ { ...mergeCode0Props ( `input__control ${ props . transformValue ? "input__control--syntax" : "" } ` , rest ) }
141
145
onFocus = { ( ) => ! open && setOpen ( true ) } // Open on focus
142
146
onKeyDown = { ( e ) => {
143
147
if ( e . key === "ArrowDown" ) {
@@ -188,10 +192,21 @@ const Input: ForwardRefExoticComponent<InputProps<any>> = React.forwardRef(
188
192
< input
189
193
tabIndex = { 2 } // Ensure keyboard tab order
190
194
ref = { inputRef as LegacyRef < HTMLInputElement > }
191
- { ...mergeCode0Props ( "input__control" , rest ) } // Basic input styling and props
195
+ { ...mergeCode0Props ( `input__control ${ props . transformValue ? "input__control--syntax" : "" } ` , rest ) } // Basic input styling and props
192
196
/>
193
197
) }
194
198
199
+ { props . transformValue ? (
200
+ < div className = { "input__syntax" } style = { {
201
+ width : inputRef ?. current ?. clientWidth ?? 0 ,
202
+ height : inputRef ?. current ?. clientHeight ?? 0 ,
203
+ top : inputRef ?. current ?. offsetTop ?? 0 ,
204
+ left : inputRef ?. current ?. offsetLeft ?? 0 ,
205
+ } } >
206
+ { props . transformValue ( inputRef ?. current ?. value ?? inputRef ?. current ?. placeholder ?? "sd" ) } { /* Render transformed value */ }
207
+ </ div >
208
+ ) : null }
209
+
195
210
{ right &&
196
211
< div className = { `input__right input__right--${ rightType } ` } > { right } </ div > } { /* Right element */ }
197
212
</ div >
0 commit comments