icon.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. 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;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import { styles, addUnit } from '../common/utils';
  11. const { prefix } = config;
  12. const name = `${prefix}-icon`;
  13. let Icon = class Icon extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [`${prefix}-class`];
  17. this.properties = props;
  18. this.data = {
  19. componentPrefix: prefix,
  20. classPrefix: name,
  21. isImage: false,
  22. iconStyle: undefined,
  23. };
  24. this.observers = {
  25. 'name, color, size, customStyle'() {
  26. this.setIconStyle();
  27. },
  28. };
  29. this.methods = {
  30. onTap(event) {
  31. this.triggerEvent('click', event.detail);
  32. },
  33. setIconStyle() {
  34. const { name, color, size, customStyle } = this.properties;
  35. const isImage = name.indexOf('/') !== -1;
  36. const sizeValue = addUnit(size);
  37. const sizeStyle = isImage ? { width: sizeValue, height: sizeValue } : {};
  38. const colorStyle = color ? { color: color } : {};
  39. const fontStyle = size ? { 'font-size': sizeValue } : {};
  40. this.setData({
  41. isImage,
  42. iconStyle: styles(Object.assign(Object.assign(Object.assign({}, colorStyle), fontStyle), sizeStyle)) + customStyle,
  43. });
  44. },
  45. };
  46. }
  47. };
  48. Icon = __decorate([
  49. wxComponent()
  50. ], Icon);
  51. export default Icon;