UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com's products.

42 lines 1.49 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import React from "react"; import cx from "clsx"; const AccordionSectionHeader = ({ children, actions, expanded, expandOnTileClick, onExpand, expandable, dataTest, ariaControls }) => { const isInteractive = expandOnTileClick && !expanded && expandable; const handleClick = React.useCallback(e => { e.stopPropagation(); onExpand?.(); }, [onExpand]); const handleKeyDown = React.useCallback(e => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onExpand?.(); } }, [onExpand]); const content = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { className: "flex grow items-center" }, children), !expanded && expandable && actions && /*#__PURE__*/React.createElement("div", { className: "ms-600 flex" }, actions)); return /*#__PURE__*/React.createElement("div", _extends({ className: cx("p-600 bg-white-normal flex w-full items-center rounded-[inherit]", expanded ? "min-h-[19px]" : "min-h-form-box-normal", isInteractive && "hover:bg-cloud-light cursor-pointer border-0 bg-transparent text-left"), "data-test": dataTest && `${dataTest}Header` }, isInteractive && { role: "button", onClick: handleClick, onKeyDown: handleKeyDown, tabIndex: 0, "aria-controls": ariaControls, "aria-expanded": expanded || undefined }), content); }; export default AccordionSectionHeader;