react-easy-scrollbar
Version:
Completely pollution-free UI, perfect scrollbar implemented through CSS
106 lines (104 loc) • 4.05 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/hooks/useEasyScrollbar.ts
var useEasyScrollbar_exports = {};
__export(useEasyScrollbar_exports, {
default: () => useEasyScrollbar_default,
useEasyScrollbar: () => useEasyScrollbar
});
module.exports = __toCommonJS(useEasyScrollbar_exports);
var import_react = require("react");
var import_perfect_scrollbar = __toESM(require("perfect-scrollbar"));
var import_perfect_scrollbar2 = require("perfect-scrollbar/css/perfect-scrollbar.css");
var import_scrollbar = require("../scrollbar.css");
var useEasyScrollbar = (ref, options) => {
const psRef = (0, import_react.useRef)(null);
const _ps = psRef.current;
(0, import_react.useEffect)(() => {
if (!ref) {
return;
}
if (typeof ref === "function") {
let fn = ref;
ref = (element) => {
fn(element);
if (!element) {
return;
}
if (element instanceof Element) {
const computedStyle = window.getComputedStyle(element);
const hasPositionStyle = computedStyle.position !== "static";
if (!hasPositionStyle) {
element.classList.add("easy-container");
}
psRef.current = new import_perfect_scrollbar.default(element, options);
} else {
console.warn("ref current is not a HTMLElement");
}
};
} else if (typeof ref === "string") {
const element = document.querySelector(ref);
if (element) {
if (element instanceof Element) {
const computedStyle = window.getComputedStyle(element);
const hasPositionStyle = computedStyle.position !== "static";
if (!hasPositionStyle) {
element.classList.add("easy-container");
}
psRef.current = new import_perfect_scrollbar.default(ref, options);
} else {
console.warn("ref current is not a HTMLElement");
}
}
} else {
const element = ref.current;
if (element) {
if (element instanceof Element) {
const computedStyle = window.getComputedStyle(element);
const hasPositionStyle = computedStyle.position !== "static";
if (!hasPositionStyle) {
element.classList.add("easy-container");
}
psRef.current = new import_perfect_scrollbar.default(element, options);
} else {
console.warn("ref current is not a HTMLElement");
}
}
}
return () => {
if (_ps) {
_ps.destroy();
}
};
}, [_ps, ref, options]);
};
var useEasyScrollbar_default = useEasyScrollbar;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useEasyScrollbar
});