index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var color_1 = require("../common/color");
  5. component_1.VantComponent({
  6. field: true,
  7. classes: ['node-class'],
  8. props: {
  9. checked: {
  10. type: null,
  11. observer: function (value) {
  12. var loadingColor = this.getLoadingColor(value);
  13. this.setData({ value: value, loadingColor: loadingColor });
  14. }
  15. },
  16. loading: Boolean,
  17. disabled: Boolean,
  18. activeColor: String,
  19. inactiveColor: String,
  20. size: {
  21. type: String,
  22. value: '30px'
  23. },
  24. activeValue: {
  25. type: null,
  26. value: true
  27. },
  28. inactiveValue: {
  29. type: null,
  30. value: false
  31. }
  32. },
  33. created: function () {
  34. var value = this.data.checked;
  35. var loadingColor = this.getLoadingColor(value);
  36. this.setData({ value: value, loadingColor: loadingColor });
  37. },
  38. methods: {
  39. getLoadingColor: function (checked) {
  40. var _a = this.data, activeColor = _a.activeColor, inactiveColor = _a.inactiveColor;
  41. return checked ? activeColor || color_1.BLUE : inactiveColor || color_1.GRAY_DARK;
  42. },
  43. onClick: function () {
  44. var _a = this.data, activeValue = _a.activeValue, inactiveValue = _a.inactiveValue;
  45. if (!this.data.disabled && !this.data.loading) {
  46. var checked = this.data.checked === activeValue;
  47. var value = checked ? inactiveValue : activeValue;
  48. this.$emit('input', value);
  49. this.$emit('change', value);
  50. }
  51. }
  52. }
  53. });