Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/.changeset/puny-cloths-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pydantic-forms': patch
---

Add custom button text and colors
17 changes: 13 additions & 4 deletions frontend/packages/pydantic-forms/src/components/form/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ const Footer = ({
onPrevious,
hasNext,
hasPrevious,
buttons,
}: PydanticFormFooterProps) => {
const t = useTranslations('footer');
const submitButtonLabel = hasNext ? t('send') : t('submit');
const { next, previous } = buttons || {};

const PreviousButton = () => (
<button
type="button"
onClick={() => onPrevious?.()}
style={{ padding: '12px' }}
style={{
padding: '12px',
backgroundColor: previous?.color,
}}
>
{t('previous')}
{previous?.text ?? t('previous')}
</button>
);

Expand All @@ -40,8 +46,11 @@ const Footer = ({
};

const SubmitButton = () => (
<button type="submit" style={{ padding: '12px' }}>
{submitButtonLabel}
<button
type="submit"
style={{ padding: '12px', backgroundColor: next?.color }}
>
{next?.text ?? submitButtonLabel}
</button>
);

Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/pydantic-forms/src/core/ReactHookForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export const ReactHookForm = ({
handleSubmit(_.cloneDeep(data));
};

const buttons = defaultValues?.buttons ?? {};

return (
<FormProvider {...reactHookForm}>
<form onSubmit={reactHookForm.handleSubmit(onSubmit)}>
Expand All @@ -123,6 +125,7 @@ export const ReactHookForm = ({
hasNext={hasNext}
hasPrevious={hasPrevious}
onPrevious={onPrevious}
buttons={buttons}
/>
</form>
</FormProvider>
Expand Down
11 changes: 11 additions & 0 deletions frontend/packages/pydantic-forms/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,22 @@ export enum Locale {
nlNL = 'nl-NL',
}

export type PydanticFormButtonProps = {
text?: string;
color?: string;
};

export type PydanticFormButtons = {
next: PydanticFormButtonProps;
previous: PydanticFormButtonProps;
};

export interface PydanticFormFooterProps {
hasNext: boolean;
hasPrevious: boolean;
onCancel?: (e?: React.BaseSyntheticEvent) => void;
onPrevious?: () => void;
buttons: PydanticFormButtons;
}

export interface PydanticFormHeaderProps {
Expand Down