@nextcloud/vue
Version:
Nextcloud vue components
128 lines (127 loc) • 3.87 kB
JavaScript
import '../assets/NcActionCheckbox-BeT6fCCy.css';
import { A as ActionGlobalMixin } from "./actionGlobal-BZFdtdJL.mjs";
import { c as createElementId } from "./createElementId-DhjFt1I9.mjs";
import { a as NC_ACTIONS_IS_SEMANTIC_MENU } from "./useNcActions-CiGWxAJE.mjs";
import { createElementBlock, openBlock, normalizeClass, createElementVNode, createCommentVNode, withKeys, withModifiers, toDisplayString } from "vue";
import { _ as _export_sfc } from "./_plugin-vue_export-helper-1tPrXgE0.mjs";
const _sfc_main = {
name: "NcActionCheckbox",
mixins: [ActionGlobalMixin],
inject: {
isInSemanticMenu: {
from: NC_ACTIONS_IS_SEMANTIC_MENU,
default: false
}
},
props: {
/**
* id attribute of the checkbox element
*/
id: {
type: String,
default: () => "action-" + createElementId(),
validator: (id) => id.trim() !== ""
},
/**
* checked state of the the checkbox element
*/
modelValue: {
type: Boolean,
default: false
},
/**
* value of the checkbox input
*/
value: {
type: [String, Number],
default: ""
},
/**
* disabled state of the checkbox element
*/
disabled: {
type: Boolean,
default: false
}
},
emits: [
"change",
"check",
"uncheck",
"update:modelValue"
],
computed: {
/**
* determines if the action is focusable
*
* @return {boolean} is the action focusable ?
*/
isFocusable() {
return !this.disabled;
},
/**
* aria-checked attribute for role="menuitemcheckbox"
*
* @return {'true'|'false'|undefined} aria-checked value if needed
*/
ariaChecked() {
if (this.isInSemanticMenu) {
return this.modelValue ? "true" : "false";
}
return void 0;
}
},
methods: {
checkInput() {
this.$refs.label.click();
},
onChange(event) {
this.$emit("update:modelValue", this.$refs.checkbox.checked);
this.$emit("change", event);
if (this.$refs.checkbox.checked) {
this.$emit("check");
} else {
this.$emit("uncheck");
}
}
}
};
const _hoisted_1 = ["role"];
const _hoisted_2 = ["role", "aria-checked"];
const _hoisted_3 = ["id", "disabled", "checked", "value"];
const _hoisted_4 = ["for"];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("li", {
class: normalizeClass(["action", { "action--disabled": $props.disabled }]),
role: $options.isInSemanticMenu && "presentation"
}, [
createElementVNode("span", {
class: "action-checkbox",
role: $options.isInSemanticMenu && "menuitemcheckbox",
"aria-checked": $options.ariaChecked
}, [
createElementVNode("input", {
id: $props.id,
ref: "checkbox",
disabled: $props.disabled,
checked: $props.modelValue,
value: $props.value,
class: normalizeClass([{ focusable: $options.isFocusable }, "checkbox action-checkbox__checkbox"]),
type: "checkbox",
onKeydown: _cache[0] || (_cache[0] = withKeys(withModifiers((...args) => $options.checkInput && $options.checkInput(...args), ["exact", "prevent"]), ["enter"])),
onChange: _cache[1] || (_cache[1] = (...args) => $options.onChange && $options.onChange(...args))
}, null, 42, _hoisted_3),
createElementVNode("label", {
ref: "label",
for: $props.id,
class: "action-checkbox__label"
}, toDisplayString(_ctx.text), 9, _hoisted_4),
createCommentVNode("", true)
], 8, _hoisted_2)
], 10, _hoisted_1);
}
const NcActionCheckbox = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6099342c"]]);
export {
NcActionCheckbox as N
};
//# sourceMappingURL=NcActionCheckbox-CwrO3g3I.mjs.map