Skip to content

Commit 7f20848

Browse files
Lara HarrowLuke Bowerman
authored andcommitted
updated InputText to have Icon warning when ValidationType = error
1 parent d55cd97 commit 7f20848

File tree

3 files changed

+94
-55
lines changed

3 files changed

+94
-55
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- removed labelFontWeight from FieldInline and update test for it
1717

18+
### Fixed
19+
20+
- updated InputText to have Icon warning when ValidationType = error
21+
1822
## [0.7.27] - 2020-04-15
1923

2024
### Added

packages/components/src/Form/Inputs/InputText/InputText.tsx

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ export interface InputTextProps
9191
const InputComponent = forwardRef(
9292
(
9393
{
94-
type = 'text',
94+
className,
9595
iconAfter,
9696
iconBefore,
9797
prefix,
9898
suffix,
99-
className,
99+
type = 'text',
100+
validationType,
100101
...props
101102
}: InputTextProps,
102103
forwardedRef: Ref<HTMLInputElement>
@@ -142,24 +143,18 @@ const InputComponent = forwardRef(
142143
inputPropKeys
143144
)
144145

145-
if (before || after) {
146-
return (
147-
<InputLayout className={className} onClick={focusInput}>
148-
{before}
149-
<input {...inputProps} type={type} ref={ref} />
150-
{after}
151-
</InputLayout>
152-
)
153-
} else {
154-
return (
155-
<StyledInput
156-
{...inputProps}
157-
className={className}
158-
type={type}
159-
ref={ref}
160-
/>
161-
)
162-
}
146+
return (
147+
<InputLayout className={className} onClick={focusInput}>
148+
{before && before}
149+
<input {...inputProps} type={type} ref={ref} />
150+
{after && after}
151+
{validationType && (
152+
<InputIconStyle paddingLeft="xsmall">
153+
<Icon color="palette.red500" name="Warning" size={18} />
154+
</InputIconStyle>
155+
)}
156+
</InputLayout>
157+
)
163158
}
164159
)
165160

