{"version":3,"file":"FieldNote.mjs","sources":["../../../src/components/FieldNote/FieldNote.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { ReactNode } from 'react';\nimport React from 'react';\nimport { assertEdsUsage } from '../../util/logging';\nimport type { IconOrContent } from '../../util/utility-types';\nimport type { Status } from '../../util/variant-types';\nimport { hasSlotContent, IconSlot, useSemanticIcon } from '../Icon';\nimport Text from '../Text';\nimport styles from './FieldNote.module.css';\n\nexport type FieldNoteProps = {\n  // Component API\n  /**\n   * Child node(s) that can be nested inside component\n   */\n  children?: ReactNode;\n  /**\n   * CSS class names that can be appended to the component.\n   */\n  className?: string;\n  /**\n   * HTML id for the component\n   */\n  id?: string;\n  // Design API\n  /**\n   * Toggles disabled styling of the field note.\n   */\n  disabled?: boolean;\n  /**\n   * Leading slot for the note. Takes an EDS icon name, or any content to render in its\n   * place at 16px.\n   *\n   * Only set this alongside a `status`. A note with no status has nothing for an icon to\n   * report, and the icon reads as a status the note does not have; EDS warns in that case.\n   *\n   * `status` supplies this slot's default, and the icon it picks comes from\n   * `IconProvider`, so an app changes every status icon in one place. An explicit value\n   * here wins over that default for this one note, and the status treatment (color, and\n   * the announced \"error\"/\"warning\") still applies.\n   *\n   * Custom content is rendered as-is and carries its own accessible treatment, so it does\n   * not receive the status title an icon name would.\n   */\n  icon?: IconOrContent;\n  /**\n   * Status for the field state\n   *\n   * **Default is `\"default\"`**.\n   */\n  status?: 'default' | Extract<Status, 'warning' | 'critical'>;\n};\n\n/**\n * ## Usage\n *\n * `FieldNote` is used to add additional context to the attached input control (e.g., `InputField`,\n * `TextareaField`, `Select`, `Combobox`, etc.). `FieldNote` should not be used in isolation, but\n * can be used when building a custom input control.\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Default | Neutral helper text sitting below the control. | Format hints. Examples of valid input. |\n * | Warning | `status=\"warning\"` adds a warning icon and treatment. | Input that is accepted but likely not what the user meant. |\n * | Critical | `status=\"critical\"` adds an error icon and treatment. | Validation failures that block submission. |\n *\n * When building a custom control, give the note an `id` and add that `id` to the control's\n * `aria-describedby` so the note is announced with the control. The EDS controls that render a\n * `FieldNote` for you already wire this up.\n *\n * For guidance on what to put in a note, see the do's and don'ts on the control itself (for\n * example, `InputField`).\n */\nexport const FieldNote = ({\n  children,\n  className,\n  id,\n  disabled,\n  icon,\n  status,\n  ...other\n}: FieldNoteProps) => {\n  const componentClassName = clsx(\n    styles['field-note'],\n    disabled && styles['field-note--disabled'],\n    status === 'critical' && styles['field-note--error'],\n    status === 'warning' && styles['field-note--warning'],\n    className,\n  );\n\n  const hasStatusIcon = status === 'critical' || status === 'warning';\n\n  assertEdsUsage(\n    [!hasStatusIcon && hasSlotContent(icon)],\n    'FieldNote can only show an icon when `status` is \"warning\" or \"critical\". Otherwise the icon reports a state the note does not have.',\n  );\n\n  // The status icon is semantic, so which glyph a status draws is set app-wide through\n  // `IconProvider`.\n  const statusIcon = useSemanticIcon(hasStatusIcon ? status : undefined);\n\n  // `status` is a default for the slot, not an override of it. An explicitly passed value\n  // losing to an inferred one is the surprising direction, and it would silently drop a\n  // consumer's own content the moment a status was set.\n  const iconToUse = hasSlotContent(icon) ? icon : statusIcon;\n\n  // Describes the status rather than whichever icon renders, so it stays correct when a\n  // consumer swaps the icon out. `IconSlot` applies it to an icon name only.\n  const title =\n    status === 'critical'\n      ? 'error'\n      : status === 'warning'\n        ? 'warning'\n        : 'fieldnote status icon';\n\n  return (\n    <div\n      aria-disabled={disabled ?? undefined}\n      className={componentClassName}\n      id={id}\n      {...other}\n    >\n      {hasSlotContent(iconToUse) && (\n        <IconSlot\n          className={styles['field-note__icon']}\n          content={iconToUse}\n          purpose=\"informative\"\n          size=\"16px\"\n          title={title}\n        />\n      )}\n      <Text as=\"span\" preset=\"body-sm\">\n        {children}\n      </Text>\n    </div>\n  );\n};\n\nFieldNote.displayName = 'FieldNote';\n"],"names":["React"],"mappings":";;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;AAmBG;MACU,SAAS,GAA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