1 | import { createVNode as _createVNode } from "vue";
|
2 |
|
3 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
4 |
|
5 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
6 |
|
7 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8 |
|
9 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
10 |
|
11 | var __rest = this && this.__rest || function (s, e) {
|
12 | var t = {};
|
13 |
|
14 | for (var p in s) {
|
15 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
16 | }
|
17 |
|
18 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
19 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
20 | }
|
21 | return t;
|
22 | };
|
23 |
|
24 | import { defineComponent, inject } from 'vue';
|
25 | import PropTypes from '../_util/vue-types';
|
26 | import VcCheckbox from '../vc-checkbox';
|
27 | import classNames from '../_util/classNames';
|
28 | import { getOptionProps } from '../_util/props-util';
|
29 | import { defaultConfigProvider } from '../config-provider';
|
30 | export var radioProps = {
|
31 | prefixCls: PropTypes.string,
|
32 | defaultChecked: PropTypes.looseBool,
|
33 | checked: PropTypes.looseBool,
|
34 | disabled: PropTypes.looseBool,
|
35 | isGroup: PropTypes.looseBool,
|
36 | value: PropTypes.any,
|
37 | name: PropTypes.string,
|
38 | id: PropTypes.string,
|
39 | autofocus: PropTypes.looseBool,
|
40 | type: PropTypes.string.def('radio'),
|
41 | onChange: PropTypes.func,
|
42 | onFocus: PropTypes.func,
|
43 | onBlur: PropTypes.func
|
44 | };
|
45 | export default defineComponent({
|
46 | name: 'ARadio',
|
47 | props: radioProps,
|
48 | emits: ['update:checked', 'update:value', 'change', 'blur', 'focus'],
|
49 | setup: function setup() {
|
50 | return {
|
51 | configProvider: inject('configProvider', defaultConfigProvider),
|
52 | radioGroupContext: inject('radioGroupContext', null)
|
53 | };
|
54 | },
|
55 | methods: {
|
56 | focus: function focus() {
|
57 | this.$refs.vcCheckbox.focus();
|
58 | },
|
59 | blur: function blur() {
|
60 | this.$refs.vcCheckbox.blur();
|
61 | },
|
62 | handleChange: function handleChange(event) {
|
63 | var targetChecked = event.target.checked;
|
64 | this.$emit('update:checked', targetChecked);
|
65 | this.$emit('update:value', targetChecked);
|
66 | this.$emit('change', event);
|
67 | },
|
68 | onChange2: function onChange2(e) {
|
69 | this.$emit('change', e);
|
70 |
|
71 | if (this.radioGroupContext && this.radioGroupContext.onRadioChange) {
|
72 | this.radioGroupContext.onRadioChange(e);
|
73 | }
|
74 | }
|
75 | },
|
76 | render: function render() {
|
77 | var _classNames;
|
78 |
|
79 | var $slots = this.$slots,
|
80 | radioGroup = this.radioGroupContext;
|
81 | var props = getOptionProps(this);
|
82 |
|
83 | var customizePrefixCls = props.prefixCls,
|
84 | restProps = __rest(props, ["prefixCls"]);
|
85 |
|
86 | var getPrefixCls = this.configProvider.getPrefixCls;
|
87 | var prefixCls = getPrefixCls('radio', customizePrefixCls);
|
88 |
|
89 | var rProps = _extends({
|
90 | prefixCls: prefixCls
|
91 | }, restProps);
|
92 |
|
93 | if (radioGroup) {
|
94 | rProps.name = radioGroup.name;
|
95 | rProps.onChange = this.onChange2;
|
96 | rProps.checked = props.value === radioGroup.stateValue;
|
97 | rProps.disabled = props.disabled || radioGroup.disabled;
|
98 | } else {
|
99 | rProps.onChange = this.handleChange;
|
100 | }
|
101 |
|
102 | var wrapperClassString = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-wrapper"), true), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-checked"), rProps.checked), _defineProperty(_classNames, "".concat(prefixCls, "-wrapper-disabled"), rProps.disabled), _classNames));
|
103 | return _createVNode("label", {
|
104 | "class": wrapperClassString
|
105 | }, [_createVNode(VcCheckbox, _objectSpread(_objectSpread({}, rProps), {}, {
|
106 | "ref": "vcCheckbox"
|
107 | }), null), $slots.default && _createVNode("span", null, [$slots.default()])]);
|
108 | }
|
109 | }); |
\ | No newline at end of file |