{"version":3,"file":"FormFieldMessage.mjs","names":[],"sources":["../../../../src/_common/form-control/FormFieldMessage.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 { ExclamationCircleIconSolid } from '../../icons/generated/heroIcons/ExclamationCircleIconSolid';\nimport { Typography } from '../../typography';\nimport {\n  type FormFieldMessageSeverity,\n  type FormFieldSize,\n  type FormFieldState,\n} from './form-control-types';\n\ntype FormFieldMessagePresentation = {\n  /** Icon rendered before the message text. */\n  icon?: React.ComponentType;\n  /** Severity modifier class on the message container. */\n  className?: string;\n};\n\n/**\n * How each severity presents itself. A future severity (`info`, `warning`) or\n * a new way of presenting a message extends this map rather than reshaping\n * the components that render messages.\n */\nconst presentationBySeverity: Record<\n  FormFieldMessageSeverity,\n  FormFieldMessagePresentation\n> = {\n  error: { className: 'ndl-error', icon: ExclamationCircleIconSolid },\n  help: {},\n};\n\ntype FormFieldMessageProps = {\n  field: FormFieldState;\n  size: FormFieldSize;\n  /** Extra class names for the message container */\n  className?: string;\n  /** Wraps the message content, so a component can put it inside a Skeleton. */\n  wrap?: (content: React.ReactNode) => React.ReactNode;\n};\n\n/**\n * The message below a form field: the help text, or the error that replaces\n * it. The container is rendered whether or not there is a message, so the\n * `aria-live` region exists in the document before any text arrives and a\n * validation error is reliably announced. The stylesheet collapses it while\n * it is empty.\n *\n * The region is polite rather than an assertive `role=\"alert\"`, since\n * validation that runs on blur or on change would otherwise interrupt\n * whatever is being read. `aria-atomic` makes the whole message announce as\n * one, matching `role=\"status\"` without presenting plain help text as a\n * status message.\n */\nexport const FormFieldMessage = ({\n  field,\n  size,\n  className,\n  wrap,\n}: FormFieldMessageProps) => {\n  const { message, messageId, messageSeverity } = field;\n  const variant = size === 'large' ? 'body-medium' : 'body-small';\n  const presentation =\n    messageSeverity === undefined\n      ? undefined\n      : presentationBySeverity[messageSeverity];\n  const Icon = presentation?.icon;\n\n  const content =\n    messageSeverity === undefined ? null : (\n      // The icon and the text share a row of their own, so the container stays\n      // a plain block that anything wrapping the content, a Skeleton in\n      // particular, can fill the width of.\n      <div className=\"ndl-form-message-content\">\n        {Icon !== undefined && (\n          <div className=\"ndl-form-message-icon\" aria-hidden=\"true\">\n            <Icon />\n          </div>\n        )}\n        <Typography\n          variant={variant}\n          className=\"ndl-form-message-text\"\n          htmlAttributes={{ id: messageId }}\n        >\n          {message}\n        </Typography>\n      </div>\n    );\n\n  return (\n    <div\n      className={classNames(\n        'ndl-form-message',\n        {\n          'ndl-large': size === 'large',\n          'ndl-medium': size === 'medium',\n          'ndl-small': size === 'small',\n        },\n        presentation?.className,\n        className,\n      )}\n      aria-live=\"polite\"\n      aria-atomic=\"true\"\n    >\n      {content !== null && (wrap === undefined ? content : wrap(content))}\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,yBAGF;CACF,OAAO;EAAE,WAAW;EAAa,MAAM;CAA2B;CAClE,MAAM,CAAC;AACT;;;;;;;;;;;;;;AAwBA,MAAa,oBAAoB,EAC/B,OACA,MACA,WACA,WAC2B;CAC3B,MAAM,EAAE,SAAS,WAAW,oBAAoB;CAChD,MAAM,UAAU,SAAS,UAAU,gBAAgB;CACnD,MAAM,eACJ,oBAAoB,KAAA,IAChB,KAAA,IACA,uBAAuB;CAC7B,MAAM,OAAA,iBAAA,QAAA,iBAAA,KAAA,IAAA,KAAA,IAAO,aAAc;CAE3B,MAAM,UACJ,oBAAoB,KAAA,IAAY,OAI9B,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,SAAS,KAAA,KACR,oBAAC,OAAD;GAAK,WAAU;GAAwB,eAAY;GACjD,UAAA,oBAAC,MAAD,CAAO,CAAA;EACJ,CAAA,GAEP,oBAAC,YAAD;GACW;GACT,WAAU;GACV,gBAAgB,EAAE,IAAI,UAAU;GAE/B,UAAA;EACS,CAAA,CACT;;CAGT,OACE,oBAAC,OAAD;EACE,WAAW,WACT,oBACA;GACE,aAAa,SAAS;GACtB,cAAc,SAAS;GACvB,aAAa,SAAS;EACxB,GAAA,iBAAA,QAAA,iBAAA,KAAA,IAAA,KAAA,IACA,aAAc,WACd,SACF;EACA,aAAU;EACV,eAAY;EAEX,UAAA,YAAY,SAAS,SAAS,KAAA,IAAY,UAAU,KAAK,OAAO;CAC9D,CAAA;AAET"}