Skip to content

Commit 41323c4

Browse files
author
Hector Arce De Las Heras
committed
Add prefixNode prop to InputPhone component
This commit introduces a new prop, prefixNode, to the InputPhone component. This allows for greater flexibility in customizing the component, as users can now provide a custom node to be rendered as a prefix in the input field. This enhances the component's versatility and adaptability to various use cases.
1 parent 1a78d64 commit 41323c4

File tree

9 files changed

+63
-36
lines changed

9 files changed

+63
-36
lines changed

src/components/inputDropdown/inputDropdown.styled.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ type InputDropdownCustomHeightType = {
2323
useActionBottomSheet?: boolean;
2424
};
2525

26-
export const InputDropdownStyled = styled.div`
26+
export const InputDropdownStyled = styled.div<InputDropdownStylesType>`
2727
position: relative;
2828
display: flex;
2929
flex-direction: column;
30+
${({ styles }) => getStyles(styles?.inputDropdownContainer)}
3031
`;
3132

3233
const buildHeight = ({
@@ -57,7 +58,7 @@ export const ListContainerStyled = styled.div<
5758
InputDropdownStylesType & InputDropdownCustomHeightType
5859
>`
5960
transition: height 200ms;
60-
${({ styles }) => getStyles(styles?.searchListContainer)}/* div { */
61+
${({ styles }) => getStyles(styles?.searchListContainer)}
6162
`;
6263

6364
export const InputDropdownListStyled = styled.div<

src/components/inputDropdown/inputDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const InputDropdownBoundary = <V extends string | unknown>(
135135
</FallbackComponent>
136136
}
137137
>
138-
<InputDropdownComponent {...props} />
138+
<InputDropdownComponent {...props} ref={ref} />
139139
</ErrorBoundary>
140140
);
141141

src/components/inputDropdown/inputDropdownStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const InputDropdownStandAloneComponent = (
2626
return (
2727
<InputDropdownStyled
2828
data-testid={`${props.dataTestId}InputDropdown`}
29+
styles={props.styles?.[props.state]}
2930
onKeyDown={e => {
3031
if (props.device === DeviceBreakpointsType.DESKTOP && isKeyTabPressed(e.key)) {
3132
props.onOpenOptions(false);

src/components/inputDropdown/stories/inputDropdown.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const commonArgs: IInputDropdown = {
5858
label: 'option 2',
5959
},
6060
],
61+
['aria-label']: 'Label',
6162
},
6263
};
6364

src/components/inputDropdown/types/inputDropdown.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ import {
1414
InputDropdownStylesProps,
1515
} from './inputDropdownTheme';
1616

17+
export type InputDropdownOptionsAriasTypes = Pick<
18+
React.AriaAttributes,
19+
'aria-label' | 'aria-labelledby'
20+
>;
21+
1722
export type InputDropdownOptionsType = {
1823
options: ListOptionsOptionType[];
1924
optionVariant?: string;
2025
listOptionsVariant?: string;
21-
};
26+
} & InputDropdownOptionsAriasTypes;
2227

2328
export interface IPopoverDropdownList {
2429
open: boolean;

src/components/inputDropdown/types/inputDropdownTheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type InputDropdownStateProps = InputBasicStateProps & {
77
popoverVariant?: { [key in DeviceBreakpointsType]?: string };
88
useActionBottomSheet?: { [key in DeviceBreakpointsType]?: boolean };
99
actionBottomSheetVariant?: string;
10+
inputDropdownContainer?: CommonStyleType;
1011
searchListContainer?: CommonStyleType;
1112
searchListSubContainer?: CommonStyleType;
1213
loaderExpandedContainer?: CommonStyleType;

src/components/inputPhone/inputPhoneStandAlone.tsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ export const InputPhoneStandAloneComponent = (
3737
: inputAffixId;
3838

3939
const flagVariant =
40-
props.flag.variant ?? props.styles?.[props.state]?.affixIconHighlighted?.variant;
41-
const flagSize = props.flag.size ?? props.styles?.[props.state]?.affixIconHighlighted?.size;
40+
props.flag?.variant ?? props.styles?.[props.state]?.affixIconHighlighted?.variant;
41+
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]}>
4444
{props.prefixNode ? (
4545
props.prefixNode
4646
) : (
4747
<>
4848
<AffixIconWrapperStyled styles={props.styles?.[props.state]}>
49-
{props.flag.type && flagVariant && flagSize ? (
49+
{props.flag?.type && flagVariant && flagSize ? (
5050
<IconHighlighted
5151
backgroundColor={props.styles?.[props.state]?.affixIconHighlighted?.backgroundColor}
5252
size={
@@ -82,38 +82,50 @@ export const InputPhoneStandAloneComponent = (
8282
<Input
8383
{...props}
8484
ref={ref}
85-
bottomExtraStyles={getExtraStyles(
86-
POSITIONS.BOTTOM,
87-
POSITIONS.LEFT,
88-
width,
89-
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
90-
props.styles?.[props.state]?.helpMessage?.position
91-
)}
92-
centerExtraStyles={getExtraStyles(
93-
POSITIONS.CENTER,
94-
POSITIONS.LEFT,
95-
width,
96-
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
97-
props.styles?.[props.state]?.helpMessage?.position
98-
)}
85+
bottomExtraStyles={
86+
props.styles?.[props.state]?.bottomExtraStyles ??
87+
getExtraStyles(
88+
POSITIONS.BOTTOM,
89+
POSITIONS.LEFT,
90+
width,
91+
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
92+
props.styles?.[props.state]?.helpMessage?.position
93+
)
94+
}
95+
centerExtraStyles={
96+
props.styles?.[props.state]?.centerExtraStyles ??
97+
getExtraStyles(
98+
POSITIONS.CENTER,
99+
POSITIONS.LEFT,
100+
width,
101+
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
102+
props.styles?.[props.state]?.helpMessage?.position
103+
)
104+
}
99105
extraAriaLabelledBy={extraAriaLabelledBy}
100106
id={inputId}
101107
leftContent={renderAffix()}
102-
leftExtraStyles={getExtraStyles(
103-
POSITIONS.LEFT,
104-
POSITIONS.LEFT,
105-
width,
106-
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
107-
props.styles?.[props.state]?.helpMessage?.position
108-
)}
108+
leftExtraStyles={
109+
props.styles?.[props.state]?.leftExtraStyles ??
110+
getExtraStyles(
111+
POSITIONS.LEFT,
112+
POSITIONS.LEFT,
113+
width,
114+
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
115+
props.styles?.[props.state]?.helpMessage?.position
116+
)
117+
}
109118
overrideStyles={props.styles}
110-
topExtraStyles={getExtraStyles(
111-
POSITIONS.TOP,
112-
POSITIONS.LEFT,
113-
width,
114-
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
115-
props.styles?.[props.state]?.helpMessage?.position
116-
)}
119+
topExtraStyles={
120+
props.styles?.[props.state]?.topExtraStyles ??
121+
getExtraStyles(
122+
POSITIONS.TOP,
123+
POSITIONS.LEFT,
124+
width,
125+
props.styles?.[props.state]?.affixContainerPosition === InputContentPosition.OUT,
126+
props.styles?.[props.state]?.helpMessage?.position
127+
)
128+
}
117129
variant={props.inputVariant ?? props.styles?.[props.state]?.inputVariant}
118130
/>
119131
</div>

src/components/inputPhone/types/inputPhone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type InputPhonePrefixType = Omit<IText<string>, 'children'> & {
2525

2626
export interface IInputPhoneStandAlone extends Omit<IInputStandAlone, propsToOmitInputBasic> {
2727
styles: InputPhoneStylesProps;
28-
flag: InputPhoneFlagType;
28+
flag?: InputPhoneFlagType;
2929
prefix?: InputPhonePrefixType;
3030
prefixNode?: React.ReactNode;
3131
inputVariant?: string;

src/components/inputPhone/types/inputPhoneTheme.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CSSProp } from 'styled-components';
2+
13
import { IconHighlightedSizeType } from '@/components/iconHighlighted/types/size';
24
import {
35
InputBasicStateProps,
@@ -19,6 +21,10 @@ export type InputPhoneStateProps = InputBasicStateProps & {
1921
backgroundColor?: string;
2022
};
2123
affixIconHighlightedContainer?: CommonStyleType;
24+
leftExtraStyles?: CSSProp;
25+
centerExtraStyles?: CSSProp;
26+
topExtraStyles?: CSSProp;
27+
bottomExtraStyles?: CSSProp;
2228
};
2329

2430
export type InputPhoneStylesProps = {

0 commit comments

Comments
 (0)