UNPKG

@appbuckets/react-ui-forms

Version:

An utilities package to manage and create Form using AppBuckets ReactUI

67 lines (64 loc) 1.93 kB
import { __assign } from '../_virtual/_tslib.js'; import * as React from 'react'; import Button from '@appbuckets/react-ui/Button'; import { useHookedFormContext } from '../context/HookedForm.context.js'; /* -------- * Component Definition * -------- */ var HookedFormActions = function () { /** Get the Wrapper Component */ var _a = useHookedFormContext(), Wrapper = _a.actionsWrapper, cancelButton = _a.cancelButton, formState = _a.formState, handleCancel = _a.handleCancel, submitButton = _a.submitButton; /** No Wrapper, no Party */ if (!Wrapper) { return null; } /** Omit props on React.Fragment, they are not allowed */ var wrapperProps = Wrapper === React.Fragment ? undefined : { className: 'form-actions' }; /** Build elements using Shorthand */ var cancelButtonElement = Button.create(cancelButton, { autoGenerateKey: false, defaultProps: { className: 'cancel', }, overrideProps: function (originalProps) { return { disabled: formState.isSubmitting, onClick: function (event, buttonProps) { /** Use user defined onClick handler if exists */ if (typeof originalProps.onClick === 'function') { originalProps.onClick(event, buttonProps); } /** Call internal Handler */ handleCancel(); }, }; }, }); var submitButtonElement = Button.create(submitButton, { autoGenerateKey: false, defaultProps: { className: 'submit', primary: true, loading: formState.isSubmitting, }, overrideProps: { disabled: formState.isSubmitting, type: 'submit', }, }); /** Return the Component */ return React.createElement( Wrapper, __assign({}, wrapperProps), cancelButtonElement, submitButtonElement ); }; HookedFormActions.displayName = 'HookedFormActions'; export { HookedFormActions as default };