UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

70 lines 3.63 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; const _excluded = ["className", "children", "__element", "style"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import PropTypes from 'prop-types'; import { convertJsxToString, isTrue } from '../../shared/component-helper'; import classnames from 'classnames'; export const skeletonDOMAttributes = function (params, skeleton) { let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; if (isTrue(skeleton) || skeleton !== false && context !== null && context !== void 0 && context.skeleton) { var _context$translation, _context$translation$; params.disabled = true; params['aria-disabled'] = true; params['aria-label'] = context === null || context === void 0 ? void 0 : (_context$translation = context.translation) === null || _context$translation === void 0 ? void 0 : (_context$translation$ = _context$translation.Skeleton) === null || _context$translation$ === void 0 ? void 0 : _context$translation$.aria_busy; } return params; }; export const createSkeletonClass = function (method, skeleton) { let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; let className = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 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.PureComponent { render() { const _this$props = this.props, { className, children, __element: Comp, style } = _this$props, props = _objectWithoutProperties(_this$props, _excluded); const string = convertJsxToString(children); if (typeof string === 'string') { const countChars = string.trim().length; if (countChars > 0) { return React.createElement(Comp, _objectSpread({ className: classnames("dnb-skeleton dnb-skeleton--font", className), 'data-skeleton-chars': String(countChars), style: _objectSpread(_objectSpread({}, 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 }); process.env.NODE_ENV !== "production" ? AutoSize.propTypes = { __element: PropTypes.node, children: PropTypes.node, className: PropTypes.string, style: PropTypes.object } : void 0; //# sourceMappingURL=SkeletonHelper.js.map