{"version":3,"file":"listItem.mjs","names":[],"sources":["../../../../package/common/listItem/listItem.tsx"],"sourcesContent":["import { useId, type ReactElement, type ReactNode } from 'react';\nimport cx from 'classnames';\nimport { faChevronRight } from '@fortawesome/free-solid-svg-icons';\n\nimport type { ListItemProps } from './listItem.types';\nimport styles from './listItem.module.pcss';\nimport { renderIcon } from '../utils/renderIcon';\nimport { useLinkClick } from '../utils/navigation';\n\n// `subtitle={isOverdue && 'Overdue'}` passes false, which renders nothing and needs no box.\nconst isShown = (node: ReactNode) => node != null && typeof node !== 'boolean' && node !== '';\n\nfunction ListItem({\n  icon,\n  title,\n  subtitle,\n  endContent,\n  href,\n  target,\n  rel,\n  download,\n  onClick,\n  selected = false,\n  chevron = href !== undefined,\n  className,\n  style,\n  classNames,\n  styles: slotStyles,\n  ...rest\n}: ListItemProps): ReactElement {\n  const followLink = useLinkClick();\n  const id = useId();\n  const hasSubtitle = isShown(subtitle);\n  const hasEndContent = isShown(endContent);\n  const isInteractive = href !== undefined || onClick !== undefined;\n  // A status in endContent (\"Open\") is part of what the row says, so the link is described by it\n  // too, where it is text: a control there would only read its own name a second time.\n  const describedBy = [hasSubtitle && `${id}-subtitle`, typeof endContent === 'string' && `${id}-end`]\n    .filter(Boolean)\n    .join(' ');\n\n  const titleElement = (\n    <span className={cx(styles.listItemTitle, classNames?.title)} style={slotStyles?.title}>\n      {title}\n    </span>\n  );\n  // Only the title is the link or button: the rest of the row can then hold controls of its own,\n  // which an <a> or <button> may not contain. Its ::after stretches over the whole row instead.\n  const triggerProps = {\n    className: cx(styles.listItemTrigger, classNames?.trigger),\n    style: slotStyles?.trigger,\n    'aria-describedby': describedBy || undefined,\n  };\n  const trigger =\n    href !== undefined ? (\n      <a\n        {...triggerProps}\n        href={href}\n        target={target}\n        rel={rel}\n        download={download}\n        aria-current={selected ? 'page' : undefined}\n        onClick={(event) => {\n          onClick?.(event);\n          followLink(event);\n        }}\n      >\n        {titleElement}\n      </a>\n    ) : onClick ? (\n      <button {...triggerProps} type='button' aria-pressed={selected || undefined} onClick={onClick}>\n        {titleElement}\n      </button>\n    ) : (\n      titleElement\n    );\n\n  return (\n    <div\n      {...rest}\n      className={cx(\n        styles.listItem,\n        { [styles.listItemInteractive]: isInteractive, [styles.listItemSelected]: selected },\n        className,\n        classNames?.root,\n      )}\n      style={{ ...style, ...slotStyles?.root }}\n    >\n      {icon != null &&\n        renderIcon(icon, { className: cx(styles.listItemIcon, classNames?.icon), style: slotStyles?.icon })}\n      <div className={cx(styles.listItemLabels, classNames?.labels)} style={slotStyles?.labels}>\n        {trigger}\n        {hasSubtitle && (\n          <div\n            id={`${id}-subtitle`}\n            className={cx(styles.listItemSubtitle, classNames?.subtitle)}\n            style={slotStyles?.subtitle}\n          >\n            {subtitle}\n          </div>\n        )}\n      </div>\n      {hasEndContent && (\n        <div\n          id={`${id}-end`}\n          className={cx(styles.listItemEndContent, classNames?.endContent)}\n          style={slotStyles?.endContent}\n        >\n          {endContent}\n        </div>\n      )}\n      {chevron &&\n        renderIcon(faChevronRight, {\n          className: cx(styles.listItemChevron, classNames?.chevron),\n          style: slotStyles?.chevron,\n        })}\n    </div>\n  );\n}\n\nexport default ListItem;\n"],"mappings":"2UAUA,IAAM,EAAW,GAAoB,GAAQ,MAAQ,OAAO,GAAS,WAAa,IAAS,GAE3F,SAAS,EAAS,CAChB,OACA,QACA,WACA,aACA,OACA,SACA,MACA,WACA,UACA,WAAW,GACX,UAAU,IAAS,IAAA,GACnB,YACA,QACA,aACA,OAAQ,EACR,GAAG,GAC2B,CAC9B,IAAM,EAAa,EAAa,EAC1B,EAAK,EAAM,EACX,EAAc,EAAQ,CAAQ,EAC9B,EAAgB,EAAQ,CAAU,EAClC,EAAgB,IAAS,IAAA,IAAa,IAAY,IAAA,GAGlD,EAAc,CAAC,GAAe,GAAG,EAAG,WAAY,OAAO,GAAe,UAAY,GAAG,EAAG,KAAK,CAAC,CACjG,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,EAEL,EACJ,EA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