UNPKG

@nextcloud/vue

Version:
137 lines (136 loc) 4.04 kB
import '../assets/NcActionRadio-DgdLD238.css'; import { createElementBlock, openBlock, normalizeClass, createElementVNode, withDirectives, createCommentVNode, withKeys, withModifiers, vModelRadio, toDisplayString, useModel } from "vue"; 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 { _ as _export_sfc } from "./_plugin-vue_export-helper-1tPrXgE0.mjs"; const _sfc_main = { name: "NcActionRadio", mixins: [ActionGlobalMixin], inject: { isInSemanticMenu: { from: NC_ACTIONS_IS_SEMANTIC_MENU, default: false } }, props: { /** * id attribute of the radio element */ id: { type: String, default: () => createElementId(), validator: (id) => id.trim() !== "" }, /** * checked state of the radio element */ modelValue: { type: [String, Number], default: "" }, /** * 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: [ "change", "update:modelValue" ], setup(props) { return { model: useModel(props, "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 === this.value ? "true" : "false"; } return void 0; } }, methods: { toggleInput() { this.$refs.label.click(); }, onChange(event) { this.$emit("change", event); } } }; const _hoisted_1 = ["role"]; const _hoisted_2 = ["aria-checked"]; const _hoisted_3 = ["id", "disabled", "name", "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-radio", role: "menuitemradio", "aria-checked": $options.ariaChecked }, [ withDirectives(createElementVNode("input", { id: $props.id, ref: "radio", "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => $setup.model = $event), class: normalizeClass(["radio action-radio__radio", { focusable: $options.isFocusable }]), disabled: $props.disabled, name: $props.name, value: $props.value, type: "radio", onKeydown: _cache[1] || (_cache[1] = withKeys(withModifiers((...args) => $options.toggleInput && $options.toggleInput(...args), ["exact", "prevent"]), ["enter"])), onChange: _cache[2] || (_cache[2] = (...args) => $options.onChange && $options.onChange(...args)) }, null, 42, _hoisted_3), [ [vModelRadio, $setup.model] ]), createElementVNode("label", { ref: "label", for: $props.id, class: "action-radio__label" }, toDisplayString(_ctx.text), 9, _hoisted_4), createCommentVNode("", true) ], 8, _hoisted_2) ], 10, _hoisted_1); } const NcActionRadio = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-9e878692"]]); export { NcActionRadio as N }; //# sourceMappingURL=NcActionRadio-ByCpOD0q.mjs.map