checkbox2.mjs 5.4 KB

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