{"version":3,"file":"FormFieldLabel.mjs","names":[],"sources":["../../../../src/_common/form-control/FormFieldLabel.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 { InformationCircleIconOutline } from '../../icons/generated/heroIcons/InformationCircleIconOutline';\nimport { Tooltip } from '../../tooltip';\nimport { Typography } from '../../typography';\nimport { type TooltipObjectProps } from '../types';\nimport { type FormFieldSize, type FormFieldState } from './form-control-types';\n\ntype FormFieldLabelProps = {\n  field: FormFieldState;\n  size: FormFieldSize;\n  /**\n   * How the label is associated with its control. `explicit` renders a\n   * `<label>` pointing at the control through `htmlFor`, carrying `labelId`\n   * for `aria-labelledby`. `implicit` renders plain text, for components\n   * whose control is wrapped by an enclosing `<label>`, where a nested label\n   * element would be invalid.\n   */\n  association?: 'explicit' | 'implicit';\n  /**\n   * Click handler for an explicit label, for controls that need more than\n   * the default `htmlFor` focus forwarding (the Combobox label must move\n   * focus without toggling the panel).\n   */\n  onLabelClick?: React.MouseEventHandler<HTMLLabelElement>;\n  /** Text displayed in an information tooltip next to the label */\n  moreInformationText?: React.ReactNode;\n  /** Props for the Tooltip component used by the information icon */\n  tooltipProps?: TooltipObjectProps;\n  /** Extra class names for the label row */\n  className?: string;\n  /** Wraps the rendered row, so a component can put it inside a Skeleton. */\n  wrap?: (row: React.ReactNode) => React.ReactNode;\n};\n\n/**\n * The label row of a form field: the label itself, an optional information\n * tooltip, and the Required/Optional indicator. The indicator and the tooltip\n * are separate elements rather than label content, keeping them out of the\n * control's accessible name.\n */\nexport const FormFieldLabel = ({\n  field,\n  size,\n  association = 'explicit',\n  onLabelClick,\n  moreInformationText,\n  tooltipProps,\n  className,\n  wrap,\n}: FormFieldLabelProps) => {\n  const {\n    label,\n    labelId,\n    controlId,\n    hasVisuallyHiddenLabel,\n    hasRequiredIndicator,\n    isRequired,\n  } = field;\n  const variant = size === 'large' ? 'body-large' : 'body-medium';\n  const isExplicit = association === 'explicit';\n  const informationIconClasses = classNames({\n    'ndl-information-icon-large': size === 'large',\n    'ndl-information-icon-small': size === 'small' || size === 'medium',\n  });\n\n  const row = (\n    <div\n      className={classNames(\n        'ndl-form-label-row',\n        { 'ndl-visually-hidden': hasVisuallyHiddenLabel },\n        className,\n      )}\n    >\n      <Typography\n        as={isExplicit ? 'label' : 'span'}\n        variant={variant}\n        className=\"ndl-form-label\"\n        htmlAttributes={\n          isExplicit\n            ? { htmlFor: controlId, id: labelId, onClick: onLabelClick }\n            : undefined\n        }\n      >\n        {label}\n      </Typography>\n      {Boolean(moreInformationText) && (\n        <Tooltip type=\"simple\" {...tooltipProps?.root}>\n          <Tooltip.Trigger\n            {...tooltipProps?.trigger}\n            className={informationIconClasses}\n            hasButtonWrapper\n          >\n            <div\n              tabIndex={0}\n              role=\"button\"\n              aria-label=\"Information icon\"\n              data-testid=\"ndl-information-icon\"\n            >\n              <InformationCircleIconOutline />\n            </div>\n          </Tooltip.Trigger>\n          <Tooltip.Content {...tooltipProps?.content}>\n            {moreInformationText}\n          </Tooltip.Content>\n        </Tooltip>\n      )}\n      {hasRequiredIndicator && (\n        <Typography variant={variant} className=\"ndl-form-label-indicator\">\n          {isRequired ? 'Required' : 'Optional'}\n        </Typography>\n      )}\n    </div>\n  );\n\n  return wrap === undefined ? row : <>{wrap(row)}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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