@react-md/divider
Version:
This package is used to create horizontal or vertical dividers in your application.
61 lines • 2.27 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { useCallback, useState } from "react";
import { applyRef } from "@react-md/utils";
/**
* This is a small hook that is used to automatically create a vertical divider
* based on the computed height of its parent element.
*
* @param maxHeight - The max height for the vertical divider. When the value is
* between 0 and 1, it will be used as a percentage. Otherwise the smaller value
* of parent element height and this will be used.
* @remarks \@since 5.0.0 The hook accepts an object instead of using multiple
* params and uses a generic for the HTMLElement type.
*/
export function useVerticalDividerHeight(_a) {
var ref = _a.ref, style = _a.style, maxHeight = _a.maxHeight;
var _b = __read(useState(undefined), 2), height = _b[0], setHeight = _b[1];
var refCallback = useCallback(function (instance) {
applyRef(instance, ref);
if (!instance || !instance.parentElement || maxHeight === 0) {
return;
}
var height = instance.parentElement.offsetHeight;
if (maxHeight <= 1) {
setHeight(height * maxHeight);
}
else {
setHeight(Math.min(height, maxHeight));
}
}, [maxHeight, ref]);
return {
ref: refCallback,
style: maxHeight <= 0 ? style : __assign(__assign({}, style), { height: height }),
};
}
//# sourceMappingURL=useVerticalDividerHeight.js.map