index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../skeleton-avatar/index': {
  6. type: 'descendant',
  7. observer() {
  8. this.debounce(this.updated)
  9. },
  10. },
  11. '../skeleton-paragraph/index': {
  12. type: 'descendant',
  13. observer() {
  14. this.debounce(this.updated)
  15. },
  16. },
  17. },
  18. properties: {
  19. prefixCls: {
  20. type: String,
  21. value: 'wux-skeleton',
  22. },
  23. active: {
  24. type: Boolean,
  25. value: false,
  26. observer: 'updated',
  27. },
  28. },
  29. computed: {
  30. classes: ['prefixCls, active', function(prefixCls, active) {
  31. const wrap = classNames(prefixCls, {
  32. [`${prefixCls}--active`]: active,
  33. })
  34. return {
  35. wrap,
  36. }
  37. }],
  38. },
  39. methods: {
  40. updated(active = this.data.active) {
  41. const avatar = this.getRelationNodes('../skeleton-avatar/index')
  42. const paragraph = this.getRelationNodes('../skeleton-paragraph/index')
  43. if (avatar.length > 0) {
  44. avatar.forEach((element) => {
  45. element.updated(active)
  46. })
  47. }
  48. if (paragraph.length > 0) {
  49. paragraph.forEach((element) => {
  50. element.updated(active)
  51. })
  52. }
  53. },
  54. },
  55. })