tntd
Version:
tntd是基于 TNT Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。
239 lines (237 loc) • 8.39 kB
JavaScript
;
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);
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var React = _interopRequireWildcard(require("react"));
var _utils = require("./utils");
function _getRequireWildcardCache(e) {
if ("function" != typeof WeakMap) return null;
var r = new WeakMap(),
t = new WeakMap();
return (_getRequireWildcardCache = function _getRequireWildcardCache(e) {
return e ? t : r;
})(e);
}
function _interopRequireWildcard(e, r) {
if (!r && e && e.__esModule) return e;
if (null === e || "object" != _typeof(e) && "function" != typeof e) return {
"default": e
};
var t = _getRequireWildcardCache(r);
if (t && t.has(e)) return t.get(e);
var n = {
__proto__: null
},
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
}
return n["default"] = e, t && t.set(e, n), n;
}
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 _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 _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);
}
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);
}
var __rest = void 0 && (void 0).__rest || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var twoToneColorPalette = {
primaryColor: '#333',
secondaryColor: '#E6E6E6'
};
var Icon = /*#__PURE__*/function (_React$Component) {
function Icon() {
_classCallCheck(this, Icon);
return _callSuper(this, Icon, arguments);
}
_inherits(Icon, _React$Component);
return _createClass(Icon, [{
key: "render",
value: function render() {
var _a = this.props,
type = _a.type,
className = _a.className,
onClick = _a.onClick,
style = _a.style,
primaryColor = _a.primaryColor,
secondaryColor = _a.secondaryColor,
rest = __rest(_a, ["type", "className", "onClick", "style", "primaryColor", "secondaryColor"]);
var target;
var colors = twoToneColorPalette;
if (primaryColor) {
colors = {
primaryColor: primaryColor,
secondaryColor: secondaryColor || (0, _utils.getSecondaryColor)(primaryColor)
};
}
if ((0, _utils.isIconDefinition)(type)) {
target = type;
} else if (typeof type === 'string') {
target = Icon.get(type, colors);
if (!target) {
// log(`Could not find icon: ${type}`);
return null;
}
}
if (!target) {
(0, _utils.log)("type should be string or icon definiton, but got ".concat(type));
return null;
}
if (target && typeof target.icon === 'function') {
target = Object.assign(Object.assign({}, target), {
icon: target.icon(colors.primaryColor, colors.secondaryColor)
});
}
return (0, _utils.generate)(target.icon, "svg-".concat(target.name), Object.assign(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
className: className,
onClick: onClick,
style: style
}, 'data-icon', target.name), "width", '1em'), "height", '1em'), "fill", 'currentColor'), 'aria-hidden', 'true'), rest));
}
}], [{
key: "add",
value: function add() {
var _this = this;
for (var _len = arguments.length, icons = new Array(_len), _key = 0; _key < _len; _key++) {
icons[_key] = arguments[_key];
}
icons.forEach(function (icon) {
_this.definitions.set((0, _utils.withSuffix)(icon.name, icon.theme), icon);
});
}
}, {
key: "clear",
value: function clear() {
this.definitions.clear();
}
}, {
key: "get",
value: function get(key) {
var colors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : twoToneColorPalette;
if (key) {
var target = this.definitions.get(key);
if (target && typeof target.icon === 'function') {
target = Object.assign(Object.assign({}, target), {
icon: target.icon(colors.primaryColor, colors.secondaryColor)
});
}
return target;
}
}
}, {
key: "setTwoToneColors",
value: function setTwoToneColors(_ref) {
var primaryColor = _ref.primaryColor,
secondaryColor = _ref.secondaryColor;
twoToneColorPalette.primaryColor = primaryColor;
twoToneColorPalette.secondaryColor = secondaryColor || (0, _utils.getSecondaryColor)(primaryColor);
}
}, {
key: "getTwoToneColors",
value: function getTwoToneColors() {
return Object.assign({}, twoToneColorPalette);
}
}]);
}(React.Component);
Object.defineProperty(Icon, "displayName", {
enumerable: true,
configurable: true,
writable: true,
value: 'IconReact'
});
Object.defineProperty(Icon, "definitions", {
enumerable: true,
configurable: true,
writable: true,
value: new _utils.MiniMap()
});
var _default = exports["default"] = Icon;