Skip to content

Commit 4698efa

Browse files
author
Hector Arce De Las Heras
committed
Enhance Code Readability and User Interface of Application
This commit focuses on improving the code readability and user interface of the application. The changes are primarily in the ErrorMessageStandAlone component and the style properties. Key changes include: errorMessage.tsx: Refactored the rendering of error messages and error icons to improve readability. This change simplifies the conditional rendering by checking for an error state before rendering the error icon and message. input.stories.tsx: Removed the icon property from commonArgs, shifting towards using leftIcon and rightIcon properties for icon placement. styles.ts: Updated padding and alignment properties in commonProps for better alignment and spacing. This includes changing the padding property in inputContainer, updating the text_align property in helpMessage, and adjusting the left and right properties in inputIconContainerRight and inputIconContainerLeft to use constants from SPACINGS. input.mixin.ts: Modified the getIconPadding function to ensure the padding is correctly calculated when only one value is provided. These changes enhance the readability of the code and the user interface, leading to a better user experience and easier maintenance.
1 parent 7cf24ca commit 4698efa

File tree

9 files changed

+27
-39
lines changed

9 files changed

+27
-39
lines changed

src/components/input/__tests__/input.test.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ function backspace(element) {
5454
fireEvent.keyUp(element, sharedEventConfig);
5555
}
5656

57-
global.structuredClone = jest.fn(val => {
58-
return JSON.parse(JSON.stringify(val));
59-
});
60-
6157
const writeText = jest.fn();
6258

