UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

40 lines (38 loc) 1.19 kB
/** * Find a child element inside a ref. */ export const getChildElement = (ref, selector) => ref.current ? ref.current.querySelector(selector) : undefined; /** * Get the available width of the inline card. * (Mainly here to make the component unit testable.) */ export const getInlineCardAvailableWidth = (startEl, endEl) => { const start = startEl.getBoundingClientRect().left; const end = endEl.getBoundingClientRect().left; return end - start; }; export const isOneLine = (startEl, endEl) => { const start = startEl.getBoundingClientRect().top; const end = endEl.getBoundingClientRect().top; return start === end; }; /** * Get max and min width of an overlay. * (Mainly here to make the component unit testable.) */ export const getOverlayWidths = (overlayEl, labelEl) => { const max = overlayEl.getBoundingClientRect().width; const min = max - labelEl.getBoundingClientRect().width; return { max, min }; }; export const getIconSize = labelEl => { const h2FontSizePx = 20; const fontSize = window && parseFloat(window.getComputedStyle(labelEl).fontSize); if (!fontSize || fontSize < h2FontSizePx) { return 'small'; } return 'medium'; };