linkmore-design
Version:
π πlmη»δ»ΆεΊγπ
66 lines (63 loc) β’ 2.63 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["prefixCls", "count", "className", "motionClassName", "style", "title", "show", "component", "children"];
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from "../config-provider";
import { cloneElement } from "../_util/reactNode";
import SingleNumber from "./SingleNumber";
var ScrollNumber = function ScrollNumber(_ref) {
var customizePrefixCls = _ref.prefixCls,
count = _ref.count,
className = _ref.className,
motionClassName = _ref.motionClassName,
style = _ref.style,
title = _ref.title,
show = _ref.show,
_ref$component = _ref.component,
component = _ref$component === void 0 ? 'sup' : _ref$component,
children = _ref.children,
restProps = _objectWithoutProperties(_ref, _excluded);
var _React$useContext = React.useContext(ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls;
var prefixCls = getPrefixCls('scroll-number', customizePrefixCls);
// ============================ Render ============================
var newProps = _objectSpread(_objectSpread({}, restProps), {}, {
'data-show': show,
style: style,
className: classNames(prefixCls, className, motionClassName),
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
});
});
}
// allow specify the border
// mock border-color by box-shadow for compatible with old usage:
// <Badge count={4} style={{ backgroundColor: '#fff', color: '#999', borderColor: '#d9d9d9' }} />
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 === null || oriProps === void 0 ? void 0 : oriProps.className, motionClassName)
};
});
}
return /*#__PURE__*/React.createElement(component, newProps, numberNodes);
};
export default ScrollNumber;