avatar-group.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 avatarGroupProps from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-avatar-group`;
  12. let AvatarGroup = class AvatarGroup extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = [`${prefix}-class`, `${prefix}-class-content`, `${prefix}-class-image`];
  16. this.properties = avatarGroupProps;
  17. this.data = {
  18. prefix,
  19. classPrefix: name,
  20. hasChild: true,
  21. length: 0,
  22. className: '',
  23. };
  24. this.options = {
  25. multipleSlots: true,
  26. };
  27. this.relations = {
  28. '../avatar/avatar': {
  29. type: 'descendant',
  30. },
  31. };
  32. this.lifetimes = {
  33. attached() {
  34. this.setClass();
  35. },
  36. ready() {
  37. this.setData({
  38. length: this.$children.length,
  39. });
  40. this.handleMax();
  41. },
  42. };
  43. this.observers = {
  44. 'cascading, size'() {
  45. this.setClass();
  46. },
  47. };
  48. this.methods = {
  49. setClass() {
  50. const { cascading, size } = this.properties;
  51. const direction = cascading.split('-')[0];
  52. const classList = [
  53. name,
  54. `${prefix}-class`,
  55. `${name}-offset-${direction}`,
  56. `${name}-offset-${direction}-${size.indexOf('px') > -1 ? 'medium' : size || 'medium'}`,
  57. ];
  58. this.setData({
  59. className: classList.join(' '),
  60. });
  61. },
  62. handleMax() {
  63. const { max } = this.data;
  64. const len = this.$children.length;
  65. if (!max || max > len)
  66. return;
  67. const restAvatars = this.$children.splice(max, len - max);
  68. restAvatars.forEach((child) => {
  69. child.hide();
  70. });
  71. },
  72. onCollapsedItemClick(e) {
  73. this.triggerEvent('collapsed-item-click', e.detail);
  74. },
  75. };
  76. }
  77. };
  78. AvatarGroup = __decorate([
  79. wxComponent()
  80. ], AvatarGroup);
  81. export default AvatarGroup;