@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
49 lines • 1.78 kB
JavaScript
import React from 'react';
import clsx from 'clsx';
import { convertJsxToString } from "../../shared/component-helper.js";
import { jsx as _jsx } from "react/jsx-runtime";
export const skeletonDOMAttributes = (params, skeleton, context) => {
if (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.ariaBusy;
}
return params;
};
export const createSkeletonClass = (method, skeleton, context, className = null) => {
if (skeleton || skeleton !== false && context !== null && context !== void 0 && context.skeleton) {
return clsx(className, 'dnb-skeleton', method && `dnb-skeleton--${method}`);
}
return className;
};
export function AutoSize({
__element: Comp = null,
children = null,
className = null,
style = null,
...props
}) {
const string = convertJsxToString(children);
if (typeof string === 'string') {
const countChars = string.trim().length;
if (countChars > 0) {
return _jsx(Comp, {
className: clsx("dnb-skeleton dnb-skeleton--font", className),
"data-skeleton-chars": String(countChars),
style: {
...(style || {}),
'--skeleton-chars': `${countChars}ch`
},
...props,
children: children
});
}
}
return _jsx(Comp, {
...props,
className: className,
style: style
});
}
//# sourceMappingURL=SkeletonHelper.js.map