Blame view

src/components/tooltip/tooltip.vue 2.86 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
8
9
10
11
12
              <div
                  :class="[prefixCls + '-popper']"
                  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
dce3e753   梁灏   add Tooltip compo...
64
65
66
67
68
              }
          },
          data () {
              return {
                  prefixCls: prefixCls
b0893113   jingsam   :art: add eslint
69
              };
dce3e753   梁灏   add Tooltip compo...
70
          },
dce3e753   梁灏   add Tooltip compo...
71
72
          methods: {
              handleShowPopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
73
                  if (this.timeout) clearTimeout(this.timeout);
dce3e753   梁灏   add Tooltip compo...
74
                  this.timeout = setTimeout(() => {
9699c270   梁灏   add Poptip component
75
                      this.visible = true;
dce3e753   梁灏   add Tooltip compo...
76
77
78
                  }, this.delay);
              },
              handleClosePopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
79
80
81
82
83
84
85
                  if (this.timeout) {
                      clearTimeout(this.timeout);
                      if (!this.controlled) {
                          this.timeout = setTimeout(() => {
                              this.visible = false;
                          }, 100);
                      }
73772536   梁灏   optimize Slider t...
86
                  }
dce3e753   梁灏   add Tooltip compo...
87
88
              }
          }
b0893113   jingsam   :art: add eslint
89
      };
d6342fe1   jingsam   fixed ie bug
90
  </script>