@flatbiz/antd
Version:
67 lines (63 loc) • 2.25 kB
JavaScript
/*! @flatjs/forge MIT @flatbiz/antd */
import _LoadingOutlined from '@ant-design/icons/es/icons/LoadingOutlined.js';
import { _ as _objectWithoutProperties, a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js';
import { isPromise } from '@dimjs/lang/is-promise';
import { hooks } from '@wove/react/hooks';
import { useState } from 'react';
import { Tag } from 'antd';
import { isUndefinedOrNull } from '@flatbiz/utils';
import { fbaHooks } from './fba-hooks/index.js';
import { jsxs, jsx } from 'react/jsx-runtime';
var _excluded = ["loading", "children", "debounceDuration", "style"];
/**
* 为 Tag 添加 loading 效果
*/
var TagWrapper = function TagWrapper(props) {
var loading = props.loading,
children = props.children,
debounceDuration = props.debounceDuration,
style = props.style,
otherProps = _objectWithoutProperties(props, _excluded);
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
innerLoading = _useState2[0],
setLoading = _useState2[1];
var debounceDurationMew = isUndefinedOrNull(debounceDuration) ? 500 : debounceDuration;
fbaHooks.useEffectCustom(function () {
if (!isUndefinedOrNull(loading)) {
setLoading(loading || false);
}
}, [loading]);
var onClick = hooks.useDebounceClick(function (e) {
var onClick = props.onClick;
if (!onClick) {
return;
}
var result = onClick(e);
if (result && isPromise(result)) {
setLoading(true);
result.catch(function (error) {
console.error(error);
}).finally(function () {
setLoading(false);
});
}
}, debounceDurationMew);
return /*#__PURE__*/jsxs(Tag, _objectSpread2(_objectSpread2({}, otherProps), {}, {
onClick: onClick,
style: _objectSpread2({
cursor: props.onClick ? 'pointer' : 'default'
}, style),
children: [innerLoading && /*#__PURE__*/jsx("div", {
className: "tw-center-loading",
children: /*#__PURE__*/jsx(_LoadingOutlined, {})
}), innerLoading ? /*#__PURE__*/jsx("div", {
style: {
opacity: 0.5
},
children: children
}) : children]
}));
};
export { TagWrapper as T };
//# sourceMappingURL=tag-wrapper-BmGPE1YG.js.map