radio-button2.mjs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, unref, withDirectives, createElementVNode, isRef, withModifiers, vModelRadio, normalizeStyle, renderSlot, createTextVNode, toDisplayString } from 'vue';
  2. import { useRadio } from './use-radio.mjs';
  3. import { radioButtonProps } from './radio-button.mjs';
  4. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  5. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  6. const _hoisted_1 = ["value", "name", "disabled"];
  7. const _sfc_main = defineComponent({
  8. ...{
  9. name: "ElRadioButton"
  10. },
  11. __name: "radio-button",
  12. props: radioButtonProps,
  13. setup(__props) {
  14. const props = __props;
  15. const ns = useNamespace("radio");
  16. const { radioRef, focus, size, disabled, modelValue, radioGroup, actualValue } = useRadio(props);
  17. const activeStyle = computed(() => {
  18. return {
  19. backgroundColor: (radioGroup == null ? void 0 : radioGroup.fill) || "",
  20. borderColor: (radioGroup == null ? void 0 : radioGroup.fill) || "",
  21. boxShadow: (radioGroup == null ? void 0 : radioGroup.fill) ? `-1px 0 0 0 ${radioGroup.fill}` : "",
  22. color: (radioGroup == null ? void 0 : radioGroup.textColor) || ""
  23. };
  24. });
  25. return (_ctx, _cache) => {
  26. var _a;
  27. return openBlock(), createElementBlock(
  28. "label",
  29. {
  30. class: normalizeClass([
  31. unref(ns).b("button"),
  32. unref(ns).is("active", unref(modelValue) === unref(actualValue)),
  33. unref(ns).is("disabled", unref(disabled)),
  34. unref(ns).is("focus", unref(focus)),
  35. unref(ns).bm("button", unref(size))
  36. ])
  37. },
  38. [
  39. withDirectives(createElementVNode("input", {
  40. ref_key: "radioRef",
  41. ref: radioRef,
  42. "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(modelValue) ? modelValue.value = $event : null),
  43. class: normalizeClass(unref(ns).be("button", "original-radio")),
  44. value: unref(actualValue),
  45. type: "radio",
  46. name: _ctx.name || ((_a = unref(radioGroup)) == null ? void 0 : _a.name),
  47. disabled: unref(disabled),
  48. onFocus: _cache[1] || (_cache[1] = ($event) => focus.value = true),
  49. onBlur: _cache[2] || (_cache[2] = ($event) => focus.value = false),
  50. onClick: _cache[3] || (_cache[3] = withModifiers(() => {
  51. }, ["stop"]))
  52. }, null, 42, _hoisted_1), [
  53. [vModelRadio, unref(modelValue)]
  54. ]),
  55. createElementVNode(
  56. "span",
  57. {
  58. class: normalizeClass(unref(ns).be("button", "inner")),
  59. style: normalizeStyle(unref(modelValue) === unref(actualValue) ? activeStyle.value : {}),
  60. onKeydown: _cache[4] || (_cache[4] = withModifiers(() => {
  61. }, ["stop"]))
  62. },
  63. [
  64. renderSlot(_ctx.$slots, "default", {}, () => [
  65. createTextVNode(
  66. toDisplayString(_ctx.label),
  67. 1
  68. )
  69. ])
  70. ],
  71. 38
  72. )
  73. ],
  74. 2
  75. );
  76. };
  77. }
  78. });
  79. var RadioButton = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/radio/src/radio-button.vue"]]);
  80. export { RadioButton as default };
  81. //# sourceMappingURL=radio-button2.mjs.map