{"version":3,"file":"DropdownButton.mjs","names":[],"sources":["../../../src/dropdown-button/DropdownButton.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 PolymorphicCommonProps } from '../_common/types';\nimport { ChevronDownIconOutline } from '../icons/generated/heroIcons/ChevronDownIconOutline';\n\n/**\n *\n *\n * Types\n *\n *\n */\n\n/**\n * @remarks\n * Make sure to set `isOpen` to the corresponding state of the Menu that is being opened by the DropdownButton. That makes sure proper styling and aria attributes are applied to reflect the state.\n */\ntype DropdownButtonProps = {\n  /** Content displayed in the button */\n  children?: React.ReactNode;\n  /** Size of button */\n  size?: 'small' | 'medium' | 'large';\n  /** Whether the button is in floating state */\n  isFloating?: boolean;\n  /** Whether the button is in disabled state */\n  isDisabled?: boolean;\n  /** Element that is shown before the button content */\n  leadingElement?: React.ReactNode;\n  /** If the dropdown is activated */\n  isOpen?: boolean;\n  /** Callback function to be called when the button is clicked */\n  onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n  /** Additional classnames */\n  className?: string;\n  /** If the button is loading. Will display a loading spinner */\n  isLoading?: boolean;\n  /** Accessible message for screen readers when the button is in a loading state */\n  loadingMessage?: string;\n};\n\n/**\n *\n *\n * DropdownButton Component\n *\n *\n */\n\nexport const DropdownButton = function DropdownButton<\n  T extends React.ElementType = 'button',\n>({\n  as,\n  children,\n  size = 'medium',\n  isDisabled = false,\n  isFloating = false,\n  leadingElement,\n  isOpen = false,\n  onClick,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  isLoading = false,\n  loadingMessage = 'Loading',\n  ...restProps\n}: PolymorphicCommonProps<T, DropdownButtonProps>) {\n  const Component: React.ElementType = as ?? 'button';\n  const classes = classNames('ndl-dropdown-btn', className, {\n    'ndl-disabled': isDisabled,\n    'ndl-floating-btn': isFloating,\n    'ndl-large': size === 'large',\n    'ndl-loading': isLoading,\n    'ndl-medium': size === 'medium',\n    'ndl-open': isOpen,\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    <Component\n      className={classes}\n      disabled={isDisabled}\n      aria-disabled={!isInteractable}\n      onClick={handleClick}\n      aria-expanded={isOpen}\n      ref={ref}\n      style={style}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      <div className=\"ndl-dropdown-btn-inner\">\n        <div className=\"ndl-dropdown-btn-leading-wrapper\">\n          {leadingElement}\n          <span className=\"ndl-dropdown-btn-content\">{children}</span>\n        </div>\n\n        <ChevronDownIconOutline\n          className={classNames('ndl-dropdown-button-icon', {\n            'ndl-dropdown-button-icon-open': isOpen,\n          })}\n        />\n        {isLoading && (\n          <ButtonSpinner loadingMessage={loadingMessage} size={size} />\n        )}\n      </div>\n    </Component>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyEE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;;AAhBF,MAAa,iB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