Skip to content

Commit ac9cbe8

Browse files
author
Georgi2704
committed
Added custom footer buttons text and colors
1 parent 86dc879 commit ac9cbe8

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pydantic-forms': patch
3+
---
4+
5+
Add custom button text and colors

frontend/packages/pydantic-forms/src/components/form/Footer.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ const Footer = ({
1414
onPrevious,
1515
hasNext,
1616
hasPrevious,
17+
buttons,
1718
}: PydanticFormFooterProps) => {
1819
const t = useTranslations('footer');
1920
const submitButtonLabel = hasNext ? t('send') : t('submit');
2021
const PreviousButton = () => (
2122
<button
2223
type="button"
2324
onClick={() => onPrevious?.()}
24-
style={{ padding: '12px' }}
25+
style={{
26+
padding: '12px',
27+
backgroundColor: buttons?.previous?.color,
28+
}}
2529
>
26-
{t('previous')}
30+
{buttons.next.text ?? t('previous')}
2731
</button>
2832
);
2933

@@ -40,8 +44,11 @@ const Footer = ({
4044
};
4145

4246
const SubmitButton = () => (
43-
<button type="submit" style={{ padding: '12px' }}>
44-
{submitButtonLabel}
47+
<button
48+
type="submit"
49+
style={{ padding: '12px', backgroundColor: buttons?.next?.color }}
50+
>
51+
{buttons.next.text ?? submitButtonLabel}
4552
</button>
4653
);
4754

frontend/packages/pydantic-forms/src/core/ReactHookForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export const ReactHookForm = ({
110110
handleSubmit(_.cloneDeep(data));
111111
};
112112

113+
const buttons = defaultValues?.buttons ?? {};
114+
113115
return (
114116
<FormProvider {...reactHookForm}>
115117
<form onSubmit={reactHookForm.handleSubmit(onSubmit)}>
@@ -123,6 +125,7 @@ export const ReactHookForm = ({
123125
hasNext={hasNext}
124126
hasPrevious={hasPrevious}
125127
onPrevious={onPrevious}
128+
buttons={buttons}
126129
/>
127130
</form>
128131
</FormProvider>

frontend/packages/pydantic-forms/src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,22 @@ export enum Locale {
448448
nlNL = 'nl-NL',
449449
}
450450

451+
export type PydanticFormButtonProps = {
452+
text?: string;
453+
color?: string;
454+
};
455+
456+
export type PydanticFormButtons = {
457+
next: PydanticFormButtonProps;
458+
previous: PydanticFormButtonProps;
459+
};
460+
451461
export interface PydanticFormFooterProps {
452462
hasNext: boolean;
453463
hasPrevious: boolean;
454464
onCancel?: (e?: React.BaseSyntheticEvent) => void;
455465
onPrevious?: () => void;
466+
buttons: PydanticFormButtons;
456467
}
457468

458469
export interface PydanticFormHeaderProps {

0 commit comments

Comments
 (0)