@carbon/ibm-products
Version:
Carbon for IBM Products
58 lines (56 loc) • 2.34 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { __toESM } from "../../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../../node_modules/classnames/index.js";
import { pkg } from "../../../settings.js";
import { usePageHeader } from "./context.js";
import { scrollableAncestor } from "./utils.js";
import React from "react";
import { IconButton } from "@carbon/react";
import { ChevronUp } from "@carbon/react/icons";
//#region src/components/PageHeader/next/PageHeaderScrollButton.tsx
/**
* Copyright IBM Corp. 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const PageHeaderScrollButton = React.forwardRef(function PageHeaderExpander({ className, children, label, onClick, collapseText = "Collapse", expandText = "Expand", ...other }, ref) {
const { refs, observerState } = usePageHeader();
const fullyCollapsed = observerState.fullyCollapsed;
const handleScroller = (isFullyCollapsed) => {
if (!refs?.contentRef?.current) return;
const scrollableTarget = scrollableAncestor(refs?.contentRef.current);
if (!isFullyCollapsed) {
const pageHeaderContentHeight = refs?.contentRef.current.offsetHeight;
scrollableTarget?.scrollTo({
top: pageHeaderContentHeight,
behavior: "smooth"
});
} else scrollableTarget?.scrollTo({
top: 0,
behavior: "smooth"
});
};
return /* @__PURE__ */ React.createElement(IconButton, {
ref,
label: fullyCollapsed ? expandText : collapseText,
size: "md",
kind: "ghost",
autoAlign: true,
...other,
onClick: (event) => {
onClick?.(event);
handleScroller(!!fullyCollapsed);
},
className: (0, import_classnames.default)(className, `${pkg.prefix}--page-header--scroller-button`)
}, /* @__PURE__ */ React.createElement(ChevronUp, { className: (0, import_classnames.default)(`${pkg.prefix}--page-header--scroller-button-icon`, { [`${pkg.prefix}--page-header--scroller-button-icon-collapsed`]: fullyCollapsed }) }));
});
PageHeaderScrollButton.displayName = "PageHeaderScrollButton";
//#endregion
export { PageHeaderScrollButton };