@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
48 lines • 1.44 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?.skeleton) {
params.disabled = true;
params['aria-disabled'] = true;
params['aria-label'] = context?.translation?.Skeleton?.ariaBusy;
}
return params;
};
export const createSkeletonClass = (method, skeleton, context, className = null) => {
if (skeleton || skeleton !== false && 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