UNPKG

carbon-react

Version:

A library of reusable React components for easily building user interfaces.

2 lines (1 loc) 3.1 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),e=require("react"),r=require("../../__internal__/utils/helpers/tags/tags.js"),n=require("./__internal__/form-summary.component.js"),o=require("./form.style.js"),i=require("./form.config.js"),l=require("../../__internal__/modal/modal.context.js");function u(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable})))),n.forEach((function(e){u(t,e,r[e])}))}return t}function s(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):function(t){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e.push.apply(e,r)}return e}(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))})),t}const c=u=>{var{children:c,saveButton:f,leftSideButtons:d,rightSideButtons:m,errorCount:y,warningCount:b,onSubmit:g,buttonAlignment:p="right",footerChildren:h,stickyFooter:j,stickyFooterVariant:O="light",fieldSpacing:S=3,noValidate:x=!0,height:F,fullWidthButtons:P=!1,footerPadding:w={}}=u,_=function(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}(u,["children","saveButton","leftSideButtons","rightSideButtons","errorCount","warningCount","onSubmit","buttonAlignment","footerChildren","stickyFooter","stickyFooterVariant","fieldSpacing","noValidate","height","fullWidthButtons","footerPadding"]);const v=e.useRef(null),k=e.useRef(null),{isInModal:B}=e.useContext(l.default),C=!!(h||f||d||m||y||b);return t.jsxs(o.StyledForm,s(a({ref:v,className:j?"sticky":"",stickyFooter:j,onSubmit:g,"data-component":"form",noValidate:x,height:F,isInModal:B},_,r.default("form",_)),{children:[t.jsx(o.StyledFormContent,{"data-element":"form-content","data-role":"form-content",stickyFooter:j,tabIndex:-1,isInModal:B,fieldSpacing:i.formSpacing[S],children:c}),C&&t.jsx(o.StyledFormFooter,s(a(s(a({"data-element":"form-footer","data-role":"form-footer",ref:k,hasFooterChildren:!!h,stickyFooter:j},j&&{stickyFooterVariant:O}),{buttonAlignment:p,fullWidthButtons:P}),w),{children:h||t.jsxs(t.Fragment,{children:[d&&t.jsx(o.StyledLeftButtons,{"data-role":"form-left-buttons",buttonAlignment:p,children:d}),t.jsx(n.default,{fullWidth:P,errorCount:y,warningCount:b,children:f}),m&&t.jsx(o.StyledRightButtons,{"data-role":"form-right-buttons",buttonAlignment:p,children:m})]})}))]}))};c.displayName="Form",exports.Form=c,exports.default=c;