{"version":3,"file":"IconButtonArray.mjs","names":[],"sources":["../../../src/icon-button-array/IconButtonArray.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 React from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ChevronDownIconOutline } from '../icons/generated/heroIcons/ChevronDownIconOutline';\nimport { ChevronLeftIconOutline } from '../icons/generated/heroIcons/ChevronLeftIconOutline';\nimport { ChevronRightIconOutline } from '../icons/generated/heroIcons/ChevronRightIconOutline';\nimport { ChevronUpIconOutline } from '../icons/generated/heroIcons/ChevronUpIconOutline';\n\n/**\n * Types\n */\ntype IconButtonArrayProps = {\n  /** Content displayed in the icon button array */\n  children: React.ReactNode;\n  /** Orientation of the icon button array */\n  orientation?: 'vertical' | 'horizontal';\n  /** Whether the icon button array is floating */\n  isFloating?: boolean;\n  /** Size of the icon button array */\n  size?: 'small' | 'medium' | 'large';\n  /** Additional class name */\n  className?: string;\n};\n\ntype CollapsibleButtonWrapperProps = {\n  /** Icon buttons to be displayed in the collapsible button wrapper */\n  children:\n    | React.ReactElement<React.ComponentProps<typeof CleanIconButton>>\n    | React.ReactElement<React.ComponentProps<typeof CleanIconButton>>[];\n};\n\nconst CollapsibleButtonWrapper: React.FC<CollapsibleButtonWrapperProps> = ({\n  children,\n}) => {\n  return <>{children}</>;\n};\nCollapsibleButtonWrapper.displayName = 'CollapsibleButtonWrapper';\n\nexport const IconButtonArrayComponent = <T extends React.ElementType = 'div'>({\n  children,\n  as,\n  isFloating = false,\n  orientation = 'horizontal',\n  size = 'medium',\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: PolymorphicCommonProps<T, IconButtonArrayProps>) => {\n  const [isCollapsed, setIsCollapsed] = React.useState(true);\n\n  const classes = classNames('ndl-icon-btn-array', className, {\n    'ndl-array-floating': isFloating,\n    'ndl-col': orientation === 'vertical',\n    'ndl-row': orientation === 'horizontal',\n    [`ndl-${size}`]: size,\n  });\n\n  const Component: React.ElementType = as || 'div';\n\n  const childrenArray = React.Children.toArray(\n    children,\n  ) as React.ReactElement[];\n\n  const fixedButtons = childrenArray.filter(\n    (child) =>\n      !React.isValidElement(child) ||\n      (child.type as React.ComponentType).displayName !==\n        'CollapsibleButtonWrapper',\n  );\n\n  const collapsibleButtonWrapper = childrenArray.find(\n    (child) =>\n      React.isValidElement(child) &&\n      (child.type as React.ComponentType).displayName ===\n        'CollapsibleButtonWrapper',\n  );\n\n  const collapsibleButtonsWithProps = collapsibleButtonWrapper\n    ? (\n        collapsibleButtonWrapper as React.ReactElement<CollapsibleButtonWrapperProps>\n      ).props.children\n    : null;\n\n  const renderChevronIcon = () => {\n    if (orientation === 'horizontal') {\n      return isCollapsed ? (\n        <ChevronRightIconOutline />\n      ) : (\n        <ChevronLeftIconOutline />\n      );\n    }\n    return isCollapsed ? <ChevronDownIconOutline /> : <ChevronUpIconOutline />;\n  };\n\n  return (\n    <Component\n      role=\"group\"\n      className={classes}\n      ref={ref}\n      style={style}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      {fixedButtons}\n      {collapsibleButtonsWithProps && (\n        <>\n          {!isCollapsed && collapsibleButtonsWithProps}\n          <CleanIconButton\n            onClick={() => {\n              setIsCollapsed((prev) => !prev);\n            }}\n            size={size}\n            description={isCollapsed ? 'Show more' : 'Show less'}\n            tooltipProps={{\n              root: {\n                shouldCloseOnReferenceClick: true,\n              },\n            }}\n            htmlAttributes={{\n              'aria-expanded': !isCollapsed,\n            }}\n          >\n            {renderChevronIcon()}\n          </CleanIconButton>\n        </>\n      )}\n    </Component>\n  );\n};\n\nconst IconButtonArray = Object.assign(IconButtonArrayComponent, {\n  CollapsibleButtonWrapper: CollapsibleButtonWrapper,\n});\n\nexport { IconButtonArray };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6DE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAhBF,MAAM,4BAAqE,EACzE,eACI;CACJ,OAAO,oBAAA,YAAA,EAAG,SAAW,CAAA;AACvB;AACA,yBAAyB,cAAc;AAEvC,MAAa,4BAAiE,SAWvB;CAXuB,IAAA,EAC5E,UACA,IACA,aAAa,OACb,cAAc,cACd,OAAO,UACP,WACA,OACA,gBACA,QAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,CAAC,aAAa,kBAAkB,MAAM,SAAS,IAAI;CAEzD,MAAM,UAAU,WAAW,sBAAsB,WAAW;EAC1D,sBAAsB;EACtB,WAAW,gBAAgB;EAC3B,WAAW,gBAAgB;GAC1B,OAAO,SAAS;CACnB,CAAC;CAED,MAAM,YAA+B,MAAM;CAE3C,MAAM,gBAAgB,MAAM,SAAS,QACnC,QACF;CAEA,MAAM,eAAe,cAAc,QAChC,UACC,CAAC,MAAM,eAAe,KAAK,KAC1B,MAAM,KAA6B,gBAClC,0BACN;CAEA,MAAM,2BAA2B,cAAc,MAC5C,UACC,MAAM,eAAe,KAAK,KACzB,MAAM,KAA6B,gBAClC,0BACN;CAEA,MAAM,8BAA8B,2BAE9B,yBACA,MAAM,WACR;CAEJ,MAAM,0BAA0B;EAC9B,IAAI,gBAAgB,cAClB,OAAO,cACL,oBAAC,yBAAD,CAA0B,CAAA,IAE1B,oBAAC,wBAAD,CAAyB,CAAA;EAG7B,OAAO,cAAc,oBAAC,wBAAD,CAAyB,CAAA,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