You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.2 KiB

4 months ago
  1. import { defineComponent, openBlock, createElementBlock, normalizeClass, unref, createElementVNode, withDirectives, isRef, withModifiers, vModelRadio, renderSlot, createTextVNode, toDisplayString, nextTick } from 'vue';
  2. import { radioProps, radioEmits } from './radio.mjs';
  3. import { useRadio } from './use-radio.mjs';
  4. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  5. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  6. import { CHANGE_EVENT } from '../../../constants/event.mjs';
  7. const __default__ = defineComponent({
  8. name: "ElRadio"
  9. });
  10. const _sfc_main = /* @__PURE__ */ defineComponent({
  11. ...__default__,
  12. props: radioProps,
  13. emits: radioEmits,
  14. setup(__props, { emit }) {
  15. const props = __props;
  16. const ns = useNamespace("radio");
  17. const { radioRef, radioGroup, focus, size, disabled, modelValue, actualValue } = useRadio(props, emit);
  18. function handleChange() {
  19. nextTick(() => emit(CHANGE_EVENT, modelValue.value));
  20. }
  21. return (_ctx, _cache) => {
  22. var _a;
  23. return openBlock(), createElementBlock("label", {
  24. class: normalizeClass([
  25. unref(ns).b(),
  26. unref(ns).is("disabled", unref(disabled)),
  27. unref(ns).is("focus", unref(focus)),
  28. unref(ns).is("bordered", _ctx.border),
  29. unref(ns).is("checked", unref(modelValue) === unref(actualValue)),
  30. unref(ns).m(unref(size))
  31. ])
  32. }, [
  33. createElementVNode("span", {
  34. class: normalizeClass([
  35. unref(ns).e("input"),
  36. unref(ns).is("disabled", unref(disabled)),
  37. unref(ns).is("checked", unref(modelValue) === unref(actualValue))
  38. ])
  39. }, [
  40. withDirectives(createElementVNode("input", {
  41. ref_key: "radioRef",
  42. ref: radioRef,
  43. "onUpdate:modelValue": ($event) => isRef(modelValue) ? modelValue.value = $event : null,
  44. class: normalizeClass(unref(ns).e("original")),
  45. value: unref(actualValue),
  46. name: _ctx.name || ((_a = unref(radioGroup)) == null ? void 0 : _a.name),
  47. disabled: unref(disabled),
  48. checked: unref(modelValue) === unref(actualValue),
  49. type: "radio",
  50. onFocus: ($event) => focus.value = true,
  51. onBlur: ($event) => focus.value = false,
  52. onChange: handleChange,
  53. onClick: withModifiers(() => {
  54. }, ["stop"])
  55. }, null, 42, ["onUpdate:modelValue", "value", "name", "disabled", "checked", "onFocus", "onBlur", "onClick"]), [
  56. [vModelRadio, unref(modelValue)]
  57. ]),
  58. createElementVNode("span", {
  59. class: normalizeClass(unref(ns).e("inner"))
  60. }, null, 2)
  61. ], 2),
  62. createElementVNode("span", {
  63. class: normalizeClass(unref(ns).e("label")),
  64. onKeydown: withModifiers(() => {
  65. }, ["stop"])
  66. }, [
  67. renderSlot(_ctx.$slots, "default", {}, () => [
  68. createTextVNode(toDisplayString(_ctx.label), 1)
  69. ])
  70. ], 42, ["onKeydown"])
  71. ], 2);
  72. };
  73. }
  74. });
  75. var Radio = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "radio.vue"]]);
  76. export { Radio as default };
  77. //# sourceMappingURL=radio2.mjs.map