UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

59 lines (58 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AutoSize = AutoSize; exports.skeletonDOMAttributes = exports.createSkeletonClass = void 0; var _react = _interopRequireDefault(require("react")); var _clsx = _interopRequireDefault(require("clsx")); var _componentHelper = require("../../shared/component-helper.js"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } 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; }; exports.skeletonDOMAttributes = skeletonDOMAttributes; const createSkeletonClass = (method, skeleton, context, className = null) => { if (skeleton || skeleton !== false && context !== null && context !== void 0 && context.skeleton) { return (0, _clsx.default)(className, 'dnb-skeleton', method && `dnb-skeleton--${method}`); } return className; }; exports.createSkeletonClass = createSkeletonClass; function AutoSize({ __element: Comp = null, children = null, className = null, style = null, ...props }) { const string = (0, _componentHelper.convertJsxToString)(children); if (typeof string === 'string') { const countChars = string.trim().length; if (countChars > 0) { return (0, _jsxRuntime.jsx)(Comp, { className: (0, _clsx.default)("dnb-skeleton dnb-skeleton--font", className), "data-skeleton-chars": String(countChars), style: { ...(style || {}), '--skeleton-chars': `${countChars}ch` }, ...props, children: children }); } } return (0, _jsxRuntime.jsx)(Comp, { ...props, className: className, style: style }); } //# sourceMappingURL=SkeletonHelper.js.map