UNPKG

@react-md/divider

Version:

This package is used to create horizontal or vertical dividers in your application.

65 lines 2.47 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useVerticalDividerHeight = void 0; var react_1 = require("react"); var utils_1 = require("@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. */ function useVerticalDividerHeight(_a) { var ref = _a.ref, style = _a.style, maxHeight = _a.maxHeight; var _b = __read((0, react_1.useState)(undefined), 2), height = _b[0], setHeight = _b[1]; var refCallback = (0, react_1.useCallback)(function (instance) { (0, utils_1.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 }), }; } exports.useVerticalDividerHeight = useVerticalDividerHeight; //# sourceMappingURL=useVerticalDividerHeight.js.map