checkbox.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.CheckboxMixin = void 0;
  5. var _icon = _interopRequireDefault(require("../icon"));
  6. var _findParent = require("./find-parent");
  7. /**
  8. * Common part of Checkbox & Radio
  9. */
  10. var CheckboxMixin = function CheckboxMixin(parent, bem) {
  11. return {
  12. mixins: [_findParent.FindParentMixin],
  13. props: {
  14. name: null,
  15. value: null,
  16. disabled: Boolean,
  17. checkedColor: String,
  18. labelPosition: String,
  19. labelDisabled: Boolean,
  20. shape: {
  21. type: String,
  22. "default": 'round'
  23. }
  24. },
  25. created: function created() {
  26. this.findParent(parent);
  27. },
  28. computed: {
  29. isDisabled: function isDisabled() {
  30. return this.parent && this.parent.disabled || this.disabled;
  31. },
  32. iconStyle: function iconStyle() {
  33. var checkedColor = this.checkedColor;
  34. if (checkedColor && this.checked && !this.isDisabled) {
  35. return {
  36. borderColor: checkedColor,
  37. backgroundColor: checkedColor
  38. };
  39. }
  40. }
  41. },
  42. render: function render(h) {
  43. var _this = this;
  44. var slots = this.slots,
  45. checked = this.checked;
  46. var CheckIcon = slots('icon', {
  47. checked: checked
  48. }) || h(_icon["default"], {
  49. "attrs": {
  50. "name": "success"
  51. },
  52. "style": this.iconStyle
  53. });
  54. var Label = slots() && h("span", {
  55. "class": bem('label', [this.labelPosition, {
  56. disabled: this.isDisabled
  57. }]),
  58. "on": {
  59. "click": this.onClickLabel
  60. }
  61. }, [slots()]);
  62. return h("div", {
  63. "class": bem(),
  64. "on": {
  65. "click": function click(event) {
  66. _this.$emit('click', event);
  67. }
  68. }
  69. }, [h("div", {
  70. "class": bem('icon', [this.shape, {
  71. disabled: this.isDisabled,
  72. checked: checked
  73. }]),
  74. "on": {
  75. "click": this.onClickIcon
  76. }
  77. }, [CheckIcon]), Label]);
  78. }
  79. };
  80. };
  81. exports.CheckboxMixin = CheckboxMixin;