UNPKG

@chayns-components/core

Version:

A set of beautiful React components for developing your own applications with chayns.

60 lines (59 loc) 2.21 kB
import { Children, isValidElement } from 'react'; export 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 }; }; export const getElementClickEvent = element => { let hasClickHandler = false; const checkForClickHandler = el => { if (! /*#__PURE__*/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 Children.forEach(el.props.children, checkForClickHandler); } }; checkForClickHandler(element); return hasClickHandler; }; //# sourceMappingURL=accordion.js.map