UNPKG

@aplus-frontend/ui

Version:

89 lines (88 loc) 2.63 kB
import { defineComponent as q, ref as s, onMounted as C, computed as O, unref as e, createElementBlock as p, openBlock as a, Fragment as m, createTextVNode as R, toDisplayString as U, createBlock as d, mergeProps as h } from "vue"; import { Spin as G, RadioGroup as N } from "@aplus-frontend/antdv"; import "../../hooks/index.mjs"; import { isNil as S, omit as z } from "lodash-unified"; import { getOptionValue as F, getOptionLabel as A } from "./helper.mjs"; import "../../config-provider/index.mjs"; import D from "../hooks/use-options.mjs"; import { useControllableValue as E } from "../../hooks/useControllableValue.mjs"; import { useNamespace as L } from "../../config-provider/hooks/use-namespace.mjs"; const W = /* @__PURE__ */ q({ name: "ApFieldRadio", __name: "index", props: { mode: { default: "edit" }, class: {}, style: {}, prefixCls: {}, value: {}, size: {}, options: {}, disabled: { type: Boolean, default: void 0 }, name: {}, buttonStyle: {}, id: {}, block: { type: Boolean }, optionType: {}, onChange: {}, "onUpdate:value": {}, emptyText: { default: "--" }, request: {}, vertical: { type: Boolean, default: !1 } }, emits: ["update:value"], setup(c, { expose: f, emit: v }) { const t = c, y = v, l = s(), { options: r, updateOptions: g } = D(t), { value: u, updateValue: k } = E(t, y), { b, m: x } = L("field-radio"), n = s(!1); C(() => { t.request && (n.value = !0, t.request?.().then((o) => g(o)).finally(() => { n.value = !1; })); }); const B = O(() => { const o = e(u); if (S(o)) return t.emptyText; const i = r.value?.find( (_) => o === F(_) ); return A(i) || t.emptyText; }); function T() { l.value?.focus(); } function V() { l.value?.blur(); } return f({ focus: T, blur: V }), (o, i) => o.mode === "read" ? (a(), p(m, { key: 0 }, [ R(U(B.value), 1) ], 64)) : (a(), p(m, { key: 1 }, [ n.value ? (a(), d(e(G), { key: 0, size: "small" })) : (a(), d(e(N), h( { key: 1 }, e(z)(t, [ "value", "onUpdate:value", "options", "request", "vertical" ]), { ref_key: "radioGroupRef", ref: l, value: e(u), options: e(r), class: [e(b)(), o.vertical ? e(x)("vertical") : null], "onUpdate:value": e(k) } ), null, 16, ["value", "options", "class", "onUpdate:value"])) ], 64)); } }); export { W as default };