Blame view

src/components/tooltip/tooltip.vue 3.82 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
                  <div :class="[prefixCls + '-content']">
                      <div :class="[prefixCls + '-arrow']"></div>
6b498dd1   梁灏   Tooltip add maxWi...
17
                      <div :class="innerClasses" :style="innerStyles"><slot name="content">{{ content }}</slot></div>
d6f644e1   梁灏   support Tooltip
18
                  </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'
6b498dd1   梁灏   Tooltip add maxWi...
70
71
              },
              maxWidth: {
953d02c7   梁灏   update Tooltip ma...
72
                  type: [String, Number]
dce3e753   梁灏   add Tooltip compo...
73
74
75
76
77
              }
          },
          data () {
              return {
                  prefixCls: prefixCls
b0893113   jingsam   :art: add eslint
78
              };
dce3e753   梁灏   add Tooltip compo...
79
          },
6b498dd1   梁灏   Tooltip add maxWi...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
          computed: {
              innerStyles () {
                  const styles = {};
                  if (this.maxWidth) styles['max-width'] = `${this.maxWidth}px`;
                  return styles;
              },
              innerClasses () {
                  return [
                      `${prefixCls}-inner`,
                      {
                          [`${prefixCls}-inner-with-width`]: !!this.maxWidth
                      }
                  ];
              }
          },
cd92d878   梁灏   fixed #1482
95
96
97
98
99
          watch: {
              content () {
                  this.updatePopper();
              }
          },
dce3e753   梁灏   add Tooltip compo...
100
101
          methods: {
              handleShowPopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
102
                  if (this.timeout) clearTimeout(this.timeout);
dce3e753   梁灏   add Tooltip compo...
103
                  this.timeout = setTimeout(() => {
9699c270   梁灏   add Poptip component
104
                      this.visible = true;
dce3e753   梁灏   add Tooltip compo...
105
106
107
                  }, this.delay);
              },
              handleClosePopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
108
109
110
111
112
113
114
                  if (this.timeout) {
                      clearTimeout(this.timeout);
                      if (!this.controlled) {
                          this.timeout = setTimeout(() => {
                              this.visible = false;
                          }, 100);
                      }
73772536   梁灏   optimize Slider t...
115
                  }
dce3e753   梁灏   add Tooltip compo...
116
              }
d293cc5c   梁灏   fixed #1568 and c...
117
118
119
120
121
          },
          mounted () {
              if (this.always) {
                  this.updatePopper();
              }
dce3e753   梁灏   add Tooltip compo...
122
          }
b0893113   jingsam   :art: add eslint
123
      };
d6342fe1   jingsam   fixed ie bug
124
  </script>