Skip to content

Commit

Permalink
Introduce additionalButtonRenderers prop for Form component (#36)
Browse files Browse the repository at this point in the history
* Introduce `additionalButtonRenderers` prop for Form component
  • Loading branch information
bedakb committed Sep 23, 2019
1 parent 75aac29 commit b411667
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion src/form/form.tsx
Expand Up @@ -77,6 +77,13 @@ interface ValidationOptions {

type ViolationMessageResolver = (key: string, context: object | null) => string;

interface FormButtonProps {
key: number;
isSubmitting: boolean;
isDirty: boolean;
isValid: boolean;
}

interface Props<MODEL> {
model: MODEL;
onCancel?: () => void;
Expand All @@ -88,6 +95,7 @@ interface Props<MODEL> {
validationSchema?: any;
validationOptions?: ValidationOptions;
resolveViolationMessage?: ViolationMessageResolver;
additionalButtonRenderers?: Array<(buttonProps: FormButtonProps) => React.ReactNode>;
}

interface State<MODEL> {
Expand Down Expand Up @@ -143,6 +151,16 @@ class Form<MODEL extends object> extends React.Component<Props<MODEL>, State<MOD
<div className="col-xs-12">
{this.props.onCancel && this.getCancelButton()}

{this.props.additionalButtonRenderers &&
this.props.additionalButtonRenderers.map((buttonRenderer, index) =>
buttonRenderer({
key: index,
isSubmitting: this.state.isSubmitting,
isDirty: this.state.isDirty,
isValid: this.state.isValid,
})
)}

<Button
id="submit"
text={this.props.submitButtonText}
Expand Down Expand Up @@ -466,4 +484,4 @@ class Form<MODEL extends object> extends React.Component<Props<MODEL>, State<MOD
}
}

export { Form, SectionType, FieldType, FieldContext, ViolationMessageResolver };
export { Form, SectionType, FieldType, FieldContext, ViolationMessageResolver, FormButtonProps };
2 changes: 1 addition & 1 deletion src/form/index.tsx
@@ -1,3 +1,3 @@
export { FieldContext, FieldType, Form, SectionType } from './form';
export { FormButtonProps, FieldContext, FieldType, Form, SectionType } from './form';
export { FormField } from './form-field';
export { Editor, Field } from './types';

0 comments on commit b411667

Please sign in to comment.