UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

62 lines 2.05 kB
import React from 'react'; import classnames from 'classnames'; import { combineDescribedBy } from '../../shared/component-helper'; export function injectTooltipSemantic(params) { params.tabIndex = '0'; params.className = classnames("dnb-tooltip__wrapper dnb-tab-focus", params.className); return params; } export const defaultProps = { id: null, size: 'basis', active: null, position: 'top', arrow: 'center', align: null, fixedPosition: false, skipPortal: null, noAnimation: false, showDelay: 300, hideDelay: 500, targetSelector: null, targetElement: null, className: null, children: null, tooltip: null }; export function getTargetElement(target) { if (typeof document !== 'undefined') { return typeof target === 'string' ? typeof document !== 'undefined' && document.querySelector(target) : target; } } export function useHandleAria(targetElement, internalId) { React.useEffect(() => { try { const existing = { 'aria-describedby': targetElement.getAttribute('aria-describedby') }; targetElement.setAttribute('aria-describedby', combineDescribedBy(existing, internalId)); } catch (e) {} }, [targetElement, internalId]); } export function getPropsFromTooltipProp(localProps) { return localProps.tooltip ? React.isValidElement(localProps.tooltip) && localProps.tooltip.props ? localProps.tooltip.props : { children: localProps.tooltip } : null; } export function getRefElement(target) { var _unknownTarget$curren; const unknownTarget = target; let element = target; if (unknownTarget !== null && unknownTarget !== void 0 && (_unknownTarget$curren = unknownTarget.current) !== null && _unknownTarget$curren !== void 0 && _unknownTarget$curren._ref) { element = getRefElement(unknownTarget.current._ref); } if (element && Object.prototype.hasOwnProperty.call(element, 'current')) { element = element.current; } return element; } export const isTouch = type => { return /touch/i.test(type); }; //# sourceMappingURL=TooltipHelpers.js.map