Blame view

src/components/tooltip/tooltip.vue 4.44 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]"
7bafe9d9   梁灏   fixes #4453 #4480...
9
                  :style="dropStyles"
fcf3cace   梁灏   Poptip & Tooltip ...
10
11
12
13
                  ref="popper"
                  v-show="!disabled && (visible || always)"
                  @mouseenter="handleShowPopper"
                  @mouseleave="handleClosePopper"
548eac43   梁灏   fixed #1387 and u...
14
15
                  :data-transfer="transfer"
                  v-transfer-dom>
d6f644e1   梁灏   support Tooltip
16
17
                  <div :class="[prefixCls + '-content']">
                      <div :class="[prefixCls + '-arrow']"></div>
6b498dd1   梁灏   Tooltip add maxWi...
18
                      <div :class="innerClasses" :style="innerStyles"><slot name="content">{{ content }}</slot></div>
d6f644e1   梁灏   support Tooltip
19
                  </div>
dce3e753   梁灏   add Tooltip compo...
20
              </div>
d6f644e1   梁灏   support Tooltip
21
          </transition>
dce3e753   梁灏   add Tooltip compo...
22
23
24
25
      </div>
  </template>
  <script>
      import Popper from '../base/popper';
fcf3cace   梁灏   Poptip & Tooltip ...
26
      import TransferDom from '../../directives/transfer-dom';
dce3e753   梁灏   add Tooltip compo...
27
      import { oneOf } from '../../utils/assist';
7bafe9d9   梁灏   fixes #4453 #4480...
28
      import { transferIndex, transferIncrease } from '../../utils/transfer-queue';
dce3e753   梁灏   add Tooltip compo...
29
30
31
32
  
      const prefixCls = 'ivu-tooltip';
  
      export default {
79288d43   梁灏   support Poptip & ...
33
          name: 'Tooltip',
fcf3cace   梁灏   Poptip & Tooltip ...
34
          directives: { TransferDom },
dce3e753   梁灏   add Tooltip compo...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
          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 ...
49
                  default: 100
dce3e753   梁灏   add Tooltip compo...
50
51
52
53
              },
              disabled: {
                  type: Boolean,
                  default: false
73772536   梁灏   optimize Slider t...
54
55
56
57
              },
              controlled: {    // under this prop,Tooltip will not close when mouseleave
                  type: Boolean,
                  default: false
59872199   Rijn   added show-tip to...
58
59
60
61
              },
              always: {
                  type: Boolean,
                  default: false
fcf3cace   梁灏   Poptip & Tooltip ...
62
63
64
              },
              transfer: {
                  type: Boolean,
28ab119d   梁灏   Tooltip support t...
65
                  default () {
fe5ffd7f   梁灏   fixed #4196 #4165
66
                      return !this.$IVIEW || this.$IVIEW.transfer === '' ? false : this.$IVIEW.transfer;
28ab119d   梁灏   Tooltip support t...
67
                  }
46c07066   梁灏   update Poptip style
68
69
70
71
72
73
              },
              theme: {
                  validator (value) {
                      return oneOf(value, ['dark', 'light']);
                  },
                  default: 'dark'
6b498dd1   梁灏   Tooltip add maxWi...
74
75
              },
              maxWidth: {
953d02c7   梁灏   update Tooltip ma...
76
                  type: [String, Number]
dce3e753   梁灏   add Tooltip compo...
77
78
79
80
              }
          },
          data () {
              return {
7bafe9d9   梁灏   fixes #4453 #4480...
81
82
                  prefixCls: prefixCls,
                  tIndex: this.handleGetIndex()
b0893113   jingsam   :art: add eslint
83
              };
dce3e753   梁灏   add Tooltip compo...
84
          },
6b498dd1   梁灏   Tooltip add maxWi...
85
86
87
88
89
90
91
92
93
94
95
96
97
          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
                      }
                  ];
7bafe9d9   梁灏   fixes #4453 #4480...
98
99
100
101
102
103
              },
              dropStyles () {
                  let styles = {};
                  if (this.transfer) styles['z-index'] = 1060 + this.tIndex;
  
                  return styles;
6b498dd1   梁灏   Tooltip add maxWi...
104
105
              }
          },
cd92d878   梁灏   fixed #1482
106
107
108
109
110
          watch: {
              content () {
                  this.updatePopper();
              }
          },
dce3e753   梁灏   add Tooltip compo...
111
112
          methods: {
              handleShowPopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
113
                  if (this.timeout) clearTimeout(this.timeout);
dce3e753   梁灏   add Tooltip compo...
114
                  this.timeout = setTimeout(() => {
9699c270   梁灏   add Poptip component
115
                      this.visible = true;
dce3e753   梁灏   add Tooltip compo...
116
                  }, this.delay);
7bafe9d9   梁灏   fixes #4453 #4480...
117
                  this.tIndex = this.handleGetIndex();
dce3e753   梁灏   add Tooltip compo...
118
119
              },
              handleClosePopper() {
fcf3cace   梁灏   Poptip & Tooltip ...
120
121
122
123
124
125
126
                  if (this.timeout) {
                      clearTimeout(this.timeout);
                      if (!this.controlled) {
                          this.timeout = setTimeout(() => {
                              this.visible = false;
                          }, 100);
                      }
73772536   梁灏   optimize Slider t...
127
                  }
7bafe9d9   梁灏   fixes #4453 #4480...
128
129
130
131
132
              },
              handleGetIndex () {
                  transferIncrease();
                  return transferIndex;
              },
d293cc5c   梁灏   fixed #1568 and c...
133
134
135
136
137
          },
          mounted () {
              if (this.always) {
                  this.updatePopper();
              }
dce3e753   梁灏   add Tooltip compo...
138
          }
b0893113   jingsam   :art: add eslint
139
      };
d6342fe1   jingsam   fixed ie bug
140
  </script>