@carbon/ibm-products-web-components
Version:
Carbon for IBM Products Web Components
57 lines (55 loc) • 1.96 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.
*/
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/globals/js/utils/collapsible-controller.ts
var CollapsibleController = class {
constructor(host, options) {
this.startY = null;
this.isDragging = false;
this.onPointerDown = (e) => {
this.startY = e.clientY;
this.isDragging = true;
};
this.onPointerMove = (e) => {
if (!this.isDragging || this.startY === null) return;
const diffY = this.startY - e.clientY;
if (diffY > 5) this.options.triggerCollapse(true);
else if (diffY < -5) this.options.triggerCollapse(false);
};
this.onPointerUp = () => {
this.isDragging = false;
this.startY = null;
document.body.style.cursor = "default";
};
this.onWheel = (e) => {
if (e.deltaY > 0) this.options.triggerCollapse(true);
else if (e.deltaY < 0) this.options.triggerCollapse(false);
};
this.options = options;
host.addController(this);
}
hostConnected() {
if (this.options.disable?.()) return;
const container = this.options.container();
if (!container) return;
container.addEventListener("pointerdown", this.onPointerDown);
container.addEventListener("pointermove", this.onPointerMove);
container.addEventListener("pointerup", this.onPointerUp);
container.addEventListener("wheel", this.onWheel);
}
hostDisconnected() {
const container = this.options.container();
if (!container) return;
container.removeEventListener("pointerdown", this.onPointerDown);
container.removeEventListener("pointermove", this.onPointerMove);
container.removeEventListener("pointerup", this.onPointerUp);
container.removeEventListener("wheel", this.onWheel);
}
};
//#endregion
exports.CollapsibleController = CollapsibleController;
//# sourceMappingURL=collapsible-controller.js.map