@@ -181,27 +176,11 @@ export const inputTextDisabled = css`
181176

182177
export const inputHeight = '36px'
183178

184-
const shared = css`
185-
height: ${inputHeight};
186-
187-
::placeholder {
188-
color: ${(props) => props.theme.colors.palette.charcoal400};
189-
}
190-
191-
&:hover {
192-
${inputTextHover}
193-
}
194-
&:focus,
195-
:focus-within {
196-
${inputTextFocus}
197-
}
198-
`
199-
200179
export const InputLayout = styled.div`
201-
${shared}
202180
align-items: center;
203181
background-color: ${(props) => props.theme.colors.palette.white};
204182
display: inline-flex;
183+
height: ${inputHeight};
205184
justify-content: space-evenly;
206185
207186
input {
@@ -214,10 +193,18 @@ export const InputLayout = styled.div`
214193
outline: none;
215194
padding: 0;
216195
}
217-
`
218196
219-
const StyledInput = styled.input`
220-
${shared}
197+
::placeholder {
198+
color: ${(props) => props.theme.colors.palette.charcoal400};
199+
}
200+
201+
&:hover {
202+
${inputTextHover}
203+
}
204+
&:focus,
205+
:focus-within {
206+
${inputTextFocus}
207+
}
221208
`
222209

223210
export const InputIconStyle = styled(Flex)`

packages/playground/src/Form/FieldsDemo.tsx

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,77 @@ export const FieldsDemo: FC = () => {
5252
inline
5353
label="Text Input"
5454
placeholder="placeholder"
55+
/>{' '}
56+
<FieldText
57+
label="Text Input"
58+
placeholder="placeholder"
59+
validationMessage={{ message: 'validation Message', type: 'error' }}
60+
/>
61+
<FieldText
62+
inline
63+
label="Text Input"
64+
placeholder="placeholder"
65+
validationMessage={{ message: 'validation Message', type: 'error' }}
66+
/>
67+
<FieldText
68+
label="Text Input"
69+
iconBefore="GearOutline"
70+
placeholder="placeholder"
71+
validationMessage={{ message: 'validation Message', type: 'error' }}
72+
/>
73+
<FieldText
74+
inline
75+
label="Text Input"
76+
iconBefore="GearOutline"
77+
placeholder="placeholder"
78+
validationMessage={{ message: 'validation Message', type: 'error' }}
79+
/>
80+
<FieldText
81+
label="Text Input"
82+
iconAfter="Check"
83+
placeholder="placeholder"
84+
validationMessage={{ message: 'validation Message', type: 'error' }}
85+
/>
86+
<FieldText
87+
inline
88+
label="Text Input"
89+
iconAfter="Check"
90+
placeholder="placeholder"
91+
validationMessage={{ message: 'validation Message', type: 'error' }}
92+
/>
93+
<FieldText
94+
label="Text Input"
95+
suffix="%"
96+
placeholder="placeholder"
97+
validationMessage={{ message: 'validation Message', type: 'error' }}
98+
/>
99+
<FieldText
100+
inline
101+
label="Text Input"
102+
suffix="%"
103+
placeholder="placeholder"
104+
validationMessage={{ message: 'validation Message', type: 'error' }}
105+
/>
106+
<FieldText
107+
label="Text Input"
108+
prefix="$"
109+
placeholder="placeholder"
110+
validationMessage={{ message: 'validation Message', type: 'error' }}
111+
/>
112+
<FieldText
113+
inline
114+
label="Text Input"
115+
prefix="$"
116+
placeholder="placeholder"
117+
validationMessage={{ message: 'validation Message', type: 'error' }}
55118
/>
56-
57119
<FieldText label="Text Input" placeholder="placeholder" required />
58120
<FieldText
59121
inline
60122
label="Text Input"
61123
placeholder="placeholder"
62124
required
63125
/>
64-
65126
<FieldText
66127
description="no vegetables allowed"
67128
label="Text Input"
@@ -73,30 +134,23 @@ export const FieldsDemo: FC = () => {
73134
label="Text Input"
74135
placeholder="placeholder"
75136
/>
76-
77137
<FieldText label="Label" prefix="$" />
78138
<FieldText inline label="Label" prefix="$" />
79-
80139
<FieldText label="Label" iconBefore="GearOutline" />
81140
<FieldText inline label="Label" iconBefore="GearOutline" />
82-
83141
<FieldText label="Label" suffix="%" />
84142
<FieldText inline label="Label" suffix="%" />
85-
86143
<FieldText label="Label" iconAfter="Check" />
87144
<FieldText inline label="Label" iconAfter="Check" />
88-
89145
<FieldText label="Label" prefix="$" iconAfter="Check" />
90146
<FieldText inline label="Label" prefix="$" iconAfter="Check" />
91-
92147
<FieldText label="hello" detail="5/50" placeholder="placeholder" />
93148
<FieldText
94149
inline
95150
label="hello"
96151
detail="5/50"
97152
placeholder="placeholder"
98153
/>
99-
100154
<FieldText
101155
label="Label"
102156
required
@@ -112,21 +166,17 @@ export const FieldsDemo: FC = () => {
112166
description="A special kind of thing..."
113167
detail="What?"
114168
/>
115-
116169
<FieldTextArea label="Text Area" />
117170
<FieldTextArea placeholder="Neat stuff" inline label="Text Area" />
118-
119171
<FieldTextArea label="Text Area" disabled />
120172
<FieldTextArea
121173
placeholder="Neat stuff"
122174
inline
123175
label="Text Area"
124176
disabled
125177
/>
126-
127178
<FieldTextArea label="Text Area" required placeholder="Hello world" />
128179
<FieldTextArea inline label="Text Area" required />
129-
130180
<FieldTextArea
131181
label="Text Area"
132182
validationMessage={{ message: 'validation Message', type: 'error' }}
@@ -137,7 +187,6 @@ export const FieldsDemo: FC = () => {
137187
required
138188
validationMessage={{ message: 'validation Message', type: 'error' }}
139189
/>
140-
141190
<FieldSelect
142191
label="Label"
143192
placeholder="placeholder"
@@ -157,7 +206,6 @@ export const FieldsDemo: FC = () => {
157206
{ label: 'Swiss', value: 'swiss' },
158207
]}
159208
/>
160-
161209
<FieldSelect
162210
label="Label"
163211
placeholder="placeholder"

0 commit comments

Comments
 (0)