zarm
Version:
基于 React 的移动端UI库
62 lines (56 loc) • 2.49 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { createBEM } from '@zarm-design/bem';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import Loading from '../loading';
import { useSafeState } from '../utils/hooks';
var ActionSheetItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _ref;
var className = props.className,
bold = props.bold,
theme = props.theme,
disabled = props.disabled,
text = props.text,
onClick = props.onClick,
rest = _objectWithoutProperties(props, ["className", "bold", "theme", "disabled", "text", "onClick"]);
var _useSafeState = useSafeState(false),
_useSafeState2 = _slicedToArray(_useSafeState, 2),
loading = _useSafeState2[0],
setLoading = _useSafeState2[1];
var _React$useContext = React.useContext(ConfigContext),
prefixCls = _React$useContext.prefixCls;
var bem = createBEM('action-sheet', {
prefixCls: prefixCls
});
var cls = bem('item', [(_ref = {}, _defineProperty(_ref, "".concat(theme), !!theme), _defineProperty(_ref, "bold", bold), _defineProperty(_ref, "disabled", disabled || loading), _ref), className]);
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
ref: ref,
className: cls,
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
setLoading(true);
_context.prev = 1;
_context.next = 4;
return onClick === null || onClick === void 0 ? void 0 : onClick();
case 4:
_context.prev = 4;
setLoading(false);
return _context.finish(4);
case 7:
case "end":
return _context.stop();
}
}
}, _callee, null, [[1,, 4, 7]]);
}))
}), loading ? /*#__PURE__*/React.createElement(Loading, null) : text);
});
export default ActionSheetItem;