@chayns-components/core
Version:
A set of beautiful React components for developing your own applications with chayns.
68 lines (66 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getElementClickEvent = exports.getAccordionHeadHeight = void 0;
var _react = require("react");
const getAccordionHeadHeight = ({
isWrapped,
title,
width,
hasSearch
}) => {
const element = document.createElement('div');
element.style.opacity = '1';
element.style.pointerEvents = 'none';
element.style.whiteSpace = 'nowrap';
element.style.width = `${width}px`;
element.innerHTML = title ?? '';
document.body.appendChild(element);
const closedHeight = Math.max(element.clientHeight + 8, isWrapped ? 40 : 33);
if (isWrapped) {
element.style.fontWeight = 'bold';
element.style.whiteSpace = 'nowrap';
} else {
element.style.fontSize = '1.3rem';
element.style.whiteSpace = hasSearch ? 'nowrap' : 'normal';
}
const openHeight = Math.max(element.clientHeight + 8, isWrapped ? 40 : 33);
document.body.removeChild(element);
return {
closed: closedHeight,
open: openHeight
};
};
exports.getAccordionHeadHeight = getAccordionHeadHeight;
const getElementClickEvent = element => {
let hasClickHandler = false;
const checkForClickHandler = el => {
if (! /*#__PURE__*/(0, _react.isValidElement)(el)) return;
if (typeof el.type !== 'string' && 'displayName' in el.type && (el.type.displayName === 'Checkbox' || el.type.displayName === 'ComboBox' || el.type.displayName === 'SelectButton' || el.type.displayName === 'AmountControl')) {
hasClickHandler = true;
return;
}
if (
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
el.props.onClick ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
el.props.onPointerDown ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
el.props.onMouseDown ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
el.props.onTouchStart) {
hasClickHandler = true;
return;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (el.props.children) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
_react.Children.forEach(el.props.children, checkForClickHandler);
}
};
checkForClickHandler(element);
return hasClickHandler;
};
exports.getElementClickEvent = getElementClickEvent;
//# sourceMappingURL=accordion.js.map