choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
70 lines (58 loc) • 2.43 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["prefixCls", "count", "className", "style", "title", "hidden", "component", "children"];
import React, { createElement, memo, useContext } from 'react';
import classNames from 'classnames';
import { cloneElement } from '../_util/reactNode';
import SingleNumber from './SingleNumber';
import ConfigContext from '../config-provider/ConfigContext';
var ScrollNumber = function ScrollNumber(_ref) {
var customizePrefixCls = _ref.prefixCls,
count = _ref.count,
className = _ref.className,
style = _ref.style,
title = _ref.title,
hidden = _ref.hidden,
_ref$component = _ref.component,
component = _ref$component === void 0 ? 'sup' : _ref$component,
children = _ref.children,
restProps = _objectWithoutProperties(_ref, _excluded);
var _useContext = useContext(ConfigContext),
getPrefixCls = _useContext.getPrefixCls;
var prefixCls = getPrefixCls('scroll-number', customizePrefixCls); // ============================ Render ============================
var newProps = _objectSpread(_objectSpread({}, restProps), {}, {
'data-show': !hidden,
style: style,
className: classNames(prefixCls, className),
title: title
}); // Only integer need motion
var numberNodes = count;
if (count && Number(count) % 1 === 0) {
var numberList = String(count).split('');
numberNodes = numberList.map(function (num, i) {
return /*#__PURE__*/React.createElement(SingleNumber, {
prefixCls: prefixCls,
count: Number(count),
value: num,
// eslint-disable-next-line react/no-array-index-key
key: numberList.length - i
});
});
}
if (style && style.borderColor) {
newProps.style = _objectSpread(_objectSpread({}, style), {}, {
boxShadow: "0 0 0 1px ".concat(style.borderColor, " inset")
});
}
if (children) {
return cloneElement(children, function (oriProps) {
return {
className: classNames("".concat(prefixCls, "-custom-component"), oriProps && oriProps.className)
};
});
}
return /*#__PURE__*/createElement(component, newProps, numberNodes);
};
ScrollNumber.displayName = 'ScrollNumber';
export default /*#__PURE__*/memo(ScrollNumber);
//# sourceMappingURL=ScrollNumber.js.map