@carbon/ibm-products
Version:
Carbon for IBM Products
113 lines (111 loc) • 4.11 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.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../node_modules/classnames/index.js");
const require_settings = require("../../settings.js");
const require_devtools = require("../../global/js/utils/devtools.js");
const require_context = require("./utils/context.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");
let _carbon_react_icons = require("@carbon/react/icons");
//#region src/components/Coachmark/CoachmarkDragbar.tsx
/**
* Copyright IBM Corp. 2023, 2025
*
* 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__ */ require_runtime.__toESM(require_index.default);
const blockClass = `${require_settings.pkg.prefix}--coachmark-dragbar`;
const overlayBlockClass = `${require_settings.pkg.prefix}--coachmark-overlay`;
const componentName = "CoachmarkDragbar";
const defaults = {
onDrag: () => {},
onClose: () => {},
showCloseButton: true,
theme: "light"
};
/**
* DO NOT USE. This component is for the exclusive use
* of other Onboarding components.
* @deprecated This component is deprecated.
*/
const CoachmarkDragbar = react.default.forwardRef(({ a11yKeyboardHandler, onClose = defaults.onClose, onDrag = defaults.onDrag, showCloseButton = defaults.showCloseButton, theme = defaults.theme, ...rest }, ref) => {
const [isDragging, setIsDragging] = (0, react.useState)(false);
(0, react.useEffect)(() => {
const handleDragStop = () => setIsDragging(false);
window.addEventListener("mouseup", handleDragStop);
return () => {
window.removeEventListener("mouseup", handleDragStop);
};
}, []);
(0, react.useEffect)(() => {
const handleDrag = (event) => {
onDrag(event.movementX, event.movementY);
};
if (isDragging) window.addEventListener("mousemove", handleDrag);
return () => {
window.removeEventListener("mousemove", handleDrag);
};
}, [isDragging, onDrag]);
const handleDragStart = () => setIsDragging(true);
const closeIconDescription = require_context.useCoachmark()?.closeIconDescription;
return /* @__PURE__ */ react.default.createElement("header", {
...rest,
className: (0, import_classnames.default)(blockClass, `${blockClass}__${theme}`, {}),
ref,
...require_devtools.getDevtoolsProps(componentName)
}, /* @__PURE__ */ react.default.createElement("button", {
type: "button",
className: `${overlayBlockClass}__handle`,
onMouseDown: handleDragStart,
onKeyDown: a11yKeyboardHandler,
title: "Drag Handle"
}, /* @__PURE__ */ react.default.createElement(_carbon_react_icons.Draggable, { size: "16" })), showCloseButton && /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
kind: "ghost",
size: "sm",
renderIcon: _carbon_react_icons.Close,
iconDescription: closeIconDescription,
hasIconOnly: true,
className: `${overlayBlockClass}--close-btn`,
onClick: onClose
}));
});
/**@ts-ignore*/
CoachmarkDragbar.deprecated = {
level: "warn",
details: `${componentName} is deprecated.`
};
CoachmarkDragbar.displayName = componentName;
CoachmarkDragbar.propTypes = {
/**
* Handler to manage keyboard interactions with the dragbar.
*/
a11yKeyboardHandler: prop_types.default.func.isRequired,
/**
* Function to call when the close button is clicked.
*/
onClose: prop_types.default.func,
/**
* Function to call when the user clicks and drags the Coachmark.
* For internal use only by the parent CoachmarkOverlay.
*/
onDrag: prop_types.default.func,
/**
* Show/hide the "X" close button.
*/
showCloseButton: prop_types.default.bool,
/**
* Determines the theme of the component.
*/
theme: prop_types.default.oneOf(["light", "dark"])
};
//#endregion
exports.CoachmarkDragbar = CoachmarkDragbar;