Blame view

src/components/tooltip/tooltip.vue 3.92 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
              },
              transfer: {
                  type: Boolean,
28ab119d   梁灏   Tooltip support t...
63
64
65
                  default () {
                      return this.$IVIEW.transfer === '' ? false : this.$IVIEW.transfer;
                  }
46c07066   梁灏   update Poptip style
66
67
68
69
70
71
              },
              theme: {
                  validator (value) {
                      return oneOf(value, ['dark', 'light']);
                  },
                  default: 'dark'
6b498dd1   梁灏   Tooltip add maxWi...
72
73
              },
              maxWidth: {
953d02c7   梁灏   update Tooltip ma...
74
                  type: [String, Number]
dce3e753   梁灏   add Tooltip compo...
75
76
77
78
79
              }
          },
          data () {
              return {
                  prefixCls: prefixCls
b0893113   jingsam   :art: add eslint
80
              };
dce3e753   梁灏   add Tooltip compo...
81
          },
6b498dd1   梁灏   Tooltip add maxWi...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
          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
97
98
99
100
101
          watch: {
              content () {
                  this.updatePopper();
              }
          },
dce3e753   梁灏   add Tooltip compo...
102
103
          methods: {
              handleShowPopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
104
                  if (this.timeout) clearTimeout(this.timeout);
dce3e753   梁灏   add Tooltip compo...
105
                  this.timeout = setTimeout(() => {
9699c270   梁灏   add Poptip component
106
                      this.visible = true;
dce3e753   梁灏   add Tooltip compo...
107
108
109
                  }, this.delay);
              },
              handleClosePopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
110
111
112
113
114
115
116
                  if (this.timeout) {
                      clearTimeout(this.timeout);
                      if (!this.controlled) {
                          this.timeout = setTimeout(() => {
                              this.visible = false;
                          }, 100);
                      }
73772536   梁灏   optimize Slider t...
117
                  }
dce3e753   梁灏   add Tooltip compo...
118
              }
d293cc5c   梁灏   fixed #1568 and c...
119
120
121
122
123
          },
          mounted () {
              if (this.always) {
                  this.updatePopper();
              }
dce3e753   梁灏   add Tooltip compo...
124
          }
b0893113   jingsam   :art: add eslint
125
      };
d6342fe1   jingsam   fixed ie bug
126
  </script>