carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 3.03 kB
JavaScript
import{jsxs as t,jsx as e,Fragment as r}from"react/jsx-runtime";import{useRef as o,useContext as n}from"react";import i from"../../__internal__/utils/helpers/tags/tags.js";import l from"./__internal__/form-summary.component.js";import{StyledForm as a,StyledFormContent as c,StyledFormFooter as f,StyledLeftButtons as u,StyledRightButtons as s}from"./form.style.js";import{formSpacing as m}from"./form.config.js";import d from"../../__internal__/modal/modal.context.js";function b(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable})))),o.forEach((function(e){b(t,e,r[e])}))}return t}function g(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 y=b=>{var{children:y,saveButton:h,leftSideButtons:O,rightSideButtons:j,errorCount:S,warningCount:P,onSubmit:w,buttonAlignment:k="right",footerChildren:_,stickyFooter:v,stickyFooterVariant:F="light",fieldSpacing:B=3,noValidate:C=!0,height:x,fullWidthButtons:V=!1,footerPadding:A={}}=b,I=function(t,e){if(null==t)return{};var r,o,n=function(t,e){if(null==t)return{};var r,o,n={},i=Object.keys(t);for(o=0;o<i.length;o++)r=i[o],e.indexOf(r)>=0||(n[r]=t[r]);return n}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}(b,["children","saveButton","leftSideButtons","rightSideButtons","errorCount","warningCount","onSubmit","buttonAlignment","footerChildren","stickyFooter","stickyFooterVariant","fieldSpacing","noValidate","height","fullWidthButtons","footerPadding"]);const D=o(null),W=o(null),{isInModal:E}=n(d),M=!!(_||h||O||j||S||P);return t(a,g(p({ref:D,className:v?"sticky":"",stickyFooter:v,onSubmit:w,"data-component":"form",noValidate:C,height:x,isInModal:E},I,i("form",I)),{children:[e(c,{"data-element":"form-content","data-role":"form-content",stickyFooter:v,tabIndex:-1,isInModal:E,fieldSpacing:m[B],children:y}),M&&e(f,g(p(g(p({"data-element":"form-footer","data-role":"form-footer",ref:W,hasFooterChildren:!!_,stickyFooter:v},v&&{stickyFooterVariant:F}),{buttonAlignment:k,fullWidthButtons:V}),A),{children:_||t(r,{children:[O&&e(u,{"data-role":"form-left-buttons",buttonAlignment:k,children:O}),e(l,{fullWidth:V,errorCount:S,warningCount:P,children:h}),j&&e(s,{"data-role":"form-right-buttons",buttonAlignment:k,children:j})]})}))]}))};y.displayName="Form";export{y as Form,y as default};