polestar-icons
Version:
Polestar UI Icons
250 lines (182 loc) • 11.7 kB
JavaScript
"use strict";
require("core-js/modules/es.symbol");
require("core-js/modules/es.symbol.description");
require("core-js/modules/es.symbol.iterator");
require("core-js/modules/es.array.concat");
require("core-js/modules/es.array.index-of");
require("core-js/modules/es.array.iterator");
require("core-js/modules/es.function.name");
require("core-js/modules/es.object.assign");
require("core-js/modules/es.object.get-prototype-of");
require("core-js/modules/es.object.keys");
require("core-js/modules/es.object.set-prototype-of");
require("core-js/modules/es.object.to-string");
require("core-js/modules/es.string.iterator");
require("core-js/modules/web.dom-collections.iterator");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _AsyncSvg = _interopRequireDefault(require("./AsyncSvg"));
require("./css/polestar.css");
require("./css/sprite.css");
require("./css/animate.css");
require("./css/size.css");
require("./css/stacked.css");
require("./css/svg.css");
require("./Example/styles/style.css");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var Icon = function (_React$Component) {
_inherits(Icon, _React$Component);
function Icon() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, Icon);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Icon)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "getIcon", function (name, className, size, color, hidden, style, animation, animationType, animationDuration, type, onClick, isStack, stackRatio) {
var prefix = "ps-".concat(type, "-icon");
var stackRatioClass = isStack ? "icon-stack-".concat(stackRatio, "x") : '';
var iconSize;
if (typeof size !== 'undefined') {
if (typeof size === 'number') {
iconSize = "icon-".concat(size, "x");
} else if (typeof size === 'string') {
iconSize = "icon-".concat(size);
}
}
var animationClassName = _this.getAnimationClassName(animation, animationType);
var iconClassName = "polestar-icon ".concat(prefix, "-").concat(name, " ").concat(iconSize, " ").concat(className || '', " ").concat(stackRatioClass, " ").concat(animationClassName);
var iconStyle = _extends({}, style, {
color: color,
visibility: hidden ? 'hidden' : 'visible'
});
if (animationType === 'duration') {
setTimeout(function () {
_this.icon.classList.toggle('animated');
_this.icon.classList.toggle("ps-".concat(animation));
}, animationDuration * 1000);
}
return _react.default.createElement("i", {
ref: function ref(_ref) {
_this.icon = _ref;
},
className: iconClassName,
role: "presentation",
style: iconStyle,
onClick: onClick
});
});
_defineProperty(_assertThisInitialized(_this), "getAnimationClassName", function (animation, animationType) {
if (animationType === 'hover') {
return "ps-".concat(animation, " animated-hover");
}
if (animationType === 'parent-hover') {
return "ps-".concat(animation);
}
if (!animation) {
return '';
}
return "ps-".concat(animation, " animated");
});
return _this;
}
_createClass(Icon, [{
key: "render",
value: function render() {
var _this$props = this.props,
name = _this$props.name,
type = _this$props.type,
size = _this$props.size,
color = _this$props.color,
hidden = _this$props.hidden,
className = _this$props.className,
style = _this$props.style,
animation = _this$props.animation,
animationType = _this$props.animationType,
animationDuration = _this$props.animationDuration,
innerName = _this$props.innerName,
innerSize = _this$props.innerSize,
innerColor = _this$props.innerColor,
innerHidden = _this$props.innerHidden,
innerClassName = _this$props.innerClassName,
innerStyle = _this$props.innerStyle,
innerAnimation = _this$props.innerAnimation,
innerAnimationType = _this$props.innerAnimationType,
innerAnimationDuration = _this$props.innerAnimationDuration,
stackRatio = _this$props.stackRatio,
onClick = _this$props.onClick,
rest = _objectWithoutProperties(_this$props, ["name", "type", "size", "color", "hidden", "className", "style", "animation", "animationType", "animationDuration", "innerName", "innerSize", "innerColor", "innerHidden", "innerClassName", "innerStyle", "innerAnimation", "innerAnimationType", "innerAnimationDuration", "stackRatio", "onClick"]);
if (type === 'svg') {
return _react.default.createElement(_AsyncSvg.default, _extends({
name: name,
className: (0, _classnames.default)('ps-svg-icon', className, {
'ps-svg-size': typeof size !== 'undefined' || typeof this.props.width === 'undefined' && typeof this.props.height === 'undefined'
}, _defineProperty({}, "ps-svg-size-".concat(size, "x"), typeof size === 'number'), _defineProperty({}, "ps-svg-size-".concat(size), typeof size === 'string'))
}, rest));
}
var icon = this.getIcon(name, className, size, color, hidden, style, animation, animationType, animationDuration, type, onClick, Boolean(innerName), stackRatio[0]);
if (innerName) {
var innerIcon = this.getIcon(innerName, innerClassName, innerSize || size, innerColor, innerHidden, innerStyle, innerAnimation, innerAnimationType, innerAnimationDuration, type, null, Boolean(innerName), stackRatio[1]);
return _react.default.createElement("span", {
className: "icon-stack"
}, icon, innerIcon);
}
return icon;
}
}]);
return Icon;
}(_react.default.Component);
_defineProperty(Icon, "propTypes", {
name: _propTypes.default.string.isRequired,
type: _propTypes.default.oneOf(['font', 'svg', 'image']),
size: _propTypes.default.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', 'lg']),
color: _propTypes.default.string,
className: _propTypes.default.string,
style: _propTypes.default.object,
hidden: _propTypes.default.bool,
animation: _propTypes.default.oneOf(['spin', 'spin-pulse', 'wrench', 'ring', 'vertical', 'horizontal', 'flash', 'bounce', 'float', 'pulse', 'tada', 'passing', 'passing-reverse', 'burst', 'falling', 'shake']),
animationType: _propTypes.default.oneOf(['always', 'duration', 'hover', 'parent-hover']),
animationDuration: _propTypes.default.number,
innerName: _propTypes.default.string,
innerSize: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
innerColor: _propTypes.default.string,
innerHidden: _propTypes.default.bool,
innerClassName: _propTypes.default.string,
innerStyle: _propTypes.default.object,
innerAnimation: _propTypes.default.oneOf(['spin', 'spin-pulse', 'wrench', 'ring', 'vertical', 'horizontal', 'flash', 'bounce', 'float', 'pulse', 'tada', 'passing', 'passing-reverse', 'burst', 'falling', 'shake']),
innerAnimationType: _propTypes.default.oneOf(['always', 'duration', 'hover', 'parent-hover']),
innerAnimationDuration: _propTypes.default.number,
stackRatio: _propTypes.default.array,
onClick: _propTypes.default.func
});
_defineProperty(Icon, "defaultProps", {
type: 'font',
innerSize: 1,
stackRatio: [1, 1],
animationType: 'always',
animationDuration: 15,
innerAnimationType: 'always',
innerAnimationDuration: 15,
onClick: function onClick() {}
});
var _default = Icon;
exports.default = _default;