{"version":3,"file":"Banner.mjs","names":[],"sources":["../../../src/banner/Banner.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 */\nimport classNames from 'classnames';\nimport type React from 'react';\n\nimport {\n  type CommonProps,\n  type PolymorphicCommonProps,\n} from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { BoltIconOutline } from '../icons/generated/heroIcons/BoltIconOutline';\nimport { CheckCircleIconSolid } from '../icons/generated/heroIcons/CheckCircleIconSolid';\nimport { ExclamationCircleIconSolid } from '../icons/generated/heroIcons/ExclamationCircleIconSolid';\nimport { ExclamationTriangleIconSolid } from '../icons/generated/heroIcons/ExclamationTriangleIconSolid';\nimport { InformationCircleIconSolid } from '../icons/generated/heroIcons/InformationCircleIconSolid';\nimport { XMarkIconOutline } from '../icons/generated/heroIcons/XMarkIconOutline';\nimport { Typography } from '../typography';\n/**\n *\n *\n * Types\n *\n *\n */\n\ntype BannerCommonProps = {\n  /** Shows a status icon. The icon is based on the value of the `variant` prop */\n  hasIcon?: boolean;\n\n  /** Content to be shown in the banner. */\n  children?: React.ReactNode;\n\n  /** Sets the role to alert */\n  isAlert?: boolean;\n\n  /** How the banner is used. */\n  usage?: 'inline' | 'global';\n\n  /** The variant of the banner */\n  variant?: BannerVariant;\n};\n\ntype CloseableBannerProps = {\n  /** If the banner is closeable. Renders an icon button in the top right corner */\n  isCloseable: true;\n\n  /** Event handler for when the close icon is clicked */\n  onClose: (\n    event?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,\n  ) => void;\n};\n\ntype NonCloseableBannerProps = {\n  isCloseable?: false;\n  onClose?: never;\n};\n\ntype BannerCloseProps = CloseableBannerProps | NonCloseableBannerProps;\n\ntype BannerProps = BannerCommonProps & BannerCloseProps;\ntype BannerVariant = 'info' | 'success' | 'warning' | 'danger' | 'neutral';\n\nconst StatusIcon = ({ variant }: { variant: BannerVariant }) => {\n  const iconComponent = (() => {\n    switch (variant) {\n      case 'success':\n        return <CheckCircleIconSolid />;\n      case 'warning':\n        return <ExclamationTriangleIconSolid />;\n      case 'danger':\n        return <ExclamationCircleIconSolid />;\n      case 'info':\n        return <InformationCircleIconSolid />;\n      case 'neutral':\n        return <BoltIconOutline />;\n      default:\n        return null;\n    }\n  })();\n\n  return <div className=\"ndl-banner-status-icon\">{iconComponent}</div>;\n};\n\nconst BannerHeader = ({\n  children,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'span', { children: React.ReactNode }>) => {\n  const classes = classNames('ndl-banner-header', className);\n  return (\n    <Typography\n      as=\"span\"\n      variant=\"title-4\"\n      className={classes}\n      style={style}\n      ref={ref}\n      htmlAttributes={htmlAttributes}\n      {...restProps}\n    >\n      {children}\n    </Typography>\n  );\n};\n\nconst BannerDescription = ({\n  children,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'div', { children: React.ReactNode }>) => {\n  const classes = classNames('ndl-banner-description', className);\n  return (\n    <Typography\n      as=\"div\"\n      variant=\"body-medium\"\n      className={classes}\n      style={style}\n      ref={ref}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      {children}\n    </Typography>\n  );\n};\n\nconst BannerActions = ({\n  children,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'div', { children: React.ReactNode }>) => {\n  const classes = classNames('ndl-banner-actions', className);\n  return (\n    <div\n      className={classes}\n      style={style}\n      ref={ref}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      {children}\n    </div>\n  );\n};\n\nconst BannerComponent = <T extends React.ElementType = 'section'>({\n  as,\n  variant = 'info',\n  hasIcon = false,\n  onClose,\n  className,\n  children,\n  isCloseable = false,\n  usage = 'inline',\n  htmlAttributes,\n  isAlert = false,\n  ref,\n  ...restProps\n}: PolymorphicCommonProps<T, BannerProps>) => {\n  const Element: React.ElementType = as ?? 'section';\n\n  const classes = classNames('ndl-banner', className, {\n    'ndl-danger': variant === 'danger',\n    'ndl-global': usage === 'global',\n    'ndl-info': variant === 'info',\n    'ndl-inline': usage === 'inline',\n    'ndl-neutral': variant === 'neutral',\n    'ndl-success': variant === 'success',\n    'ndl-warning': variant === 'warning',\n  });\n\n  const handleClose = (\n    event:\n      | React.MouseEvent<HTMLElement, MouseEvent>\n      | React.KeyboardEvent<HTMLElement>,\n  ) => {\n    if (onClose && typeof onClose === 'function') {\n      onClose(event);\n    }\n  };\n\n  return (\n    <Element\n      className={classes}\n      role={isAlert ? 'alert' : undefined}\n      ref={ref}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      <div className=\"ndl-banner-content-wrapper\">\n        {hasIcon && <StatusIcon variant={variant} />}\n        <div className=\"ndl-banner-content\">{children}</div>\n      </div>\n      {isCloseable && (\n        <CleanIconButton\n          size=\"small\"\n          onClick={handleClose}\n          description={null}\n          htmlAttributes={{ 'aria-label': 'Close' }}\n        >\n          <XMarkIconOutline />\n        </CleanIconButton>\n      )}\n    </Element>\n  );\n};\n\nconst Banner = Object.assign(BannerComponent, {\n  Actions: BannerActions,\n  Description: BannerDescription,\n  Header: BannerHeader,\n});\n\nexport { Banner };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsGE;CACA;CACA;CACA;CACA;;;CAoBA;CACA;CACA;CACA;CACA;;;CAoBA;CACA;CACA;CACA;CACA;;;CAkBA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA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