1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _Checkbox = require('./Checkbox');
var _Checkbox2 = _interopRequireDefault(_Checkbox);
var _propsUtil = require('../_util/props-util');
var _propsUtil2 = _interopRequireDefault(_propsUtil);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function noop() {}
exports['default'] = {
name: 'ACheckboxGroup',
model: {
prop: 'value'
},
props: {
prefixCls: {
'default': 'ant-checkbox',
type: String
},
defaultValue: {
'default': undefined,
type: Array
},
value: {
'default': undefined,
type: Array
},
options: {
'default': function _default() {
return [];
},
type: Array
},
disabled: Boolean
},
provide: function provide() {
return {
checkboxGroupContext: this
};
},
data: function data() {
var value = this.value,
defaultValue = this.defaultValue;
return {
sValue: value || defaultValue || []
};
},
watch: {
value: function value(val) {
this.sValue = val;
}
},
methods: {
getOptions: function getOptions() {
var options = this.options,
$scopedSlots = this.$scopedSlots;
return options.map(function (option) {
if (typeof option === 'string') {
return {
label: option,
value: option
};
}
var label = option.label;
if (label === undefined && $scopedSlots.label) {
label = $scopedSlots.label(option);
}
return (0, _extends3['default'])({}, option, { label: label });
});
},
toggleOption: function toggleOption(option) {
var optionIndex = this.sValue.indexOf(option.value);
var value = [].concat((0, _toConsumableArray3['default'])(this.sValue));
if (optionIndex === -1) {
value.push(option.value);
} else {
value.splice(optionIndex, 1);
}
if (!(0, _propsUtil2['default'])(this, 'value')) {
this.sValue = value;
}
this.$emit('input', value);
this.$emit('change', value);
}
},
render: function render() {
var h = arguments[0];
var props = this.$props,
state = this.$data,
$slots = this.$slots;
var prefixCls = props.prefixCls,
options = props.options;
var children = $slots['default'];
var groupPrefixCls = prefixCls + '-group';
if (options && options.length > 0) {
children = this.getOptions().map(function (option) {
return h(
_Checkbox2['default'],
{
attrs: {
prefixCls: prefixCls,
disabled: 'disabled' in option ? option.disabled : props.disabled,
value: option.value,
checked: state.sValue.indexOf(option.value) !== -1
},
key: option.value.toString(), on: {
'change': option.onChange || noop
},
'class': groupPrefixCls + '-item'
},
[option.label]
);
});
}
return h(
'div',
{ 'class': groupPrefixCls },
[children]
);
}
};