{"version":3,"file":"SelectIconButton.mjs","names":[],"sources":["../../../src/select-icon-button/SelectIconButton.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 { ButtonSpinner } from '../_common/ButtonSpinner';\nimport { type CommonProps, type TooltipObjectProps } from '../_common/types';\nimport { ChevronDownIconOutline } from '../icons/generated/heroIcons/ChevronDownIconOutline';\nimport { Tooltip } from '../tooltip';\n\ntype SelectIconButtonProps = {\n  /** Content displayed in the button */\n  children?: React.ReactNode;\n  /** Size of button */\n  size?: 'small' | 'medium' | 'large';\n  /** If the button is doing something Async, it will display a loading spinner   */\n  isLoading?: boolean;\n  /** Whether the button is in disabled state */\n  isDisabled?: boolean;\n  /** If the button is opened */\n  isOpen: boolean;\n  /** Callback function to be called when the button is clicked */\n  onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n  /**\n   * A string that will be shown as a tooltip when hovering over the button. It also acts as an aria-label.\n   * {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label}\n   */\n  description: string | null;\n  /**\n   * Props for the tooltip component.\n   */\n  tooltipProps?: TooltipObjectProps;\n\n  /** Accessible message for screen readers when the button is in a loading state */\n  loadingMessage?: string;\n};\n\nexport const SelectIconButton = ({\n  children,\n  size = 'medium',\n  isDisabled = false,\n  isLoading = false,\n  isOpen = false,\n  className,\n  description,\n  tooltipProps,\n  onClick,\n  style,\n  htmlAttributes,\n  ref,\n  loadingMessage = 'Loading',\n  ...restProps\n}: CommonProps<'button', SelectIconButtonProps>) => {\n  const classes = classNames('ndl-select-icon-btn', className, {\n    'ndl-active': isOpen,\n    'ndl-disabled': isDisabled,\n    'ndl-large': size === 'large',\n    'ndl-loading': isLoading,\n    'ndl-medium': size === 'medium',\n    'ndl-small': size === 'small',\n  });\n\n  const isInteractable = !isDisabled && !isLoading;\n\n  const handleClick = (\n    event: React.MouseEvent<HTMLButtonElement, MouseEvent>,\n  ) => {\n    // If the button is disabled or loading, we don't want to call the onClick handler. The loading is only aria-disabled, so we need this.\n    if (!isInteractable) {\n      event.preventDefault();\n      event.stopPropagation();\n      return;\n    }\n\n    if (onClick) {\n      onClick(event);\n    }\n  };\n\n  return (\n    <Tooltip\n      hoverDelay={{\n        close: 0,\n        open: 500,\n      }}\n      type=\"simple\"\n      // We disable the tooltip if the button is disabled or open, so it doesn't interfere with a menu open\n      isDisabled={description === null || isDisabled || isOpen === true}\n      shouldCloseOnReferenceClick\n      {...tooltipProps?.root}\n    >\n      <Tooltip.Trigger {...tooltipProps?.trigger} hasButtonWrapper>\n        <button\n          type=\"button\"\n          ref={ref}\n          className={classes}\n          style={style}\n          disabled={isDisabled}\n          aria-disabled={!isInteractable}\n          aria-label={description ?? undefined}\n          aria-expanded={isOpen}\n          onClick={handleClick}\n          {...restProps}\n          {...htmlAttributes}\n        >\n          <div className=\"ndl-select-icon-btn-inner\">\n            <div className=\"ndl-icon\">{children}</div>\n          </div>\n          <ChevronDownIconOutline\n            className={classNames('ndl-select-icon-btn-icon', {\n              'ndl-select-icon-btn-icon-open': isOpen === true,\n            })}\n          />\n          {isLoading && (\n            <ButtonSpinner loadingMessage={loadingMessage} size={size} />\n          )}\n        </button>\n      </Tooltip.Trigger>\n      <Tooltip.Content {...tooltipProps?.content}>\n        {description}\n      </Tooltip.Content>\n    </Tooltip>\n  );\n};\n"],"mappings":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