checkbox-button.mjs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { defineComponent, useSlots, inject, computed, openBlock, createElementBlock, normalizeClass, unref, withDirectives, isRef, vModelCheckbox, normalizeStyle, renderSlot, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
  2. import '../../../hooks/index.mjs';
  3. import '../../../tokens/index.mjs';
  4. import './composables/index.mjs';
  5. import { checkboxProps, checkboxEmits } from './checkbox.mjs';
  6. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  7. import { useCheckbox } from './composables/use-checkbox.mjs';
  8. import { checkboxGroupContextKey } from '../../../tokens/checkbox.mjs';
  9. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  10. const _hoisted_1 = ["name", "tabindex", "disabled", "true-value", "false-value"];
  11. const _hoisted_2 = ["name", "tabindex", "disabled", "value"];
  12. const __default__ = defineComponent({
  13. name: "ElCheckboxButton"
  14. });
  15. const _sfc_main = /* @__PURE__ */ defineComponent({
  16. ...__default__,
  17. props: checkboxProps,
  18. emits: checkboxEmits,
  19. setup(__props) {
  20. const props = __props;
  21. const slots = useSlots();
  22. const {
  23. isFocused,
  24. isChecked,
  25. isDisabled,
  26. checkboxButtonSize,
  27. model,
  28. handleChange
  29. } = useCheckbox(props, slots);
  30. const checkboxGroup = inject(checkboxGroupContextKey, void 0);
  31. const ns = useNamespace("checkbox");
  32. const activeStyle = computed(() => {
  33. var _a, _b, _c, _d;
  34. const fillValue = (_b = (_a = checkboxGroup == null ? void 0 : checkboxGroup.fill) == null ? void 0 : _a.value) != null ? _b : "";
  35. return {
  36. backgroundColor: fillValue,
  37. borderColor: fillValue,
  38. color: (_d = (_c = checkboxGroup == null ? void 0 : checkboxGroup.textColor) == null ? void 0 : _c.value) != null ? _d : "",
  39. boxShadow: fillValue ? `-1px 0 0 0 ${fillValue}` : void 0
  40. };
  41. });
  42. const lableKls = computed(() => {
  43. return [
  44. ns.b("button"),
  45. ns.bm("button", checkboxButtonSize.value),
  46. ns.is("disabled", isDisabled.value),
  47. ns.is("checked", isChecked.value),
  48. ns.is("focus", isFocused.value)
  49. ];
  50. });
  51. return (_ctx, _cache) => {
  52. return openBlock(), createElementBlock("label", {
  53. class: normalizeClass(unref(lableKls))
  54. }, [
  55. _ctx.trueLabel || _ctx.falseLabel ? withDirectives((openBlock(), createElementBlock("input", {
  56. key: 0,
  57. "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(model) ? model.value = $event : null),
  58. class: normalizeClass(unref(ns).be("button", "original")),
  59. type: "checkbox",
  60. name: _ctx.name,
  61. tabindex: _ctx.tabindex,
  62. disabled: unref(isDisabled),
  63. "true-value": _ctx.trueLabel,
  64. "false-value": _ctx.falseLabel,
  65. onChange: _cache[1] || (_cache[1] = (...args) => unref(handleChange) && unref(handleChange)(...args)),
  66. onFocus: _cache[2] || (_cache[2] = ($event) => isFocused.value = true),
  67. onBlur: _cache[3] || (_cache[3] = ($event) => isFocused.value = false)
  68. }, null, 42, _hoisted_1)), [
  69. [vModelCheckbox, unref(model)]
  70. ]) : withDirectives((openBlock(), createElementBlock("input", {
  71. key: 1,
  72. "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => isRef(model) ? model.value = $event : null),
  73. class: normalizeClass(unref(ns).be("button", "original")),
  74. type: "checkbox",
  75. name: _ctx.name,
  76. tabindex: _ctx.tabindex,
  77. disabled: unref(isDisabled),
  78. value: _ctx.label,
  79. onChange: _cache[5] || (_cache[5] = (...args) => unref(handleChange) && unref(handleChange)(...args)),
  80. onFocus: _cache[6] || (_cache[6] = ($event) => isFocused.value = true),
  81. onBlur: _cache[7] || (_cache[7] = ($event) => isFocused.value = false)
  82. }, null, 42, _hoisted_2)), [
  83. [vModelCheckbox, unref(model)]
  84. ]),
  85. _ctx.$slots.default || _ctx.label ? (openBlock(), createElementBlock("span", {
  86. key: 2,
  87. class: normalizeClass(unref(ns).be("button", "inner")),
  88. style: normalizeStyle(unref(isChecked) ? unref(activeStyle) : void 0)
  89. }, [
  90. renderSlot(_ctx.$slots, "default", {}, () => [
  91. createTextVNode(toDisplayString(_ctx.label), 1)
  92. ])
  93. ], 6)) : createCommentVNode("v-if", true)
  94. ], 2);
  95. };
  96. }
  97. });
  98. var CheckboxButton = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/checkbox/src/checkbox-button.vue"]]);
  99. export { CheckboxButton as default };
  100. //# sourceMappingURL=checkbox-button.mjs.map