Checkbox.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { i as E, d as o, c as V, _ as W, P as F } from "./index2.js";
  2. import { defineComponent as I, ref as f, watch as M, createVNode as h } from "vue";
  3. var R = function(t, l) {
  4. var c = {};
  5. for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && l.indexOf(n) < 0 && (c[n] = t[n]);
  6. if (t != null && typeof Object.getOwnPropertySymbols == "function") for (var a = 0, n = Object.getOwnPropertySymbols(t); a < n.length; a++)
  7. l.indexOf(n[a]) < 0 && Object.prototype.propertyIsEnumerable.call(t, n[a]) && (c[n[a]] = t[n[a]]);
  8. return c;
  9. };
  10. const T = {
  11. prefixCls: String,
  12. name: String,
  13. id: String,
  14. type: String,
  15. defaultChecked: {
  16. type: [Boolean, Number],
  17. default: void 0
  18. },
  19. checked: {
  20. type: [Boolean, Number],
  21. default: void 0
  22. },
  23. disabled: Boolean,
  24. tabindex: {
  25. type: [Number, String]
  26. },
  27. readonly: Boolean,
  28. autofocus: Boolean,
  29. value: F.any,
  30. required: Boolean
  31. }, H = I({
  32. compatConfig: {
  33. MODE: 3
  34. },
  35. name: "Checkbox",
  36. inheritAttrs: !1,
  37. props: E(T, {
  38. prefixCls: "rc-checkbox",
  39. type: "checkbox",
  40. defaultChecked: !1
  41. }),
  42. emits: ["click", "change"],
  43. setup(t, l) {
  44. let {
  45. attrs: c,
  46. emit: n,
  47. expose: a
  48. } = l;
  49. const d = f(t.checked === void 0 ? t.defaultChecked : t.checked), i = f();
  50. M(() => t.checked, () => {
  51. d.value = t.checked;
  52. }), a({
  53. focus() {
  54. var e;
  55. (e = i.value) === null || e === void 0 || e.focus();
  56. },
  57. blur() {
  58. var e;
  59. (e = i.value) === null || e === void 0 || e.blur();
  60. }
  61. });
  62. const s = f(), y = (e) => {
  63. if (t.disabled)
  64. return;
  65. t.checked === void 0 && (d.value = e.target.checked), e.shiftKey = s.value;
  66. const u = {
  67. target: o(o({}, t), {
  68. checked: e.target.checked
  69. }),
  70. stopPropagation() {
  71. e.stopPropagation();
  72. },
  73. preventDefault() {
  74. e.preventDefault();
  75. },
  76. nativeEvent: e
  77. };
  78. t.checked !== void 0 && (i.value.checked = !!t.checked), n("change", u), s.value = !1;
  79. }, k = (e) => {
  80. n("click", e), s.value = e.shiftKey;
  81. };
  82. return () => {
  83. const {
  84. prefixCls: e,
  85. name: u,
  86. id: g,
  87. type: m,
  88. disabled: b,
  89. readonly: x,
  90. tabindex: C,
  91. autofocus: O,
  92. value: P,
  93. required: S
  94. } = t, _ = R(t, ["prefixCls", "name", "id", "type", "disabled", "readonly", "tabindex", "autofocus", "value", "required"]), {
  95. class: j,
  96. onFocus: B,
  97. onBlur: K,
  98. onKeydown: N,
  99. onKeypress: w,
  100. onKeyup: D
  101. } = c, v = o(o({}, _), c), $ = Object.keys(v).reduce((p, r) => ((r.startsWith("data-") || r.startsWith("aria-") || r === "role") && (p[r] = v[r]), p), {}), q = V(e, j, {
  102. [`${e}-checked`]: d.value,
  103. [`${e}-disabled`]: b
  104. }), A = o(o({
  105. name: u,
  106. id: g,
  107. type: m,
  108. readonly: x,
  109. disabled: b,
  110. tabindex: C,
  111. class: `${e}-input`,
  112. checked: !!d.value,
  113. autofocus: O,
  114. value: P
  115. }, $), {
  116. onChange: y,
  117. onClick: k,
  118. onFocus: B,
  119. onBlur: K,
  120. onKeydown: N,
  121. onKeypress: w,
  122. onKeyup: D,
  123. required: S
  124. });
  125. return h("span", {
  126. class: q
  127. }, [h("input", W({
  128. ref: i
  129. }, A), null), h("span", {
  130. class: `${e}-inner`
  131. }, null)]);
  132. };
  133. }
  134. });
  135. export {
  136. H as V
  137. };