Skip to content

Commit 053ffd2

Browse files
author
Hector Arce De Las Heras
committed
Add prefixNode Prop to InputPhone Component
This commit introduces a new prefixNode prop to the InputPhone component. This new prop enhances the flexibility of the component, allowing users to add a custom prefix node to the input field. This can be particularly useful for displaying additional information or customizing the input field's appearance.
1 parent 63be35b commit 053ffd2

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

src/components/input/types/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export type IInformationAssociated = IInformationAssociatedDecoration & {
251251
};
252252

253253
export type InputHelpMessageType = Omit<IText<string>, 'children'> & {
254-
content?: string;
254+
content?: React.ReactNode | string;
255255
};
256256

257257
export interface IHelpMessage {

src/components/input/utils/aria.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const buildAriaLabelledBy = ({
1212
}: {
1313
labelId: string;
1414
extraAriaLabelledBy?: string;
15-
helpMessage?: string;
15+
helpMessage?: React.ReactNode;
1616
helpMessageId?: string;
1717
errorMessage?: string;
1818
errorMessageId: string;

src/components/inputPhone/inputPhoneStandAlone.tsx

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,37 @@ export const InputPhoneStandAloneComponent = (
4141
const flagSize = props.flag.size ?? props.styles?.[props.state]?.affixIconHighlighted?.size;
4242
const renderAffix = () => (
4343
<AffixStyled ref={measuredRef} id={extraAriaLabelledBy} styles={props.styles?.[props.state]}>
44-
<AffixIconWrapperStyled styles={props.styles?.[props.state]}>
45-
{props.flag.type && flagVariant && flagSize ? (
46-
<IconHighlighted
47-
backgroundColor={props.styles?.[props.state]?.affixIconHighlighted?.backgroundColor}
48-
size={
49-
props.styles?.[props.state]?.affixIconHighlighted?.size as IconHighlightedSizeType
50-
}
51-
variant={props.styles?.[props.state]?.affixIconHighlighted?.variant}
52-
{...props.flag}
53-
/>
54-
) : (
55-
<ElementOrIcon
56-
height={props.styles?.[props.state]?.affixIcon?.height}
57-
width={props.styles?.[props.state]?.affixIcon?.width}
58-
{...props.flag}
59-
/>
60-
)}
61-
</AffixIconWrapperStyled>
62-
<Text
63-
customTypography={props.styles?.[props.state]?.affix}
64-
dataTestId={`${props.dataTestId}Suffix`}
65-
{...props.prefix}
66-
>
67-
{props.prefix.content}
68-
</Text>
44+
{props.prefixNode ? (
45+
props.prefixNode
46+
) : (
47+
<>
48+
<AffixIconWrapperStyled styles={props.styles?.[props.state]}>
49+
{props.flag.type && flagVariant && flagSize ? (
50+
<IconHighlighted
51+
backgroundColor={props.styles?.[props.state]?.affixIconHighlighted?.backgroundColor}
52+
size={
53+
props.styles?.[props.state]?.affixIconHighlighted?.size as IconHighlightedSizeType
54+
}
55+
variant={props.styles?.[props.state]?.affixIconHighlighted?.variant}
56+
{...props.flag}
57+
/>
58+
) : (
59+
<ElementOrIcon
60+
height={props.styles?.[props.state]?.affixIcon?.height}
61+
width={props.styles?.[props.state]?.affixIcon?.width}
62+
{...props.flag}
63+
/>
64+
)}
65+
</AffixIconWrapperStyled>
66+
<Text
67+
customTypography={props.styles?.[props.state]?.affix}
68+
dataTestId={`${props.dataTestId}Suffix`}
69+
{...props.prefix}
70+
>
71+
{props.prefix?.content}
72+
</Text>
73+
</>
74+
)}
6975
</AffixStyled>
7076
);
7177

src/components/inputPhone/stories/argtypes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,17 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
6262
category: CATEGORY_CONTROL.CONTENT,
6363
},
6464
},
65+
prefixNode: {
66+
description:
67+
'Node to show into prefix container. If this prop is passed, the prefix prop will be ignored',
68+
control: { type: 'string' },
69+
type: { name: 'string' },
70+
table: {
71+
type: {
72+
summary: 'ReactNode',
73+
},
74+
category: CATEGORY_CONTROL.CONTENT,
75+
},
76+
},
6577
};
6678
};

src/components/inputPhone/types/inputPhone.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export type InputPhonePrefixType = Omit<IText<string>, 'children'> & {
2626
export interface IInputPhoneStandAlone extends Omit<IInputStandAlone, propsToOmitInputBasic> {
2727
styles: InputPhoneStylesProps;
2828
flag: InputPhoneFlagType;
29-
prefix: InputPhonePrefixType;
29+
prefix?: InputPhonePrefixType;
30+
prefixNode?: React.ReactNode;
3031
inputVariant?: string;
3132
}
3233

0 commit comments

Comments
 (0)