Skip to content

Commit b3713dd

Browse files
committed
feat(inputs): add isError prop to enhance error handling
Added the `isError` property to the input components within the ra-inputs package, allowing for improved error state management. This change updates the component styles to display error-specific colors when `isError` is true, ensuring consistent visual feedback. Additionally, certain optional properties like `borderWidth` and `disabled` are now explicitly marked as optional in the TypeScript interfaces, increasing flexibility in their usage. These enhancements collectively improve the user experience by providing clearer input validation feedback.
1 parent 7055359 commit b3713dd

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

npm-packages/src/packages/components/ra-inputs/src/input.props.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @ Author: Redon Alla
33
* @ Create Time: 2024-06-17 22:55:53
44
* @ Modified by: Redon Alla
5-
* @ Modified time: 2025-02-01 23:50:28
5+
* @ Modified time: 2025-02-02 19:23:08
66
* @ Description: Defines interfaces and types commonly used for input components, specifically tailored for a UI library or framework based on React Native. It provides a structured way to define the properties that these components will accept.
77
*/
88

@@ -51,12 +51,18 @@ export interface BaseInputProps extends TextInputProps {
5151
* @default 'medium'
5252
*/
5353
radius?: BorderRadius;
54+
55+
56+
/** Indicates if the input has an error state.
57+
* @default false
58+
*/
59+
isError?: boolean;
5460

5561
/**
5662
* Optional property to specify the width of the input borders.
5763
* @default 'hairline'
5864
*/
59-
borderWidth: BorderWidth;
65+
borderWidth?: BorderWidth;
6066

6167
/**
6268
* Color of the border as per `react-native` ColorValue standards.

npm-packages/src/packages/components/ra-inputs/src/input.styles.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ContainerProps = {
2828
color: Color;
2929
size: Sizes;
3030
radius: BorderRadius;
31+
isError?: boolean;
3132
borderWidth?: BorderWidth;
3233
disabled?: boolean;
3334
readOnly?: boolean;
@@ -118,6 +119,7 @@ export function createStyles(props: ContainerProps) {
118119
fontSize: iconSize,
119120
textAlign: 'center',
120121
verticalAlign: 'middle',
122+
color: props.isError ? props.theme.colors.isError : props.theme.colors.text,
121123
},
122124
container: {
123125
flexDirection: 'row',
@@ -136,10 +138,12 @@ export function createStyles(props: ContainerProps) {
136138
},
137139
containerFocus: {
138140
backgroundColor: props.activeBackgroundColor ?? backgroundColor,
139-
borderColor: focusBorderColor,
141+
borderColor: props.isError ? props.theme.colors.error : focusBorderColor,
140142
},
141143
containerNotFocus: {
142-
borderColor: props.disabled ? 'transparent' : props.borderColor || themeColor,
144+
borderColor: props.isError
145+
? props.theme.colors.error
146+
: props.disabled ? 'transparent' : props.borderColor || themeColor,
143147
backgroundColor:
144148
props.disabled
145149
? props.theme.colors.default
@@ -151,7 +155,7 @@ export function createStyles(props: ContainerProps) {
151155
},
152156
label: {
153157
fontFamily: 'Regular',
154-
color: props.theme.colors.text,
158+
color: props.isError ? props.theme.colors.isError : props.theme.colors.text,
155159
marginBottom: TEXT_HELPER_MARGIN_TOP_MULTIPLIER * paddingVertical,
156160
fontSize: props.material ? TEXT_HELPER_MULTIPLIER * fontSize : fontSize,
157161
},

npm-packages/src/packages/components/ra-inputs/src/number-text-box/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default class extends React.PureComponent<NumberTextBoxProps, State> {
122122
type,
123123
size,
124124
radius,
125+
isError,
125126
borderWidth,
126127
borderColor,
127128
activeBackgroundColor,
@@ -161,6 +162,7 @@ export default class extends React.PureComponent<NumberTextBoxProps, State> {
161162
color: color!,
162163
size: size!,
163164
radius: radius!,
165+
isError: isError!,
164166
borderWidth: borderWidth,
165167
disabled: disabled,
166168
readOnly: readOnly,

npm-packages/src/packages/components/ra-inputs/src/number-text-box/number-actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ActionProps = {
2828
/**
2929
* Indicates if the action is disabled.
3030
*/
31-
disabled: boolean;
31+
disabled?: boolean;
3232

3333
/**
3434
* Specifies the icon type.

npm-packages/src/packages/components/ra-inputs/src/text-box.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ export default class TextBox extends React.PureComponent<BaseInputProps, State>
7878
this.setState({isFocused: false});
7979

8080
this.props.onBlur?.(e);
81-
};
81+
}
8282

8383
/**
8484
* Handles focus event and updates focus state. It also calls a parent's onFocus callback.
8585
* @param {NativeSyntheticEvent<TextInputFocusEventData>} e
8686
*/
87-
private handleFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
87+
public handleFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
8888
if(!this.props.disabled)
8989
this.setState({isFocused: true});
9090

@@ -109,6 +109,7 @@ export default class TextBox extends React.PureComponent<BaseInputProps, State>
109109
type,
110110
size,
111111
radius,
112+
isError,
112113
borderWidth,
113114
borderColor,
114115
activeBackgroundColor,
@@ -146,6 +147,7 @@ export default class TextBox extends React.PureComponent<BaseInputProps, State>
146147
color: color!,
147148
size: size!,
148149
radius: radius!,
150+
isError: isError!,
149151
borderWidth: borderWidth,
150152
disabled: disabled,
151153
readOnly: readOnly,

0 commit comments

Comments
 (0)