@nextcloud/vue
Version:
Nextcloud vue components
147 lines (146 loc) • 4.37 kB
JavaScript
import '../assets/NcActionRadio-C87waXE-.css';
import Vue from "vue";
import { u as useModelMigration } from "./useModelMigration-EhAWvqDD.mjs";
import { A as ActionGlobalMixin } from "./actionGlobal-DqVa7c7G.mjs";
import { G as GenRandomId } from "./GenRandomId-CMooMQt0.mjs";
import { n as normalizeComponent } from "./_plugin-vue2_normalizer-DU4iP6Vu.mjs";
const _sfc_main = {
name: "NcActionRadio",
mixins: [ActionGlobalMixin],
inject: {
isInSemanticMenu: {
from: "NcActions:isSemanticMenu",
default: false
}
},
model: {
prop: "modelValue",
event: "update:modelValue"
},
props: {
/**
* id attribute of the radio element
*/
id: {
type: String,
default: () => "action-" + GenRandomId(),
validator: (id) => id.trim() !== ""
},
/**
* Removed in v9 - use `modelValue` (`v-model`) instead
* @deprecated
*/
checked: {
type: Boolean,
default: void 0
},
/**
* Checked state of the radio element
* Boolean type removed in v9 - use String | Number instead
*/
modelValue: {
type: [Boolean, String, Number],
default: false
},
/**
* Define if this radio is part of a set.
* Checking the radio will disable all the
* others with the same name.
*/
name: {
type: String,
required: true
},
/**
* value of the radio input
*/
value: {
type: [String, Number],
default: ""
},
/**
* disabled state of the radio element
*/
disabled: {
type: Boolean,
default: false
}
},
emits: [
/**
* Removed in v9 - use `update:modelValue` (`v-model`) instead
* @deprecated
*/
"update:checked",
/**
* The radio state is changed
* @type {boolean}
*/
"update:modelValue",
/** Same as update:modelValue for Vue 2 compatibility */
"update:model-value",
"change"
],
setup(props) {
if (typeof props.modelValue === "boolean") {
Vue.util.warn("[NcActionRadio] Boolean type of `modelValue` is deprecated and will be removed in next versions");
}
const model = useModelMigration("checked", "update:checked");
return {
model
};
},
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.model ? "true" : "false";
}
return void 0;
}
},
methods: {
toggleInput(event) {
this.$refs.label.click();
},
onChange(event) {
this.$emit("change", event);
}
}
};
var _sfc_render = function render() {
var _vm = this, _c = _vm._self._c;
return _c("li", { staticClass: "action", class: { "action--disabled": _vm.disabled }, attrs: { "role": _vm.isInSemanticMenu && "presentation" } }, [_c("span", { staticClass: "action-radio", attrs: { "role": "menuitemradio", "aria-checked": _vm.ariaChecked } }, [_c("input", { directives: [{ name: "model", rawName: "v-model", value: _vm.model, expression: "model" }], staticClass: "radio action-radio__radio", class: { focusable: _vm.isFocusable }, attrs: { "id": _vm.id, "disabled": _vm.disabled, "name": _vm.name, "type": "radio" }, domProps: { "value": _vm.value, "checked": _vm._q(_vm.model, _vm.value) }, on: { "keydown": function($event) {
if (!$event.type.indexOf("key") && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")) return null;
if ($event.ctrlKey || $event.shiftKey || $event.altKey || $event.metaKey) return null;
$event.preventDefault();
return _vm.toggleInput.apply(null, arguments);
}, "change": [function($event) {
_vm.model = _vm.value;
}, _vm.onChange] } }), _c("label", { ref: "label", staticClass: "action-radio__label", attrs: { "for": _vm.id } }, [_vm._v(_vm._s(_vm.text))]), _vm._e()], 2)]);
};
var _sfc_staticRenderFns = [];
var __component__ = /* @__PURE__ */ normalizeComponent(
_sfc_main,
_sfc_render,
_sfc_staticRenderFns,
false,
null,
"8ddd08c0"
);
const NcActionRadio = __component__.exports;
export {
NcActionRadio as N
};