You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
5.2 KiB

3 months ago
  1. import { defineComponent, useSlots, computed, openBlock, createBlock, resolveDynamicComponent, unref, normalizeClass, withCtx, createElementVNode, withDirectives, createElementBlock, isRef, withModifiers, vModelCheckbox, renderSlot, Fragment, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
  2. import { checkboxProps, checkboxEmits } from './checkbox.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 ns = useNamespace("checkbox");
  30. const compKls = computed(() => {
  31. return [
  32. ns.b(),
  33. ns.m(checkboxSize.value),
  34. ns.is("disabled", isDisabled.value),
  35. ns.is("bordered", props.border),
  36. ns.is("checked", isChecked.value)
  37. ];
  38. });
  39. const spanKls = computed(() => {
  40. return [
  41. ns.e("input"),
  42. ns.is("disabled", isDisabled.value),
  43. ns.is("checked", isChecked.value),
  44. ns.is("indeterminate", props.indeterminate),
  45. ns.is("focus", isFocused.value)
  46. ];
  47. });
  48. return (_ctx, _cache) => {
  49. return openBlock(), createBlock(resolveDynamicComponent(!unref(hasOwnLabel) && unref(isLabeledByFormItem) ? "span" : "label"), {
  50. class: normalizeClass(unref(compKls)),
  51. "aria-controls": _ctx.indeterminate ? _ctx.ariaControls : null,
  52. onClick: unref(onClickRoot)
  53. }, {
  54. default: withCtx(() => {
  55. var _a, _b, _c, _d;
  56. return [
  57. createElementVNode("span", {
  58. class: normalizeClass(unref(spanKls))
  59. }, [
  60. _ctx.trueValue || _ctx.falseValue || _ctx.trueLabel || _ctx.falseLabel ? withDirectives((openBlock(), createElementBlock("input", {
  61. key: 0,
  62. id: unref(inputId),
  63. "onUpdate:modelValue": ($event) => isRef(model) ? model.value = $event : null,
  64. class: normalizeClass(unref(ns).e("original")),
  65. type: "checkbox",
  66. indeterminate: _ctx.indeterminate,
  67. name: _ctx.name,
  68. tabindex: _ctx.tabindex,
  69. disabled: unref(isDisabled),
  70. "true-value": (_b = (_a = _ctx.trueValue) != null ? _a : _ctx.trueLabel) != null ? _b : true,
  71. "false-value": (_d = (_c = _ctx.falseValue) != null ? _c : _ctx.falseLabel) != null ? _d : false,
  72. onChange: unref(handleChange),
  73. onFocus: ($event) => isFocused.value = true,
  74. onBlur: ($event) => isFocused.value = false,
  75. onClick: withModifiers(() => {
  76. }, ["stop"])
  77. }, null, 42, ["id", "onUpdate:modelValue", "indeterminate", "name", "tabindex", "disabled", "true-value", "false-value", "onChange", "onFocus", "onBlur", "onClick"])), [
  78. [vModelCheckbox, unref(model)]
  79. ]) : withDirectives((openBlock(), createElementBlock("input", {
  80. key: 1,
  81. id: unref(inputId),
  82. "onUpdate:modelValue": ($event) => isRef(model) ? model.value = $event : null,
  83. class: normalizeClass(unref(ns).e("original")),
  84. type: "checkbox",
  85. indeterminate: _ctx.indeterminate,
  86. disabled: unref(isDisabled),
  87. value: unref(actualValue),
  88. name: _ctx.name,
  89. tabindex: _ctx.tabindex,
  90. onChange: unref(handleChange),
  91. onFocus: ($event) => isFocused.value = true,
  92. onBlur: ($event) => isFocused.value = false,
  93. onClick: withModifiers(() => {
  94. }, ["stop"])
  95. }, null, 42, ["id", "onUpdate:modelValue", "indeterminate", "disabled", "value", "name", "tabindex", "onChange", "onFocus", "onBlur", "onClick"])), [
  96. [vModelCheckbox, unref(model)]
  97. ]),
  98. createElementVNode("span", {
  99. class: normalizeClass(unref(ns).e("inner"))
  100. }, null, 2)
  101. ], 2),
  102. unref(hasOwnLabel) ? (openBlock(), createElementBlock("span", {
  103. key: 0,
  104. class: normalizeClass(unref(ns).e("label"))
  105. }, [
  106. renderSlot(_ctx.$slots, "default"),
  107. !_ctx.$slots.default ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
  108. createTextVNode(toDisplayString(_ctx.label), 1)
  109. ], 64)) : createCommentVNode("v-if", true)
  110. ], 2)) : createCommentVNode("v-if", true)
  111. ];
  112. }),
  113. _: 3
  114. }, 8, ["class", "aria-controls", "onClick"]);
  115. };
  116. }
  117. });
  118. var Checkbox = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "checkbox.vue"]]);
  119. export { Checkbox as default };
  120. //# sourceMappingURL=checkbox2.mjs.map