a6fdeeeac4874a83e2ba12db146a0fe88074225054e1dcd2d0a1cdd20b7538f4826d573b75eb9d14b5a0d4c2e692490c485c95f6926e43e0fa8cffa8dbf3ae 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { defineComponent, useSlots, computed, openBlock, createBlock, resolveDynamicComponent, unref, normalizeClass, withCtx, createElementVNode, withDirectives, mergeProps, isRef, withModifiers, vModelCheckbox, createElementBlock, renderSlot, Fragment, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
  2. import { checkboxProps, checkboxEmits } from './checkbox2.mjs';
  3. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  4. import { useCheckbox } from './composables/use-checkbox.mjs';
  5. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  6. const __default__ = defineComponent({
  7. name: "ElCheckbox"
  8. });
  9. const _sfc_main = /* @__PURE__ */ defineComponent({
  10. ...__default__,
  11. props: checkboxProps,
  12. emits: checkboxEmits,
  13. setup(__props) {
  14. const props = __props;
  15. const slots = useSlots();
  16. const {
  17. inputId,
  18. isLabeledByFormItem,
  19. isChecked,
  20. isDisabled,
  21. isFocused,
  22. checkboxSize,
  23. hasOwnLabel,
  24. model,
  25. actualValue,
  26. handleChange,
  27. onClickRoot
  28. } = useCheckbox(props, slots);
  29. const inputBindings = computed(() => {
  30. var _a, _b, _c, _d;
  31. if (props.trueValue || props.falseValue || props.trueLabel || props.falseLabel) {
  32. return {
  33. "true-value": (_b = (_a = props.trueValue) != null ? _a : props.trueLabel) != null ? _b : true,
  34. "false-value": (_d = (_c = props.falseValue) != null ? _c : props.falseLabel) != null ? _d : false
  35. };
  36. }
  37. return {
  38. value: actualValue.value
  39. };
  40. });
  41. const ns = useNamespace("checkbox");
  42. const compKls = computed(() => {
  43. return [
  44. ns.b(),
  45. ns.m(checkboxSize.value),
  46. ns.is("disabled", isDisabled.value),
  47. ns.is("bordered", props.border),
  48. ns.is("checked", isChecked.value)
  49. ];
  50. });
  51. const spanKls = computed(() => {
  52. return [
  53. ns.e("input"),
  54. ns.is("disabled", isDisabled.value),
  55. ns.is("checked", isChecked.value),
  56. ns.is("indeterminate", props.indeterminate),
  57. ns.is("focus", isFocused.value)
  58. ];
  59. });
  60. return (_ctx, _cache) => {
  61. return openBlock(), createBlock(resolveDynamicComponent(!unref(hasOwnLabel) && unref(isLabeledByFormItem) ? "span" : "label"), {
  62. class: normalizeClass(unref(compKls)),
  63. "aria-controls": _ctx.indeterminate ? _ctx.ariaControls : null,
  64. onClick: unref(onClickRoot)
  65. }, {
  66. default: withCtx(() => [
  67. createElementVNode("span", {
  68. class: normalizeClass(unref(spanKls))
  69. }, [
  70. withDirectives(createElementVNode("input", mergeProps({
  71. id: unref(inputId),
  72. "onUpdate:modelValue": ($event) => isRef(model) ? model.value = $event : null,
  73. class: unref(ns).e("original"),
  74. type: "checkbox",
  75. indeterminate: _ctx.indeterminate,
  76. name: _ctx.name,
  77. tabindex: _ctx.tabindex,
  78. disabled: unref(isDisabled)
  79. }, unref(inputBindings), {
  80. onChange: unref(handleChange),
  81. onFocus: ($event) => isFocused.value = true,
  82. onBlur: ($event) => isFocused.value = false,
  83. onClick: withModifiers(() => {
  84. }, ["stop"])
  85. }), null, 16, ["id", "onUpdate:modelValue", "indeterminate", "name", "tabindex", "disabled", "onChange", "onFocus", "onBlur", "onClick"]), [
  86. [vModelCheckbox, unref(model)]
  87. ]),
  88. createElementVNode("span", {
  89. class: normalizeClass(unref(ns).e("inner"))
  90. }, null, 2)
  91. ], 2),
  92. unref(hasOwnLabel) ? (openBlock(), createElementBlock("span", {
  93. key: 0,
  94. class: normalizeClass(unref(ns).e("label"))
  95. }, [
  96. renderSlot(_ctx.$slots, "default"),
  97. !_ctx.$slots.default ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
  98. createTextVNode(toDisplayString(_ctx.label), 1)
  99. ], 64)) : createCommentVNode("v-if", true)
  100. ], 2)) : createCommentVNode("v-if", true)
  101. ]),
  102. _: 3
  103. }, 8, ["class", "aria-controls", "onClick"]);
  104. };
  105. }
  106. });
  107. var Checkbox = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "checkbox.vue"]]);
  108. export { Checkbox as default };
  109. //# sourceMappingURL=checkbox.mjs.map