{"version":3,"file":"Card.mjs","sources":["../../../src/components/Card/Card.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { HTMLAttributes, ReactNode } from 'react';\nimport React from 'react';\n\nimport { assertEdsUsage } from '../../util/logging';\nimport type { IconOrContent } from '../../util/utility-types';\nimport type { Size } from '../../util/variant-types';\n\nimport Heading, { type HeadingElement } from '../Heading';\nimport { hasSlotContent, IconSlot } from '../Icon';\nimport Text from '../Text';\n\nimport styles from './Card.module.css';\n\nexport type CardProps = HTMLAttributes<HTMLElement> & {\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   * CSS properties defined for the HTML element. Includes the component's CSS Custom Properties:\n   *\n   * - `--card__top-stripe-bg`\n   */\n  style?: CardCSSProperties;\n  /**\n   * When `isInteractive` and has a behavior set, name is used as the name of the hidden form field.\n   */\n  name?: string;\n  // Design API\n  /**\n   * When `isInteractive`, describes the behavior of the card when selected. Single (radio) or multiple (checkbox) selection.\n   */\n  behavior?: 'checkbox' | 'radio';\n  /**\n   * Treatment for the card's container element. When using `\"custom-brand\"`, set the\n   * container background and border color using the brand border/bg utility classes.\n   *\n   * **Default is `\"default\"`**.\n   */\n  containerColor?: 'default' | 'call-out' | 'custom-brand';\n  /**\n   * The bounding box and other container emphasis details\n   *\n   * **Default is `\"low\"`**.\n   */\n  containerStyle?: 'none' | 'low' | 'high';\n  /**\n   * State to trigger when the card is being dragged. Can be combined with the HTML `draggable` property,\n   * or used programmatically with drag and drop libraries\n   */\n  isDragging?: boolean;\n  /**\n   * Whether `Card` itself is directly interactive (code wrapping component so that clicking will perform some navigation or action)\n   *\n   * **Default is `false`**.\n   */\n  isInteractive?: boolean;\n  /**\n   * Decorative top bar used to cause a highlight on a given card. When present, this\n   * corresponds to a specified emphasis level.\n   *\n   * **Default is `\"none\"`**.\n   *\n   * @deprecated\n   */\n  topStripe?: 'none' | 'medium' | 'high';\n};\nexport type CardSubComponentProps = {\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\n/**\n * Heading levels `Card.Header` takes for its title.\n *\n * A card always sits inside a section the page has already given a heading, so its title\n * goes below that heading rather than competing with it. `h2` and `h3` cover where a card\n * actually lands in an outline: `h1` would claim the page, and `h4` and down are deeper\n * than a card nests.\n *\n * Kept as a value as well as a type so the component can check a level that reached it\n * from untyped code, where the type alone stops nothing.\n */\nconst titleElements = ['h2', 'h3'] as const;\n\nexport type CardHeaderTitleElement = Extract<\n  HeadingElement,\n  (typeof titleElements)[number]\n>;\n\nexport type CardHeaderProps = {\n  // Component API\n  /**\n   * Child node(s) that can be nested inside component. Used in place of any of the above named slots.\n   */\n  children?: ReactNode;\n  /**\n   * CSS class names that can be appended to the component.\n   */\n  className?: string;\n  // Design API\n  /**\n   * Component slot to add in an action-focused area to a card. Typically a button with hidden options.\n   */\n  action?: ReactNode;\n  /**\n   * Text above the main title of the card, to add category text/information.\n   */\n  eyebrow?: string;\n  /**\n   * Card slot sitting in front of the card header text. Takes an EDS icon name, or any\n   * content to render in its place, sized to match `size`.\n   */\n  icon?: IconOrContent;\n  /**\n   * Overall size treatment of the Card header\n   */\n  size?: Extract<Size, 'sm' | 'md'>;\n  /**\n   * Secondary text used to describe the content in more detail\n   */\n  subTitle?: ReactNode;\n  /**\n   * The title/heading of the component\n   */\n  title?: string;\n  /**\n   * Which heading level `title` renders at. Take it from the page outline: the level below\n   * whatever heading introduces the section the card sits in, not the size you want the\n   * title to read at.\n   *\n   * Only `h2` and `h3` are available, since a card's title sits under a heading the page\n   * has already set. The level never changes the title's treatment, which follows `size`,\n   * so a card can sit at the right level in the outline and still look the same.\n   *\n   * **Default is `\"h3\"`**.\n   */\n  titleAs?: CardHeaderTitleElement;\n};\n\nexport interface CardCSSProperties extends React.CSSProperties {\n  '--card__top-stripe-bg'?: string;\n}\n\n// TODO: needs useRef for input field (allow react to control things)?\n/**\n * ## Usage\n *\n * * **Static card**: Group related elements, including some combination of images, text, buttons, input fields, etc.\n * * **Interactive card**: A selectable or actionable card.\n *\n * ### Best Practices\n *\n * * Display information so that what the user needs to know first is prioritized.\n * * Limit call-to-action buttons and/or links, using only one primary call-to-action per card.\n * * Do not use a card as an action.\n *\n * ## Header titles\n *\n * `Card.Header` renders its `title` as a heading, at the level `titleAs` sets. Take that\n * level from the page outline, the one below whatever heading introduces the section the\n * card sits in. Only `h2` and `h3` are available, because a card's title always sits under\n * a heading the page has already set.\n *\n * | Prop | What it sets | Where the value comes from |\n * |------|--------------|----------------------------|\n * | `titleAs` | Which heading tag the title renders as, `h2` or `h3`. | The document structure: the level below the heading of the section holding the card. |\n * | `size` | The treatment of the title, and the rest of the header with it. | The design. |\n *\n * The two stay independent, so moving a card to a different level of the outline never\n * changes how its title looks.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Group related information within separate cards.\n * * Use subheadings, paragraphs, and bullet lists to break up larger amounts of content.\n * * Use headings that make the card's purpose clear.\n * * Include essential, summarized information.\n * * Set `titleAs` to the level the page outline calls for, so a card's title doesn't skip a heading level.\n *\n * ### Don'ts\n *\n * * Don't overwhelm the card with too much content; keep it scannable.\n * * Avoid too many call-to-action buttons or links within the same card.\n * * Don't pick `titleAs` for the size it renders at. The title's treatment comes from `size`.\n */\nexport const Card = ({\n  containerColor = 'default',\n  behavior,\n  className,\n  children,\n  containerStyle = 'low',\n  isDragging,\n  isInteractive = false,\n  name,\n  topStripe = 'none',\n  ...other\n}: CardProps) => {\n  const componentClassName = clsx(\n    styles['card'],\n    styles[`card--container-style-${containerStyle}`],\n    styles[`card--container-color-${containerColor}`],\n    typeof isDragging !== 'undefined' &&\n      styles[`card--is-dragging-${isDragging}`],\n    isInteractive && styles['card--is-interactive'],\n    className,\n  );\n\n  const behaviorId = React.useId();\n  const cardComponent = (\n    <div className={componentClassName} {...other}>\n      {children}\n      {(topStripe || behavior) && (\n        <div\n          className={clsx(\n            styles['card__top-stripe'],\n            styles[`top-stripe--${behavior ? 'medium' : topStripe}`],\n          )}\n        />\n      )}\n      {behavior && isInteractive && (\n        <input\n          className={styles['card__behavior-input']}\n          id={behaviorId}\n          name={name}\n          type={behavior}\n        />\n      )}\n    </div>\n  );\n\n  return (\n    <>\n      {behavior && isInteractive ? (\n        <label className={styles['card__behavior-label']} htmlFor={behaviorId}>\n          {cardComponent}\n        </label>\n      ) : (\n        cardComponent\n      )}\n    </>\n  );\n};\n\n/**\n * Body of the Card component.\n */\nconst CardBody = ({ children, className, ...other }: CardSubComponentProps) => {\n  const componentClassName = clsx(styles['card__body'], className);\n  return (\n    <div className={componentClassName} {...other}>\n      {children}\n    </div>\n  );\n};\n\n/**\n * Footer of the Card component.\n */\nconst CardFooter = ({\n  children,\n  className,\n  ...other\n}: CardSubComponentProps) => {\n  return (\n    <div className={className} {...other}>\n      {children}\n    </div>\n  );\n};\n\n/**\n * Header of the Card component.\n */\nconst CardHeader = ({\n  action,\n  children,\n  className,\n  eyebrow,\n  icon,\n  size = 'md',\n  subTitle,\n  title,\n  titleAs = 'h3',\n  ...other\n}: CardHeaderProps) => {\n  const componentClassName = clsx(\n    styles['card__header'],\n    size && styles[`header--size-${size}`],\n    className,\n  );\n  const headerEyebrowClassName = clsx(\n    styles['header__eyebrow'],\n    size && styles[`header--size-${size}`],\n  );\n  const headerTitleClassName = clsx(\n    styles['header__title'],\n    size && styles[`header--size-${size}`],\n  );\n  const headerSubTitleClassName = clsx(\n    styles['header__sub-title'],\n    size && styles[`header--size-${size}`],\n  );\n\n  const isSupportedTitleElement = titleElements.includes(titleAs);\n\n  assertEdsUsage(\n    [!isSupportedTitleElement],\n    `Card.Header takes only \\`h2\\` or \\`h3\\` for \\`titleAs\\`, and \\`${titleAs}\\` is ignored in favor of \\`h3\\`. A card's title sits under a heading the page has already set, so pick the level just below that one.`,\n  );\n\n  return children ? (\n    <div className={componentClassName} {...other}>\n      <div className={styles['header__custom']}>{children}</div>\n    </div>\n  ) : (\n    <div className={componentClassName} {...other}>\n      {hasSlotContent(icon) && (\n        <div className={styles['header__icon']}>\n          <IconSlot\n            content={icon}\n            purpose=\"decorative\"\n            size={size === 'sm' ? '16px' : '24px'}\n          />\n        </div>\n      )}\n      <div className={styles['header__text']}>\n        {eyebrow && (\n          <Text\n            as=\"div\"\n            className={headerEyebrowClassName}\n            preset={size === 'sm' ? 'overline-sm' : 'overline-md'}\n          >\n            {eyebrow}\n          </Text>\n        )}\n        {title && (\n          <Heading\n            as={isSupportedTitleElement ? titleAs : 'h3'}\n            className={headerTitleClassName}\n            preset={size === 'sm' ? 'title-sm' : 'title-lg'}\n          >\n            {title}\n          </Heading>\n        )}\n        {subTitle && (\n          <Text\n            as=\"div\"\n            className={headerSubTitleClassName}\n            preset={size === 'sm' ? 'body-xs' : 'body-md'}\n          >\n            {subTitle}\n          </Text>\n        )}\n      </div>\n      {action && <div className={styles['header__action']}>{action}</div>}\n    </div>\n  );\n};\n\nCard.displayName = 'Card';\nCardBody.displayName = 'Card.Body';\nCardFooter.displayName = 'Card.Footer';\nCardHeader.displayName = 'Card.Header';\n\nCard.Body = CardBody;\nCard.Footer = CardFooter;\nCard.Header = CardHeader;\n"],"names":["React"],"mappings":";;;;;;;;;;AAqFA;;;;;;;;;;AAUG;AACH,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,CAAU;AA6D3C;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CG;AACI,MAAM,IAAI,GAAG,CAAC,EACnB,cAAc,GAAG,SAAS,EAC1B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,GAAG,KAAK,EACtB,UAAU,EACV,aAAa,GAAG,KAAK,EACrB,IAAI,EACJ,SAAS,GAAG,MAAM,EAClB,GAAG,KAAK,EACE,KAAI;IACd,MAAM,kBAAkB,GAAG,IAAI,CAC7B,MAAM,CAAC,MAAM,CAAC,EACd,MAAM,CA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