Blame view

src/components/radio/radio-group.vue 2.33 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
3f281d6c   梁灏   update RadioGroup
7
      import { oneOf, findComponentsDownward } from '../../utils/assist';
cd78c9c4   梁灏   some comps suppor...
8
      import Emitter from '../../mixins/emitter';
7fa943eb   梁灏   init
9
10
11
12
  
      const prefixCls = 'ivu-radio-group';
  
      export default {
34ee7b4a   梁灏   support Tree & ad...
13
          name: 'RadioGroup',
cd78c9c4   梁灏   some comps suppor...
14
          mixins: [ Emitter ],
7fa943eb   梁灏   init
15
          props: {
06322514   梁灏   support Radio
16
              value: {
7fa943eb   梁灏   init
17
18
19
20
21
                  type: [String, Number],
                  default: ''
              },
              size: {
                  validator (value) {
4d545420   梁灏   Radio add size prop
22
                      return oneOf(value, ['small', 'large', 'default']);
7fa943eb   梁灏   init
23
24
25
26
27
28
                  }
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['button']);
                  }
5722a6fb   梁灏   RadioGroup add ve...
29
30
31
32
              },
              vertical: {
                  type: Boolean,
                  default: false
7fa943eb   梁灏   init
33
34
              }
          },
06322514   梁灏   support Radio
35
36
          data () {
              return {
3f281d6c   梁灏   update RadioGroup
37
38
                  currentValue: this.value,
                  childrens: []
cbe03a12   梁灏   support Checkbox
39
              };
06322514   梁灏   support Radio
40
          },
7fa943eb   梁灏   init
41
42
43
44
45
46
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.size}`]: !!this.size,
4d545420   梁灏   Radio add size prop
47
                          [`ivu-radio-${this.size}`]: !!this.size,
5722a6fb   梁灏   RadioGroup add ve...
48
49
                          [`${prefixCls}-${this.type}`]: !!this.type,
                          [`${prefixCls}-vertical`]: this.vertical
7fa943eb   梁灏   init
50
                      }
b0893113   jingsam   :art: add eslint
51
                  ];
7fa943eb   梁灏   init
52
53
              }
          },
06322514   梁灏   support Radio
54
55
          mounted () {
              this.updateValue();
7fa943eb   梁灏   init
56
57
          },
          methods: {
06322514   梁灏   support Radio
58
59
              updateValue () {
                  const value = this.value;
3f281d6c   梁灏   update RadioGroup
60
61
62
63
64
65
66
67
                  this.childrens = findComponentsDownward(this, 'Radio');
  
                  if (this.childrens) {
                      this.childrens.forEach(child => {
                          child.currentValue = value == child.label;
                          child.group = true;
                      });
                  }
7fa943eb   梁灏   init
68
69
              },
              change (data) {
06322514   梁灏   support Radio
70
71
72
                  this.currentValue = data.value;
                  this.updateValue();
                  this.$emit('input', data.value);
7fa943eb   梁灏   init
73
                  this.$emit('on-change', data.value);
cd78c9c4   梁灏   some comps suppor...
74
                  this.dispatch('FormItem', 'on-form-change', data.value);
7fa943eb   梁灏   init
75
76
77
              }
          },
          watch: {
06322514   梁灏   support Radio
78
79
              value () {
                  this.updateValue();
7fa943eb   梁灏   init
80
81
              }
          }
b0893113   jingsam   :art: add eslint
82
83
      };
  </script>