Blame view

src/components/tooltip/tooltip.vue 3.27 KB
dce3e753   梁灏   add Tooltip compo...
1
  <template>
4b7138b9   梁灏   fixed some bugs
2
      <div :class="[prefixCls]" @mouseenter="handleShowPopper" @mouseleave="handleClosePopper">
d6f644e1   梁灏   support Tooltip
3
          <div :class="[prefixCls + '-rel']" ref="reference">
dce3e753   梁灏   add Tooltip compo...
4
5
              <slot></slot>
          </div>
d6f644e1   梁灏   support Tooltip
6
          <transition name="fade">
fcf3cace   梁灏   Poptip & Tooltip ...
7
              <div
46c07066   梁灏   update Poptip style
8
                  :class="[prefixCls + '-popper', prefixCls + '-' + theme]"
fcf3cace   梁灏   Poptip & Tooltip ...
9
10
11
12
                  ref="popper"
                  v-show="!disabled && (visible || always)"
                  @mouseenter="handleShowPopper"
                  @mouseleave="handleClosePopper"
548eac43   梁灏   fixed #1387 and u...
13
14
                  :data-transfer="transfer"
                  v-transfer-dom>
d6f644e1   梁灏   support Tooltip
15
16
17
18
                  <div :class="[prefixCls + '-content']">
                      <div :class="[prefixCls + '-arrow']"></div>
                      <div :class="[prefixCls + '-inner']"><slot name="content">{{ content }}</slot></div>
                  </div>
dce3e753   梁灏   add Tooltip compo...
19
              </div>
d6f644e1   梁灏   support Tooltip
20
          </transition>
dce3e753   梁灏   add Tooltip compo...
21
22
23
24
      </div>
  </template>
  <script>
      import Popper from '../base/popper';
fcf3cace   梁灏   Poptip & Tooltip ...
25
      import TransferDom from '../../directives/transfer-dom';
dce3e753   梁灏   add Tooltip compo...
26
27
28
29
30
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-tooltip';
  
      export default {
79288d43   梁灏   support Poptip & ...
31
          name: 'Tooltip',
fcf3cace   梁灏   Poptip & Tooltip ...
32
          directives: { TransferDom },
dce3e753   梁灏   add Tooltip compo...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
          mixins: [Popper],
          props: {
              placement: {
                  validator (value) {
                      return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
                  },
                  default: 'bottom'
              },
              content: {
                  type: [String, Number],
                  default: ''
              },
              delay: {
                  type: Number,
fcf3cace   梁灏   Poptip & Tooltip ...
47
                  default: 100
dce3e753   梁灏   add Tooltip compo...
48
49
50
51
              },
              disabled: {
                  type: Boolean,
                  default: false
73772536   梁灏   optimize Slider t...
52
53
54
55
              },
              controlled: {    // under this prop,Tooltip will not close when mouseleave
                  type: Boolean,
                  default: false
59872199   Rijn   added show-tip to...
56
57
58
59
              },
              always: {
                  type: Boolean,
                  default: false
fcf3cace   梁灏   Poptip & Tooltip ...
60
61
62
63
              },
              transfer: {
                  type: Boolean,
                  default: false
46c07066   梁灏   update Poptip style
64
65
66
67
68
69
              },
              theme: {
                  validator (value) {
                      return oneOf(value, ['dark', 'light']);
                  },
                  default: 'dark'
dce3e753   梁灏   add Tooltip compo...
70
71
72
73
74
              }
          },
          data () {
              return {
                  prefixCls: prefixCls
b0893113   jingsam   :art: add eslint
75
              };
dce3e753   梁灏   add Tooltip compo...
76
          },
cd92d878   梁灏   fixed #1482
77
78
79
80
81
          watch: {
              content () {
                  this.updatePopper();
              }
          },
dce3e753   梁灏   add Tooltip compo...
82
83
          methods: {
              handleShowPopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
84
                  if (this.timeout) clearTimeout(this.timeout);
dce3e753   梁灏   add Tooltip compo...
85
                  this.timeout = setTimeout(() => {
9699c270   梁灏   add Poptip component
86
                      this.visible = true;
dce3e753   梁灏   add Tooltip compo...
87
88
89
                  }, this.delay);
              },
              handleClosePopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
90
91
92
93
94
95
96
                  if (this.timeout) {
                      clearTimeout(this.timeout);
                      if (!this.controlled) {
                          this.timeout = setTimeout(() => {
                              this.visible = false;
                          }, 100);
                      }
73772536   梁灏   optimize Slider t...
97
                  }
dce3e753   梁灏   add Tooltip compo...
98
              }
d293cc5c   梁灏   fixed #1568 and c...
99
100
101
102
103
          },
          mounted () {
              if (this.always) {
                  this.updatePopper();
              }
dce3e753   梁灏   add Tooltip compo...
104
          }
b0893113   jingsam   :art: add eslint
105
      };
d6342fe1   jingsam   fixed ie bug
106
  </script>