IconBase.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var _excluded = ["icon", "primaryColor", "secondaryColor"];
  2. 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; }
  3. 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; }
  4. 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; }
  5. 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; }
  6. import { generate, getSecondaryColor, isIconDefinition, warning } from '../utils';
  7. import { reactive } from 'vue';
  8. var twoToneColorPalette = reactive({
  9. primaryColor: '#333',
  10. secondaryColor: '#E6E6E6',
  11. calculated: false
  12. });
  13. function setTwoToneColors(_ref) {
  14. var primaryColor = _ref.primaryColor,
  15. secondaryColor = _ref.secondaryColor;
  16. twoToneColorPalette.primaryColor = primaryColor;
  17. twoToneColorPalette.secondaryColor = secondaryColor || getSecondaryColor(primaryColor);
  18. twoToneColorPalette.calculated = !!secondaryColor;
  19. }
  20. function getTwoToneColors() {
  21. return _objectSpread({}, twoToneColorPalette);
  22. }
  23. var IconBase = function IconBase(props, context) {
  24. var _props$context$attrs = _objectSpread({}, props, context.attrs),
  25. icon = _props$context$attrs.icon,
  26. primaryColor = _props$context$attrs.primaryColor,
  27. secondaryColor = _props$context$attrs.secondaryColor,
  28. restProps = _objectWithoutProperties(_props$context$attrs, _excluded);
  29. var colors = twoToneColorPalette;
  30. if (primaryColor) {
  31. colors = {
  32. primaryColor: primaryColor,
  33. secondaryColor: secondaryColor || getSecondaryColor(primaryColor)
  34. };
  35. }
  36. warning(isIconDefinition(icon), "icon should be icon definiton, but got ".concat(icon));
  37. if (!isIconDefinition(icon)) {
  38. return null;
  39. }
  40. var target = icon;
  41. if (target && typeof target.icon === 'function') {
  42. target = _objectSpread({}, target, {
  43. icon: target.icon(colors.primaryColor, colors.secondaryColor)
  44. });
  45. }
  46. return generate(target.icon, "svg-".concat(target.name), _objectSpread({}, restProps, {
  47. 'data-icon': target.name,
  48. width: '1em',
  49. height: '1em',
  50. fill: 'currentColor',
  51. 'aria-hidden': 'true'
  52. })); // },
  53. };
  54. IconBase.props = {
  55. icon: Object,
  56. primaryColor: String,
  57. secondaryColor: String,
  58. focusable: String
  59. };
  60. IconBase.inheritAttrs = false;
  61. IconBase.displayName = 'IconBase';
  62. IconBase.getTwoToneColors = getTwoToneColors;
  63. IconBase.setTwoToneColors = setTwoToneColors;
  64. export default IconBase;