{"version":3,"file":"Code.mjs","names":[],"sources":["../../../src/code/Code.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';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { Tooltip } from '../tooltip';\n\ntype CodeProps = {\n  /** The content of the code */\n  children?: React.ReactNode;\n  /** Whether the code is disabled */\n  isDisabled?: boolean;\n  /** Whether the code is runnable */\n  isRunnable?: boolean;\n  /** The description of the code, will be displayed in a tooltip */\n  description?: string;\n  /** The callback function triggered when the inline code is clicked */\n  onClick?: (\n    event:\n      | React.MouseEvent<HTMLElement, MouseEvent>\n      | React.KeyboardEvent<HTMLElement>,\n  ) => void;\n};\n\nexport const Code = <T extends React.ElementType = 'button'>({\n  children,\n  className,\n  isDisabled = false,\n  style,\n  isRunnable = false,\n  description,\n  onClick,\n  as,\n  ref,\n  htmlAttributes,\n  ...restProps\n}: PolymorphicCommonProps<T, CodeProps>) => {\n  const Component: React.ElementType = as ?? (onClick ? 'button' : 'span');\n\n  const isButton = Component === 'button';\n\n  const classes = classNames(\n    'ndl-code',\n    {\n      'ndl-disabled': isDisabled,\n      'ndl-runnable': isRunnable,\n    },\n    className,\n  );\n\n  const handleClick = (event: React.MouseEvent<HTMLElement, MouseEvent>) => {\n    if (isDisabled) {\n      event.preventDefault();\n      return;\n    }\n\n    onClick?.(event);\n  };\n\n  return (\n    <ConditionalWrap\n      shouldWrap={Boolean(description) === true}\n      wrap={(children) => (\n        <Tooltip type=\"simple\">\n          <Tooltip.Trigger hasButtonWrapper={Component === 'button'}>\n            {children}\n          </Tooltip.Trigger>\n          <Tooltip.Content>{description}</Tooltip.Content>\n        </Tooltip>\n      )}\n    >\n      <Component\n        className={classes}\n        style={style}\n        onClick={handleClick}\n        disabled={isButton ? isDisabled : undefined}\n        aria-disabled={!isButton && isDisabled ? true : undefined}\n        ref={ref}\n        {...restProps}\n        {...htmlAttributes}\n      >\n        <code>{children}</code>\n      </Component>\n    </ConditionalWrap>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAVF,MAAa,QAAgD,SAYjB;CAZiB,IAAA,EAC3D,UACA,WACA,aAAa,OACb,OACA,aAAa,OACb,aACA,SACA,IACA,KACA,mBAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,YAA+B,OAAA,QAAA,OAAA,KAAA,IAAA,KAAO,UAAU,WAAW;CAEjE,MAAM,WAAW,cAAc;CAE/B,MAAM,UAAU,WACd,YACA;EACE,gBAAgB;EAChB,gBAAgB;CAClB,GACA,SACF;CAEA,MAAM,eAAe,UAAqD;EACxE,IAAI,YAAY;GACd,MAAM,eAAe;GACrB;EACF;EAEA,YAAA,QAAA,YAAA,KAAA,KAAA,QAAU,KAAK;CACjB;CAEA,OACE,oBAAC,iBAAD;EACE,YAAY,QAAQ,WAAW,MAAM;EACrC,OAAO,aACL,qBAAC,SAAD;GAAS,MAAK;GAAd,UAAA,CACE,oBAAC,QAAQ,SAAT;IAAiB,kBAAkB,cAAc;IAC9C;GACc,CAAA,GACjB,oBAAC,QAAQ,SAAT,EAAA,UAAkB,YAA6B,CAAA,CACxC;;EAGX,UAAA,oBAAC,WAAA,eAAA,eAAA,eAAA;GACC,WAAW;GACJ;GACP,SAAS;GACT,UAAU,WAAW,aAAa,KAAA;GAClC,iBAAe,CAAC,YAAY,aAAa,OAAO,KAAA;GAC3C;EACD,GAAA,SAAA,GACA,cAAA,GAAA,CAAA,GAAA,EAAA,UAEJ,oBAAC,QAAD,EAAO,SAAe,CAAA,EAAA,CACb,CAAA;CACI,CAAA;AAErB"}