@@ -2,10 +2,12 @@ import { ComponentPropsWithoutRef, MutableRefObject, RefCallback } from 'react'
2
2
3
3
import cn from 'classnames'
4
4
5
+ import layoutStyles from 'components/layout/layout.module.css'
6
+ import { Text } from 'components/typography'
7
+
5
8
import { HelperText } from './HelperText'
6
9
import styles from './InputV2.module.css'
7
10
import { useFocusState } from './useFocusState'
8
-
9
11
export enum InputV2Size {
10
12
SMALL ,
11
13
MEDIUM ,
@@ -29,6 +31,8 @@ export type InputV2Props = Omit<ComponentPropsWithoutRef<'input'>, 'size'> & {
29
31
inputClassName ?: string
30
32
label ?: string
31
33
helperText ?: string
34
+ startAdornment ?: string
35
+ endAdornment ?: string
32
36
}
33
37
34
38
export const InputV2 = ( props : InputV2Props ) => {
@@ -51,10 +55,12 @@ export const InputV2 = (props: InputV2Props) => {
51
55
onBlur : onBlurProp ,
52
56
placeholder,
53
57
helperText,
58
+ startAdornment,
59
+ endAdornment,
54
60
...other
55
61
} = props
56
62
57
- const characterCount = value ? `${ value } ` . length : 0
63
+ const characterCount = value !== undefined ? `${ value } ` . length : 0
58
64
const nearCharacterLimit = maxLength && characterCount >= 0.9 * maxLength
59
65
const elevatePlaceholder = variant === InputV2Variant . ELEVATED_PLACEHOLDER
60
66
const label = required ? `${ labelProp } *` : labelProp
@@ -80,18 +86,36 @@ export const InputV2 = (props: InputV2Props) => {
80
86
}
81
87
82
88
const input = (
83
- < input
84
- onFocus = { handleFocus }
85
- onBlur = { handleBlur }
86
- ref = { inputRef }
87
- required = { required }
88
- className = { cn ( styles . textInput , inputClassName ) }
89
- value = { value }
90
- maxLength = { maxLength }
91
- disabled = { disabled }
92
- placeholder = { isFocused ? placeholder : undefined }
93
- { ...other }
94
- />
89
+ < div className = { cn ( styles . inputRow , layoutStyles . row ) } >
90
+ < div className = { layoutStyles . row } >
91
+ { startAdornment ? (
92
+ < Text variant = 'label' size = 'large' color = '--neutral-light-2' >
93
+ { startAdornment }
94
+ </ Text >
95
+ ) : null }
96
+ < input
97
+ onFocus = { handleFocus }
98
+ onBlur = { handleBlur }
99
+ ref = { inputRef }
100
+ required = { required }
101
+ className = { cn ( styles . textInput , inputClassName ) }
102
+ value = { value }
103
+ maxLength = { maxLength }
104
+ disabled = { disabled }
105
+ placeholder = {
106
+ isFocused || startAdornment || endAdornment
107
+ ? placeholder
108
+ : undefined
109
+ }
110
+ { ...other }
111
+ />
112
+ </ div >
113
+ { endAdornment ? (
114
+ < Text variant = 'label' size = 'large' color = '--neutral-light-2' >
115
+ { endAdornment }
116
+ </ Text >
117
+ ) : null }
118
+ </ div >
95
119
)
96
120
97
121
return (
@@ -101,7 +125,8 @@ export const InputV2 = (props: InputV2Props) => {
101
125
< label className = { styles . elevatedLabel } >
102
126
< span
103
127
className = { cn ( styles . label , {
104
- [ styles . hasValue ] : characterCount > 0
128
+ [ styles . hasValue ] :
129
+ characterCount > 0 || startAdornment || endAdornment
105
130
} ) }
106
131
>
107
132
{ label }
0 commit comments