carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 2.08 kB
JavaScript
import{jsxs as e,jsx as r}from"react/jsx-runtime";import{useState as t,useContext as n,useEffect as o}from"react";import i from"../../__internal__/utils/helpers/tags/tags.js";import{FieldsetStyle as l,StyledLegend as s}from"./fieldset.style.js";import c from"../carbon-provider/__internal__/new-validation.context.js";import"../../style/utils/filter-styled-system-padding-props.js";import a from"../../style/utils/filter-styled-system-margin-props.js";function p(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}const u=u=>{var{children:f,legend:y,required:b}=u,d=function(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(u,["children","legend","required"]);const[O,m]=t(null),j=a(d),{validationRedesignOptIn:g}=n(c);return o((()=>{O&&b&&Array.from(O.querySelectorAll("input")||[]).forEach((e=>{e.setAttribute("required","")}))}),[O,b]),e(l,(v=function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),n.forEach((function(r){p(e,r,t[r])}))}return e}({ref:m,newValidation:g},d,j,i("fieldset",d)),w=null!=(w={children:[y&&r(s,{"data-element":"legend",isRequired:b,children:y}),f]})?w:{},Object.getOwnPropertyDescriptors?Object.defineProperties(v,Object.getOwnPropertyDescriptors(w)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(w)).forEach((function(e){Object.defineProperty(v,e,Object.getOwnPropertyDescriptor(w,e))})),v));var v,w};u.displayName="Fieldset";export{u as Fieldset,u as default};