UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

57 lines 2.16 kB
import _extends from "@babel/runtime-corejs3/helpers/esm/extends"; import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty"; import React from 'react'; import classnames from 'classnames'; import { convertJsxToString, isTrue } from "../../shared/component-helper.js"; export const skeletonDOMAttributes = (params, skeleton, context) => { if (isTrue(skeleton) || skeleton !== false && context !== null && context !== void 0 && context.skeleton) { var _context$translation; params.disabled = true; params['aria-disabled'] = true; params['aria-label'] = context === null || context === void 0 || (_context$translation = context.translation) === null || _context$translation === void 0 || (_context$translation = _context$translation.Skeleton) === null || _context$translation === void 0 ? void 0 : _context$translation.aria_busy; } return params; }; export const createSkeletonClass = (method, skeleton, context, className = null) => { if (isTrue(skeleton) || skeleton !== false && context !== null && context !== void 0 && context.skeleton) { return classnames(className, 'dnb-skeleton', method && `dnb-skeleton--${method}`); } return className; }; export class AutoSize extends React.Component { render() { const { className, children, __element: Comp, style, ...props } = this.props; const string = convertJsxToString(children); if (typeof string === 'string') { const countChars = string.trim().length; if (countChars > 0) { return React.createElement(Comp, { className: classnames("dnb-skeleton dnb-skeleton--font", className), 'data-skeleton-chars': String(countChars), style: { ...(style || {}), '--skeleton-chars': `${countChars}ch` }, ...props }, children); } } return React.createElement(Comp, _extends({}, props, { className: className, style: style })); } } _defineProperty(AutoSize, "defaultProps", { __element: null, children: null, className: null, style: null }); //# sourceMappingURL=SkeletonHelper.js.map