checkbox-button.js 4.6 KB

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