98bf0010251fe4e6b50535d645a24303afaffadfed2b13a039580af35d1962c5542a91b2812517073c643a975a4e44c72d3bcbab4089bc5145455ea0afb54e 3.9 KB

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