{"version":3,"file":"Text.mjs","sources":["../../../src/components/Text/Text.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type {\n  ReactNode,\n  ForwardedRef,\n  ForwardRefExoticComponent,\n  RefAttributes,\n} from 'react';\nimport React, { forwardRef } from 'react';\n\nimport type { AnyPreset, Preset } from '../../util/variant-types';\n\nimport styles from './Text.module.css';\n\nexport type TextProps = {\n  /**\n   * Controls which component to use when rendering copy: e.g., `p` or `span`.\n   *\n   * **Default is `\"p\"`**.\n   */\n  as?: 'p' | 'span' | 'div';\n  children: ReactNode;\n  className?: string;\n  tabIndex?: number;\n  /**\n   * Prop to set the desired typography value used in design. Acceptable values\n   * match those used across the design system.\n   */\n  preset?: Preset;\n} & React.HTMLAttributes<HTMLElement>; // TODO-AH: add in each possible element and spread in <Markdown>\n\n/**\n * `TextProps`, widened to also accept the presets a component reserves for its own use.\n */\nexport type InternalTextProps = Omit<TextProps, 'preset'> & {\n  preset?: AnyPreset;\n};\n\n/**\n * ## Usage\n *\n * `Text` is strictly used to style non-heading tags used in a page. Typography presets cover body\n * copy, labels, captions, overlines, code, and other treatments.\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Paragraph | The default. `as=\"p\"` for a standalone block of copy. | Body text, descriptions, help text. |\n * | Span | `as=\"span\"` for text that sits inline within a larger block. | A label beside an icon, inline emphasis. |\n * | Div | `as=\"div\"` when the text needs to wrap other block content. | Text composed alongside nested layout. |\n *\n * Set the treatment with `preset`, which defaults to `body-md`. The preset scale is shared across\n * the design system, so heading-level values appear in it too. Reach for `Heading` when you need\n * heading semantics; `Text` only renders `p`, `span`, and `div`.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Use `Text` for all typographical treatments, and specify a block (`<div>` / `<p>`) tag, or `<span>` as desired.\n *\n * ### Don'ts\n *\n * * Never use TailwindCSS or other styles on raw HTML tags to style/format typography.\n * * Don't use a heading preset on `Text` to imitate a heading. It changes the look without adding the semantics, so the document outline stays wrong. Use `Heading` instead.\n *\n * ## Presets\n *\n * `preset` only takes the reusable presets. A handful of presets belong to one component\n * (`tag`, `appHeader-label`, and friends) and are not available here, since they carry\n * that component's own treatment and can change with it.\n */\nexport const Text = forwardRef(\n  (\n    {\n      as: TagName = 'p',\n      children,\n      className,\n      preset = 'body-md',\n      ...other\n    }: TextProps,\n    ref: ForwardedRef<HTMLParagraphElement>,\n    // Setting as HTMLParagraphElement to satisfy TS, but unit test covers both span and p cases for sanity\n  ) => {\n    const componentClassName = clsx(\n      styles['text'],\n      preset && styles[`text--${preset}`],\n      className,\n    );\n    return (\n      <TagName className={componentClassName} ref={ref} {...other}>\n        {children}\n      </TagName>\n    );\n  },\n);\n\nText.displayName = 'Text';\n\n/**\n * `Text`, typed to also accept the presets components reserve for their own use.\n *\n * For use inside EDS components only. This is deliberately absent from the package\n * exports, so consumers get `Text` and its reusable presets instead.\n *\n * The cast widens the `preset` type; nothing changes at runtime, since the component\n * only ever interpolates `preset` into a class name.\n */\nexport const InternalText = Text as ForwardRefExoticComponent<\n  InternalTextProps & RefAttributes<HTMLParagraphElement>\n>;\n"],"names":["styles","React"],"mappings":";;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACI,MAAM,IAAI,GAAG,UAAU,CAC5B,CACE,EACE,EAAE,EAAE,OAAO,GAAG,GAAG,EACjB,QAAQ,EACR,SAAS,EACT,MAAM,GAAG,SAAS,EAClB,GAAG,KAAK,EACE,EACZ,GAAuC,KAErC;IACF,MAAM,kBAAkB,GAAG,IAAI,CAC7BA,UAAM,CAAC,MAAM,CAAC,EACd,MAAM,IAAIA,UAAM,CAAC,SAAS,MAAM,CAAA,CAAE,CAAC,EACnC,SAAS,CACV;AACD,IAAA,QACEC,cAAA,CAAA,aAAA,CAAC,OAAO,EAAA,EAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,EAAA,GAAM,KAAK,IACxD,QAAQ,CACD;AAEd,CAAC;AAGH,IAAI,CAAC,WAAW,GAAG,MAAM;AAEzB;;;;;;;;AAQG;AACI,MAAM,YAAY,GAAG;;"}