6359
Object.assign(navigator, {
@@ -295,7 +291,7 @@ describe('New Input Component', () => {
295291
informationAssociatedValue: undefined,
296292
informationAssociatedIcon: undefined,
297293
};
298-
const { container, getByText, getByAltText } = renderProvider(
294+
const { container, getByText, getByLabelText } = renderProvider(
299295
<Input
300296
{...commonProps}
301297
{...informationAssociatedConfig}
@@ -308,7 +304,7 @@ describe('New Input Component', () => {
308304
const errorMessage = getByText('ERROR');
309305
expect(errorMessage).toBeInTheDocument();
310306

311-
const errorIcon = getByAltText('Error alt text');
307+
const errorIcon = getByLabelText('Error alt text');
312308
expect(errorIcon).toBeInTheDocument();
313309
// A11Y and w3c validator
314310
const results = await axe(container);

src/components/input/components/errorMessage.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@ export const ErrorMessageStandAlone = (props: IErrorMessage): JSX.Element => {
1515
id={props.errorMessageId}
1616
styles={props.styles}
1717
>
18-
{props.errorMessage?.content && hasError(props.state) ? (
19-
<Text
20-
customTypography={props.styles?.errorMessage}
21-
dataTestId={`${props.dataTestId}ErrorMessage`}
22-
{...props.errorMessage}
23-
>
24-
{props.errorIcon?.icon && (
25-
<ErrorIconWrapperStyled styles={props.styles}>
26-
<ElementOrIcon
27-
customIconStyles={props.styles?.errorMessageIcon}
28-
{...props.errorIcon}
29-
/>
30-
</ErrorIconWrapperStyled>
31-
)}
32-
{props.errorMessage.content}
33-
</Text>
34-
) : null}
18+
{hasError(props.state) && (
19+
<>
20+
<ErrorIconWrapperStyled styles={props.styles}>
21+
<ElementOrIcon customIconStyles={props.styles?.errorMessageIcon} {...props.errorIcon} />
22+
</ErrorIconWrapperStyled>
23+
<Text
24+
customTypography={props.styles?.errorMessage}
25+
dataTestId={`${props.dataTestId}ErrorMessage`}
26+
{...props.errorMessage}
27+
>
28+
{props.errorMessage?.content}
29+
</Text>
30+
</>
31+
)}
3532
</InputErrorStyled>
3633
);
3734
};

src/components/input/components/informationAssociated.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export const InformationAssociatedStandAlone = (
4444
/>
4545
) : (
4646
<ElementOrIcon
47-
color={props.styles?.informationAssociatedIcon?.color}
48-
height={props.styles?.informationAssociatedIcon?.height}
49-
width={props.styles?.informationAssociatedIcon?.width}
47+
customIconStyles={props.styles?.informationAssociatedIcon}
5048
{...props.informationAssociatedIcon}
5149
/>
5250
);

src/components/input/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export { InputControlled } from './inputControlled';
55
export { InputUnControlled as Input } from './inputUnControlled';
66

77
export * from './input.styled';
8+
9+
export * from './utils';

src/components/input/input.styled.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const InfoAssociatedButtonStyled = styled.div<InformationAssociatedStyled
5252
export const InputErrorAndHelpMessageWrapperStyled = styled.div`
5353
display: flex;
5454
flex-direction: column;
55+
width: 100%;
5556
`;
5657

5758
export const InputErrorStyled = styled.div<ErrorMessageStyledProps>`
@@ -179,8 +180,6 @@ export const InputStyled = styled.input<InputStyledProps>`
179180
cursor: ${cursorPointer};
180181
`}
181182
182-
padding-left: ${({ styles, state, leftIcon }) =>
183-
leftIcon && styles?.[state]?.inputContainer?.padding_left};
184183
box-shadow: ${({ styles, state }) => styles?.[state]?.inputContainer?.box_shadow};
185184
${({
186185
theme: {

src/components/input/inputStandAlone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const InputStandAloneComponent = (
7979
aria-labelledby={buildAriaLabelledBy({
8080
extraAriaLabelledBy,
8181
labelId,
82-
helpMessage: helpMessage?.content,
82+
helpMessage: helpMessage?.content as string,
8383
helpMessageId,
8484
errorMessage: errorMessage?.content,
8585
errorMessageId,

src/components/input/stories/input.stories.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22

33
import { ICONS } from '@/assets';
4-
import { IconHighlightedType } from '@/components/iconHighlighted';
54
import { STYLES_NAME } from '@/constants';
65
import { themesObject, variantsObject } from '@/designSystem/themesObject';
76

@@ -40,15 +39,12 @@ const commonArgs: IInputUnControlled = {
4039
title: { content: 'Title', component: InputTitleComponentType.H1 },
4140
errorMessage: { content: 'Error message' },
4241
errorIcon: { icon: ICONS.ICON_PLACEHOLDER },
43-
highlightedInformationAssociatedIcon: {
42+
informationAssociatedIcon: {
4443
icon: ICONS.ICON_PLACEHOLDER,
4544
altText: 'unicorn alt text',
46-
type: IconHighlightedType.INFORMATIVE,
4745
position: InputIconPosition.LEFT,
4846
},
4947
informationAssociatedValue: { content: 'Lorem ipsum dolor sit. Lorem ipsum dolor sit amet' },
50-
iconPosition: InputIconPosition.RIGHT,
51-
icon: { icon: ICONS.ICON_PLACEHOLDER },
5248
leftIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'icon alt text' },
5349
rightIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'icon alt text' },
5450
secondaryLabel: labelSecondary(themeSelected),

src/designSystem/kubit/components/input/styles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const commonProps = {
4343
},
4444
inputContainer: {
4545
opacity: '1',
46-
padding_left: SPACINGS.spacing_50,
4746
padding: SPACINGS.spacing_250,
4847
background_color: COLORS.NEUTRAL.color_neutral_bg_250,
4948
border_width: BORDERS.border_50,
@@ -57,7 +56,7 @@ const commonProps = {
5756
color: COLORS.NEUTRAL.color_neutral_font_50,
5857
},
5958
helpMessage: {
60-
font_align: TEXT_ALIGN.left,
59+
text_align: TEXT_ALIGN.left,
6160
font_weight: FONT_WEIGHT.font_weight_300,
6261
color: COLORS.NEUTRAL.color_neutral_font_100,
6362
font_variant: TextVariantType.PARAGRAPH_CAPTION_EXPANDED,
@@ -85,14 +84,14 @@ const commonProps = {
8584
position: 'absolute',
8685
top: '50%',
8786
transform: 'translate(0%, -50%)',
88-
left: '0.625rem',
87+
left: SPACINGS.spacing_250,
8988
},
9089
inputIconContainerRight: {
9190
position: 'absolute',
9291
top: '50%',
9392
transform: 'translate(0%, -50%)',
9493
left: 'auto',
95-
right: '1.1rem',
94+
right: SPACINGS.spacing_250,
9695
},
9796
loaderContainer: {
9897
position: 'absolute',
@@ -170,6 +169,7 @@ const errorProps = {
170169
errorMessageIcon: {
171170
width: SIZES.size_150,
172171
height: SIZES.size_150,
172+
color: COLORS.FEEDBACK.color_feedbackError_icon_100,
173173
},
174174
placeholder: {
175175
...commonProps.placeholder,

src/styles/mixins/input.mixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export const getIconPadding = (
193193
rightIcon?: boolean,
194194
styles?: InputBasicStateProps
195195
): CSSProp | undefined => {
196-
const padding = styles?.inputContainer?.padding?.split(' ')[1] || null;
196+
const padding = styles?.inputContainer?.padding?.split(' ')[1] || styles?.inputContainer?.padding;
197197
const iconWidth = styles?.inputIcon?.width;
198198

199199
if (leftIcon && rightIcon) {

0 commit comments

Comments
 (0)