UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

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