UNPKG

antd-omi-icons

Version:
115 lines (114 loc) 5.39 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __rest = (this && this.__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; }; Object.defineProperty(exports, "__esModule", { value: true }); var omi_1 = require("omi"); var omi_tools_1 = require("omi-tools"); var utils_1 = require("../utils"); var twoToneColorPalette = { primaryColor: '#333', secondaryColor: '#E6E6E6', calculated: false, }; function setTwoToneColors(_a) { var primaryColor = _a.primaryColor, secondaryColor = _a.secondaryColor; twoToneColorPalette.primaryColor = primaryColor; twoToneColorPalette.secondaryColor = secondaryColor || (0, utils_1.getSecondaryColor)(primaryColor); twoToneColorPalette.calculated = !!secondaryColor; } function getTwoToneColors() { return __assign({}, twoToneColorPalette); } var IconBase = /** @class */ (function (_super) { __extends(IconBase, _super); function IconBase() { return _super !== null && _super.apply(this, arguments) || this; } IconBase.prototype.render = function (props) { var _a; var icon = props.icon, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, spin = props.spin, rotate = props.rotate, restProps = __rest(props, ["icon", "primaryColor", "secondaryColor", "spin", "rotate"]); var classObj = (0, omi_1.extractClass)(props, (_a = { anticon: true }, _a["anticon-".concat(icon.name)] = Boolean(icon.name), _a['anticon-spin'] = spin === '' || !!spin || icon.name === 'loading', _a)); var svgStyle = rotate && !isNaN(parseFloat(String(rotate))) ? "-ms-transform: rotate(".concat(rotate, "deg);transform: rotate(").concat(rotate, "deg);") : undefined; var styleObj = svgStyle ? { style: svgStyle } : {}; var colors = twoToneColorPalette; if (primaryColor) { colors = { primaryColor: primaryColor, secondaryColor: secondaryColor || (0, utils_1.getSecondaryColor)(primaryColor), }; } (0, utils_1.warning)((0, utils_1.isIconDefinition)(icon), "icon should be icon definiton, but got ".concat(icon)); if (!(0, utils_1.isIconDefinition)(icon)) { return null; } var target = icon; if (target && typeof target.icon === 'function') { target = __assign(__assign({}, target), { icon: target.icon(colors.primaryColor, colors.secondaryColor) }); } return (0, utils_1.generate)(target.icon, "svg-".concat(target.name), __assign(__assign(__assign(__assign({}, (0, omi_tools_1.rmIEFP)(restProps)), classObj), styleObj), { 'data-icon': target.name, width: '1em', height: '1em', fill: 'currentColor', 'aria-hidden': 'true' })); }; ; IconBase.propTypes = { primaryColor: String, secondaryColor: String, focusable: String }; IconBase.inheritAttrs = false; IconBase.displayName = 'IconBase'; IconBase.css = utils_1.iconStyles; IconBase.getTwoToneColors = getTwoToneColors; IconBase.setTwoToneColors = setTwoToneColors; IconBase = __decorate([ (0, omi_1.tag)('o-icon-base') ], IconBase); return IconBase; }(omi_1.Component)); exports.default = IconBase;