Skip to content

Commit 052617e

Browse files
authored
Merge pull request #226 from deriv-com/codex/extend-steppertextfield-to-support-suffix
Matin/Implement StepperTextField suffix support
2 parents 76cb339 + 36fd41a commit 052617e

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/features/dashboard/components/stepper-text-field/__tests__/stepperTextField.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('StepperTextField', () => {
2020
});
2121
});
2222

23-
const renderStepperTextField = () => {
23+
const renderStepperTextField = (props?: Partial<React.ComponentProps<typeof StepperTextField>>) => {
2424
render(
2525
<StepperTextField
2626
handleOnMinusClick={() => jest.fn()}
@@ -31,6 +31,7 @@ describe('StepperTextField', () => {
3131
error={{
3232
type: 'min',
3333
}}
34+
{...props}
3435
/>,
3536
);
3637
};
@@ -40,4 +41,9 @@ describe('StepperTextField', () => {
4041
const input = screen.getByTestId('stepper-text-field');
4142
expect(input).toBeInTheDocument();
4243
});
44+
45+
it('should render suffix when provided', () => {
46+
renderStepperTextField({ suffix: '%' });
47+
expect(screen.getByTestId('stepper-text-field-suffix')).toHaveTextContent('%');
48+
});
4349
});

src/features/dashboard/components/stepper-text-field/stepper-text-field.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
width: 340px;
1717
display: flex;
1818
justify-content: space-between;
19+
align-items: center;
1920
padding-block: 12px;
2021
border: 1px solid rgba(0, 0, 0, 0.08);
2122
}
23+
24+
&__suffix {
25+
margin-left: 8px;
26+
}
2227
}

src/features/dashboard/components/stepper-text-field/stepper-text-field.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ type StepperTextFieldProps = {
1010
name: string;
1111
min: number;
1212
max: number;
13+
/**
14+
* Optional element to display after the input value
15+
*/
16+
suffix?: React.ReactNode;
1317
error: {
1418
type: string;
1519
};
@@ -21,6 +25,7 @@ const StepperTextField: React.FC<StepperTextFieldProps> = ({
2125
name,
2226
min,
2327
max,
28+
suffix,
2429
error,
2530
...rest
2631
}) => {
@@ -65,6 +70,11 @@ const StepperTextField: React.FC<StepperTextFieldProps> = ({
6570
{...register(name)}
6671
{...rest}
6772
/>
73+
{suffix && (
74+
<span className='stepper_text_field__suffix' data-testid='stepper-text-field-suffix'>
75+
{suffix}
76+
</span>
77+
)}
6878
<Button
6979
color='black'
7080
icon={<LabelPairedPlusSmFillIcon />}

src/features/dashboard/update-app/AppUpdateForm/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const AppUpdateForm = ({ initialValues, submit, onCancel, is_loading }: TAppForm
149149
}}
150150
min={0}
151151
max={3}
152+
suffix='%'
152153
error={errors?.app_markup_percentage}
153154
/>
154155
{errors?.app_markup_percentage && (

0 commit comments

Comments
 (0)