89 lines
4.1 KiB
JavaScript
89 lines
4.1 KiB
JavaScript
|
"use strict";
|
|||
|
|
|||
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|||
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|||
|
Object.defineProperty(exports, "__esModule", {
|
|||
|
value: true
|
|||
|
});
|
|||
|
exports.default = void 0;
|
|||
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|||
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|||
|
var _KeyCode = _interopRequireDefault(require("rc-util/lib/KeyCode"));
|
|||
|
var React = _interopRequireWildcard(require("react"));
|
|||
|
var _util = require("../util");
|
|||
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|||
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|||
|
function TabNode(_ref) {
|
|||
|
var _classNames;
|
|||
|
var prefixCls = _ref.prefixCls,
|
|||
|
id = _ref.id,
|
|||
|
active = _ref.active,
|
|||
|
_ref$tab = _ref.tab,
|
|||
|
key = _ref$tab.key,
|
|||
|
label = _ref$tab.label,
|
|||
|
disabled = _ref$tab.disabled,
|
|||
|
closeIcon = _ref$tab.closeIcon,
|
|||
|
closable = _ref.closable,
|
|||
|
renderWrapper = _ref.renderWrapper,
|
|||
|
removeAriaLabel = _ref.removeAriaLabel,
|
|||
|
editable = _ref.editable,
|
|||
|
onClick = _ref.onClick,
|
|||
|
onFocus = _ref.onFocus,
|
|||
|
style = _ref.style;
|
|||
|
var tabPrefix = "".concat(prefixCls, "-tab");
|
|||
|
var removable = (0, _util.getRemovable)(closable, closeIcon, editable, disabled);
|
|||
|
function onInternalClick(e) {
|
|||
|
if (disabled) {
|
|||
|
return;
|
|||
|
}
|
|||
|
onClick(e);
|
|||
|
}
|
|||
|
function onRemoveTab(event) {
|
|||
|
event.preventDefault();
|
|||
|
event.stopPropagation();
|
|||
|
editable.onEdit('remove', {
|
|||
|
key: key,
|
|||
|
event: event
|
|||
|
});
|
|||
|
}
|
|||
|
var node = /*#__PURE__*/React.createElement("div", {
|
|||
|
key: key
|
|||
|
// ref={ref}
|
|||
|
,
|
|||
|
"data-node-key": (0, _util.genDataNodeKey)(key),
|
|||
|
className: (0, _classnames.default)(tabPrefix, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(tabPrefix, "-with-remove"), removable), (0, _defineProperty2.default)(_classNames, "".concat(tabPrefix, "-active"), active), (0, _defineProperty2.default)(_classNames, "".concat(tabPrefix, "-disabled"), disabled), _classNames)),
|
|||
|
style: style,
|
|||
|
onClick: onInternalClick
|
|||
|
}, /*#__PURE__*/React.createElement("div", {
|
|||
|
role: "tab",
|
|||
|
"aria-selected": active,
|
|||
|
id: id && "".concat(id, "-tab-").concat(key),
|
|||
|
className: "".concat(tabPrefix, "-btn"),
|
|||
|
"aria-controls": id && "".concat(id, "-panel-").concat(key),
|
|||
|
"aria-disabled": disabled,
|
|||
|
tabIndex: disabled ? null : 0,
|
|||
|
onClick: function onClick(e) {
|
|||
|
e.stopPropagation();
|
|||
|
onInternalClick(e);
|
|||
|
},
|
|||
|
onKeyDown: function onKeyDown(e) {
|
|||
|
if ([_KeyCode.default.SPACE, _KeyCode.default.ENTER].includes(e.which)) {
|
|||
|
e.preventDefault();
|
|||
|
onInternalClick(e);
|
|||
|
}
|
|||
|
},
|
|||
|
onFocus: onFocus
|
|||
|
}, label), removable && /*#__PURE__*/React.createElement("button", {
|
|||
|
type: "button",
|
|||
|
"aria-label": removeAriaLabel || 'remove',
|
|||
|
tabIndex: 0,
|
|||
|
className: "".concat(tabPrefix, "-remove"),
|
|||
|
onClick: function onClick(e) {
|
|||
|
e.stopPropagation();
|
|||
|
onRemoveTab(e);
|
|||
|
}
|
|||
|
}, closeIcon || editable.removeIcon || '×'));
|
|||
|
return renderWrapper ? renderWrapper(node) : node;
|
|||
|
}
|
|||
|
var _default = TabNode;
|
|||
|
exports.default = _default;
|