IconBase.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _utils = require("../utils");
  7. var _vue = require("vue");
  8. var _excluded = ["icon", "primaryColor", "secondaryColor"];
  9. 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; }
  10. 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; }
  11. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  12. 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; }
  13. var twoToneColorPalette = (0, _vue.reactive)({
  14. primaryColor: '#333',
  15. secondaryColor: '#E6E6E6',
  16. calculated: false
  17. });
  18. function setTwoToneColors(_ref) {
  19. var primaryColor = _ref.primaryColor,
  20. secondaryColor = _ref.secondaryColor;
  21. twoToneColorPalette.primaryColor = primaryColor;
  22. twoToneColorPalette.secondaryColor = secondaryColor || (0, _utils.getSecondaryColor)(primaryColor);
  23. twoToneColorPalette.calculated = !!secondaryColor;
  24. }
  25. function getTwoToneColors() {
  26. return _objectSpread({}, twoToneColorPalette);
  27. }
  28. var IconBase = function IconBase(props, context) {
  29. var _props$context$attrs = _objectSpread({}, props, context.attrs),
  30. icon = _props$context$attrs.icon,
  31. primaryColor = _props$context$attrs.primaryColor,
  32. secondaryColor = _props$context$attrs.secondaryColor,
  33. restProps = _objectWithoutProperties(_props$context$attrs, _excluded);
  34. var colors = twoToneColorPalette;
  35. if (primaryColor) {
  36. colors = {
  37. primaryColor: primaryColor,
  38. secondaryColor: secondaryColor || (0, _utils.getSecondaryColor)(primaryColor)
  39. };
  40. }
  41. (0, _utils.warning)((0, _utils.isIconDefinition)(icon), "icon should be icon definiton, but got ".concat(icon));
  42. if (!(0, _utils.isIconDefinition)(icon)) {
  43. return null;
  44. }
  45. var target = icon;
  46. if (target && typeof target.icon === 'function') {
  47. target = _objectSpread({}, target, {
  48. icon: target.icon(colors.primaryColor, colors.secondaryColor)
  49. });
  50. }
  51. return (0, _utils.generate)(target.icon, "svg-".concat(target.name), _objectSpread({}, restProps, {
  52. 'data-icon': target.name,
  53. width: '1em',
  54. height: '1em',
  55. fill: 'currentColor',
  56. 'aria-hidden': 'true'
  57. })); // },
  58. };
  59. IconBase.props = {
  60. icon: Object,
  61. primaryColor: String,
  62. secondaryColor: String,
  63. focusable: String
  64. };
  65. IconBase.inheritAttrs = false;
  66. IconBase.displayName = 'IconBase';
  67. IconBase.getTwoToneColors = getTwoToneColors;
  68. IconBase.setTwoToneColors = setTwoToneColors;
  69. var _default = IconBase;
  70. exports["default"] = _default;