Skip to content

Commit 8a2b1bf

Browse files
committed
feat: default error icon
1 parent 947ef20 commit 8a2b1bf

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/components/TextField/TextField.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414

1515
import { useTextField } from './logic';
1616
import { $addendumStyle } from './styles';
17+
import TextFieldErrorIcon from './TextFieldErrorIcon';
1718
import type { InternalTheme, ThemeProp } from '../../types';
1819

1920
export type TextFieldVariant = 'filled' | 'outlined';
@@ -306,14 +307,16 @@ function TextField(props: TextFieldProps) {
306307
)}
307308
</View>
308309

309-
{!!TrailingAccessory && (
310+
{TrailingAccessory ? (
310311
<TrailingAccessory
311312
style={$trailingAccessoryStyles}
312313
status={status}
313314
editable={!disabled}
314315
multiline={!!textInputProps.multiline}
315316
/>
316-
)}
317+
) : hasError ? (
318+
<TextFieldErrorIcon style={$trailingAccessoryStyles} theme={theme} />
319+
) : null}
317320
</View>
318321

319322
<View style={$addendumStyle}>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { StyleProp, View, ViewStyle } from 'react-native';
3+
4+
import { ACCESSORY_SIZE, ERROR_ICON_SIZE } from './constants';
5+
import { useInternalTheme } from '../../core/theming';
6+
import type { ThemeProp } from '../../types';
7+
import Icon from '../Icon';
8+
9+
interface TextFieldErrorIconProps {
10+
style?: StyleProp<ViewStyle>;
11+
theme?: ThemeProp;
12+
}
13+
14+
const TextFieldErrorIcon = ({
15+
style: $wrapperStyle,
16+
theme: themeOverride,
17+
}: TextFieldErrorIconProps) => {
18+
const theme = useInternalTheme(themeOverride);
19+
20+
const $circleStyle: ViewStyle = {
21+
width: ACCESSORY_SIZE,
22+
height: ACCESSORY_SIZE,
23+
borderRadius: ACCESSORY_SIZE / 2,
24+
justifyContent: 'center',
25+
alignItems: 'center',
26+
backgroundColor: theme.colors.error,
27+
};
28+
29+
return (
30+
<View style={$wrapperStyle}>
31+
<View style={$circleStyle}>
32+
<Icon
33+
source="exclamation-thick"
34+
size={ERROR_ICON_SIZE}
35+
color={theme.colors.onError}
36+
/>
37+
</View>
38+
</View>
39+
);
40+
};
41+
42+
export default TextFieldErrorIcon;

src/components/TextField/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const ACCESSORY_SIZE = 24;
2121
export const PREFIX_END_PADDING = 2;
2222
export const SUFFIX_START_PADDING = 2;
2323

24+
export const ERROR_ICON_SIZE = 16;
25+
2426
// ===============
2527
// TYPOGRAPHY
2628
// ===============

0 commit comments

Comments
 (0)