@txdfe/at
Version:
一个设计体系组件库
151 lines (149 loc) • 8.43 kB
JavaScript
var _excluded = ["title", "icon", "children", "className", "isExpanded", "disabled", "style", "prefix", "onClick", "id"];
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ConfigProvider from '../config-provider';
import Icon from '../icon';
import { func, KEYCODE } from '../util';
/** Collapse.Panel */
var Panel = /*#__PURE__*/function (_React$Component) {
function Panel() {
var _this;
_classCallCheck(this, Panel);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, Panel, [].concat(args));
//
_defineProperty(_this, "onKeyDown", function (e) {
var keyCode = e.keyCode;
if (keyCode === KEYCODE.SPACE) {
var onClick = _this.props.onClick;
e.preventDefault();
onClick && onClick(e);
}
});
_defineProperty(_this, "renderTitleIcon", function () {
var _this$props = _this.props,
prefix = _this$props.prefix,
icon = _this$props.icon;
if (icon) {
if (typeof icon === 'string') {
return /*#__PURE__*/React.createElement("span", {
className: "".concat(prefix, "collapse-panel-title-icon")
}, /*#__PURE__*/React.createElement(Icon, {
type: icon
}));
} else {
return /*#__PURE__*/React.createElement("span", {
className: "".concat(prefix, "collapse-panel-title-icon")
}, icon);
}
}
return null;
});
return _this;
}
_inherits(Panel, _React$Component);
return _createClass(Panel, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
title = _this$props2.title,
icon = _this$props2.icon,
children = _this$props2.children,
className = _this$props2.className,
isExpanded = _this$props2.isExpanded,
disabled = _this$props2.disabled,
style = _this$props2.style,
prefix = _this$props2.prefix,
onClick = _this$props2.onClick,
id = _this$props2.id,
others = _objectWithoutProperties(_this$props2, _excluded);
var cls = classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefix, "collapse-panel"), true), "".concat(prefix, "collapse-panel-expanded"), isExpanded), "".concat(prefix, "collapse-panel-disabled"), disabled), className, className));
var iconCls = classNames(_defineProperty(_defineProperty({}, "".concat(prefix, "collapse-panel-icon"), true), "".concat(prefix, "collapse-panel-icon-expanded"), isExpanded));
// 为了无障碍 需要添加两个id
var headingId = id ? "".concat(id, "-heading") : undefined;
var regionId = id ? "".concat(id, "-region") : undefined;
return /*#__PURE__*/React.createElement("div", _extends({
className: cls,
style: style,
id: id
}, others), /*#__PURE__*/React.createElement("div", {
id: headingId,
className: "".concat(prefix, "collapse-panel-title"),
onClick: onClick,
onKeyDown: this.onKeyDown,
tabIndex: "0",
"aria-disabled": disabled,
"aria-expanded": isExpanded,
"aria-controls": regionId,
role: "button"
}, /*#__PURE__*/React.createElement(Icon, {
type: "triangle-up-s",
className: iconCls,
"aria-hidden": "true"
}), this.renderTitleIcon(), /*#__PURE__*/React.createElement("span", {
className: "".concat(prefix, "collapse-panel-title-text")
}, title)), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefix, "collapse-panel-content"),
role: "region",
id: regionId
}, children));
}
}]);
}(React.Component);
_defineProperty(Panel, "propTypes", {
/**
* 样式类名的品牌前缀
*/
prefix: PropTypes.string,
/**
* 子组件接受行内样式
*/
style: PropTypes.object,
children: PropTypes.any,
isExpanded: PropTypes.bool,
/**
* 是否禁止用户操作
*/
disabled: PropTypes.bool,
/**
* 标题
*/
title: PropTypes.node,
/**
* 标题前的icon
*/
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* 扩展class
*/
className: PropTypes.string,
onClick: PropTypes.func,
id: PropTypes.string
});
_defineProperty(Panel, "defaultProps", {
prefix: 'next-',
isExpanded: false,
onClick: func.noop
});
_defineProperty(Panel, "isNextPanel", true);
export default ConfigProvider.config(Panel);