{"version":3,"file":"Fieldset.mjs","names":[],"sources":["../../../src/fieldset/Fieldset.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport type React from 'react';\n\nimport {\n  FormFieldGroupContext,\n  type FormFieldGroupContextValue,\n  FormFieldMessage,\n  useFormField,\n} from '../_common/form-control';\nimport { type CommonProps } from '../_common/types';\nimport { Typography } from '../typography';\n\ntype FieldsetProps = {\n  /** The accessible label displayed in the fieldset legend */\n  label: React.ReactNode;\n  /** The controls grouped by the fieldset */\n  children: React.ReactNode;\n  /** Assistive text displayed below the grouped controls */\n  helpText?: React.ReactNode;\n  /** Error message displayed below the grouped controls. When provided, it replaces `helpText` */\n  errorText?: React.ReactNode;\n  /** Whether the grouped field is required */\n  isRequired?: boolean;\n  /** Whether Required or Optional is shown at the end of the legend row */\n  hasRequiredIndicator?: boolean;\n  /** Whether the legend is clipped out of the layout, leaving it to screen readers only */\n  hasVisuallyHiddenLabel?: boolean;\n  /** Whether all native form controls in the fieldset are disabled */\n  isDisabled?: boolean;\n};\n\ntype FieldsetBaseProps = FieldsetProps & {\n  fieldGroup?: Pick<\n    FormFieldGroupContextValue,\n    'name' | 'controlType' | 'value' | 'onChange'\n  >;\n  orientation?: 'horizontal' | 'vertical';\n};\n\nconst FieldsetBase = ({\n  label,\n  children,\n  helpText,\n  errorText,\n  isRequired = false,\n  hasRequiredIndicator = false,\n  hasVisuallyHiddenLabel = false,\n  isDisabled = false,\n  fieldGroup,\n  orientation = 'vertical',\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'fieldset', FieldsetBaseProps>) => {\n  const { field, controlProps } = useFormField({\n    errorText,\n    hasRequiredIndicator,\n    hasVisuallyHiddenLabel,\n    helpText,\n    isRequired,\n    label,\n  });\n  const classes = classNames('ndl-fieldset', className, {\n    'ndl-disabled': isDisabled,\n    'ndl-has-error': field.hasError,\n  });\n  const content = (\n    <div\n      className={classNames('ndl-fieldset-content', {\n        'ndl-horizontal': orientation === 'horizontal',\n      })}\n    >\n      {children}\n    </div>\n  );\n  const fieldGroupValue =\n    fieldGroup === undefined\n      ? undefined\n      : {\n          ...fieldGroup,\n          hasError: field.hasError,\n          isDisabled,\n          isRequired,\n        };\n\n  return (\n    <fieldset\n      ref={ref}\n      className={classes}\n      style={style}\n      disabled={isDisabled}\n      aria-describedby={controlProps['aria-describedby']}\n      aria-invalid={controlProps['aria-invalid']}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      <legend\n        className={classNames('ndl-fieldset-legend', {\n          'ndl-visually-hidden': hasVisuallyHiddenLabel,\n        })}\n      >\n        <span className=\"ndl-form-label-row\">\n          <Typography\n            as=\"span\"\n            variant=\"body-medium\"\n            className=\"ndl-form-label\"\n          >\n            {label}\n          </Typography>\n          {hasRequiredIndicator && (\n            <Typography\n              as=\"span\"\n              variant=\"body-medium\"\n              className=\"ndl-form-label-indicator\"\n            >\n              {isRequired ? 'Required' : 'Optional'}\n            </Typography>\n          )}\n        </span>\n      </legend>\n      {fieldGroupValue === undefined ? (\n        content\n      ) : (\n        <FormFieldGroupContext.Provider value={fieldGroupValue}>\n          {content}\n        </FormFieldGroupContext.Provider>\n      )}\n      <FormFieldMessage field={field} size=\"medium\" />\n    </fieldset>\n  );\n};\n\n/**\n * Groups related form controls under a native fieldset and legend.\n *\n * @remarks\n * Use `RadioGroup` or `CheckboxGroup` when the children are exclusively\n * radios or checkboxes and should inherit shared group attributes.\n */\nconst Fieldset = (props: CommonProps<'fieldset', FieldsetProps>) => (\n  <FieldsetBase {...props} />\n);\n\nFieldset.displayName = 'Fieldset';\n\nexport { Fieldset, FieldsetBase, type FieldsetProps };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6DE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAdF,MAAM,gBAAgB,SAgB4B;CAhB5B,IAAA,EACpB,OACA,UACA,UACA,WACA,aAAa,OACb,uBAAuB,OACvB,yBAAyB,OACzB,aAAa,OACb,YACA,cAAc,YACd,WACA,OACA,gBACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,EAAE,OAAO,iBAAiB,aAAa;EAC3C;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,UAAU,WAAW,gBAAgB,WAAW;EACpD,gBAAgB;EAChB,iBAAiB,MAAM;CACzB,CAAC;CACD,MAAM,UACJ,oBAAC,OAAD;EACE,WAAW,WAAW,wBAAwB,EAC5C,kBAAkB,gBAAgB,aACpC,CAAC;EAEA;CACE,CAAA;CAEP,MAAM,kBACJ,eAAe,KAAA,IACX,KAAA,IAAA,eAAA,eAAA,CAAA,GAEK,UAAA,GAAA,CAAA,GAAA;EACH,UAAU,MAAM;EAChB;EACA;CACF,CAAA;CAEN,OACE,qBAAC,YAAA,eAAA,eAAA,eAAA;EACM;EACL,WAAW;EACJ;EACP,UAAU;EACV,oBAAkB,aAAa;EAC/B,gBAAc,aAAa;CACvB,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAAA,UARN;EAUE,oBAAC,UAAD;GACE,WAAW,WAAW,uBAAuB,EAC3C,uBAAuB,uBACzB,CAAC;GAED,UAAA,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CACE,oBAAC,YAAD;KACE,IAAG;KACH,SAAQ;KACR,WAAU;KAET,UAAA;IACS,CAAA,GACX,wBACC,oBAAC,YAAD;KACE,IAAG;KACH,SAAQ;KACR,WAAU;KAET,UAAA,aAAa,aAAa;IACjB,CAAA,CAEV;;EACA,CAAA;EACP,oBAAoB,KAAA,IACnB,UAEA,oBAAC,sBAAsB,UAAvB;GAAgC,OAAO;GACpC,UAAA;EAC6B,CAAA;EAElC,oBAAC,kBAAD;GAAyB;GAAO,MAAK;EAAU,CAAA;CACvC,EAAA,CAAA,CAAA;AAEd;;;;;;;;AASA,MAAM,YAAY,UAChB,oBAAC,cAAA,eAAA,CAAA,GAAiB,KAAQ,CAAA;AAG5B,SAAS,cAAc"}