c54608b4a8f95573ee65acecfda36fdc30bdea3a451da9881c32e15f5c3ec9c0f2154f32a534f84307d8419b1421368d5949ad676aba649cf06f0e45152e00 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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('./checkbox2.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 inputBindings = vue.computed(() => {
  29. var _a, _b, _c, _d;
  30. if (props.trueValue || props.falseValue || props.trueLabel || props.falseLabel) {
  31. return {
  32. "true-value": (_b = (_a = props.trueValue) != null ? _a : props.trueLabel) != null ? _b : true,
  33. "false-value": (_d = (_c = props.falseValue) != null ? _c : props.falseLabel) != null ? _d : false
  34. };
  35. }
  36. return {
  37. value: actualValue.value
  38. };
  39. });
  40. const checkboxGroup = vue.inject(constants.checkboxGroupContextKey, void 0);
  41. const ns = index.useNamespace("checkbox");
  42. const activeStyle = vue.computed(() => {
  43. var _a, _b, _c, _d;
  44. const fillValue = (_b = (_a = checkboxGroup == null ? void 0 : checkboxGroup.fill) == null ? void 0 : _a.value) != null ? _b : "";
  45. return {
  46. backgroundColor: fillValue,
  47. borderColor: fillValue,
  48. color: (_d = (_c = checkboxGroup == null ? void 0 : checkboxGroup.textColor) == null ? void 0 : _c.value) != null ? _d : "",
  49. boxShadow: fillValue ? `-1px 0 0 0 ${fillValue}` : void 0
  50. };
  51. });
  52. const labelKls = vue.computed(() => {
  53. return [
  54. ns.b("button"),
  55. ns.bm("button", checkboxButtonSize.value),
  56. ns.is("disabled", isDisabled.value),
  57. ns.is("checked", isChecked.value),
  58. ns.is("focus", isFocused.value)
  59. ];
  60. });
  61. return (_ctx, _cache) => {
  62. return vue.openBlock(), vue.createElementBlock("label", {
  63. class: vue.normalizeClass(vue.unref(labelKls))
  64. }, [
  65. vue.withDirectives(vue.createElementVNode("input", vue.mergeProps({
  66. "onUpdate:modelValue": ($event) => vue.isRef(model) ? model.value = $event : null,
  67. class: vue.unref(ns).be("button", "original"),
  68. type: "checkbox",
  69. name: _ctx.name,
  70. tabindex: _ctx.tabindex,
  71. disabled: vue.unref(isDisabled)
  72. }, vue.unref(inputBindings), {
  73. onChange: vue.unref(handleChange),
  74. onFocus: ($event) => isFocused.value = true,
  75. onBlur: ($event) => isFocused.value = false,
  76. onClick: vue.withModifiers(() => {
  77. }, ["stop"])
  78. }), null, 16, ["onUpdate:modelValue", "name", "tabindex", "disabled", "onChange", "onFocus", "onBlur", "onClick"]), [
  79. [vue.vModelCheckbox, vue.unref(model)]
  80. ]),
  81. _ctx.$slots.default || _ctx.label ? (vue.openBlock(), vue.createElementBlock("span", {
  82. key: 0,
  83. class: vue.normalizeClass(vue.unref(ns).be("button", "inner")),
  84. style: vue.normalizeStyle(vue.unref(isChecked) ? vue.unref(activeStyle) : void 0)
  85. }, [
  86. vue.renderSlot(_ctx.$slots, "default", {}, () => [
  87. vue.createTextVNode(vue.toDisplayString(_ctx.label), 1)
  88. ])
  89. ], 6)) : vue.createCommentVNode("v-if", true)
  90. ], 2);
  91. };
  92. }
  93. });
  94. var CheckboxButton = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "checkbox-button.vue"]]);
  95. exports["default"] = CheckboxButton;
  96. //# sourceMappingURL=checkbox-button.js.map