@webitel/ui-sdk 3.1.96 → 3.1.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "3.1.96",
3
+ "version": "3.1.98",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -1,32 +1,51 @@
1
1
  <template>
2
- <div class="wt-tooltip">
3
- <div ref="reference"><slot name="activator"></slot></div>
4
- <div ref="floating" :style="floatingStyles"><slot></slot></div>
2
+ <div
3
+ :class="{
4
+ 'wt-tooltip--contrast': contrast,
5
+ 'wt-tooltip--visible': isVisible,
6
+ }"
7
+ class="wt-tooltip"
8
+ >
9
+ <div
10
+ ref="activator"
11
+ class="wt-tooltip__activator"
12
+ >
13
+ <slot name="activator"></slot>
14
+ </div>
15
+ <div
16
+ ref="floating"
17
+ class="wt-tooltip__floating"
18
+ :class="[popperClass]"
19
+ :style="floatingStyles"
20
+ >
21
+ <slot></slot>
22
+ </div>
5
23
  </div>
6
- <!-- <v-tooltip-->
7
- <!-- :class="{-->
8
- <!-- 'wt-tooltip&#45;&#45;contrast': contrast-->
9
- <!-- }"-->
10
- <!-- :placement="placement"-->
11
- <!-- :popper-class="[-->
12
- <!-- 'wt-tooltip__popper',-->
13
- <!-- { 'wt-tooltip&#45;&#45;contrast__popper': contrast },-->
14
- <!-- popperClass,-->
15
- <!-- ]"-->
16
- <!-- :triggers="triggers"-->
17
- <!-- :popper-triggers="popperTriggers"-->
18
- <!-- class="wt-tooltip"-->
19
- <!-- >-->
20
- <!-- <slot name="activator"></slot>-->
21
- <!-- <template #popper>-->
22
- <!-- <slot></slot>-->
23
- <!-- </template>-->
24
- <!-- </v-tooltip>-->
25
24
  </template>
26
25
 
27
26
  <script setup>
28
- import { ref } from 'vue';
29
- import { useFloating, autoPlacement, shift, flip } from '@floating-ui/vue';
27
+ import { ref, onMounted, onBeforeUnmount } from 'vue';
28
+ import {
29
+ useFloating, autoPlacement, shift, flip, offset,
30
+ } from '@floating-ui/vue';
31
+
32
+ // https://github.com/Akryum/floating-vue/blob/main/packages/floating-vue/src/util/events.ts
33
+ const SHOW_EVENT_MAP = {
34
+ hover: 'mouseenter',
35
+ focus: 'focus',
36
+ click: 'click',
37
+ touch: 'touchstart',
38
+ pointer: 'pointerdown',
39
+ };
40
+
41
+ // https://github.com/Akryum/floating-vue/blob/main/packages/floating-vue/src/util/events.ts
42
+ const HIDE_EVENT_MAP = {
43
+ hover: 'mouseleave',
44
+ focus: 'blur',
45
+ click: 'click',
46
+ touch: 'touchend',
47
+ pointer: 'pointerup',
48
+ };
30
49
 
31
50
  const props = defineProps({
32
51
  contrast: {
@@ -51,17 +70,115 @@ const props = defineProps({
51
70
  },
52
71
  });
53
72
 
54
- const reference = ref(null);
73
+ const activator = ref(null);
55
74
  const floating = ref(null);
56
- const { floatingStyles } = useFloating(reference, floating, {
57
- middleware: [autoPlacement(), shift(), flip()],
75
+
76
+ const isVisible = ref(false);
77
+
78
+ const showTooltip = (event) => {
79
+ if (isVisible.value) return;
80
+ isVisible.value = true;
81
+
82
+ // https://github.com/Akryum/floating-vue/blob/main/packages/floating-vue/src/components/Popper.ts#L884
83
+ event.usedByTooltip = true;
84
+ };
85
+
86
+ const hideTooltip = (event) => {
87
+ if (event.usedByTooltip) return;
88
+ isVisible.value = false;
89
+ };
90
+
91
+ const subscribeTriggers = () => {
92
+ const setEventListeners = (target, triggers) => {
93
+ triggers.forEach((trigger) => {
94
+ const showEvent = SHOW_EVENT_MAP[trigger];
95
+ if (showEvent) {
96
+ target.addEventListener(showEvent, showTooltip);
97
+ } else {
98
+ console.log(`No Tooltip Show event for ${trigger} trigger`);
99
+ }
100
+ const hideEvent = HIDE_EVENT_MAP[trigger];
101
+ if (hideEvent) {
102
+ target.addEventListener(hideEvent, hideTooltip);
103
+ } else {
104
+ console.log(`No Tooltip Hide event for ${trigger} trigger`);
105
+ }
106
+ });
107
+ };
108
+
109
+ setEventListeners(activator.value, props.triggers);
110
+ setEventListeners(floating.value, props.popperTriggers);
111
+ };
112
+ const unsubscribeTriggers = () => {
113
+ const unsetEventListeners = (target, triggers) => {
114
+ triggers.forEach((trigger) => {
115
+ const showEvent = SHOW_EVENT_MAP[trigger];
116
+ if (showEvent) {
117
+ target.removeEventListener(showEvent, showTooltip);
118
+ } else {
119
+ console.log(`No Tooltip Show event for ${trigger} trigger`);
120
+ }
121
+ const hideEvent = HIDE_EVENT_MAP[trigger];
122
+ if (hideEvent) {
123
+ target.removeEventListener(hideEvent, hideTooltip);
124
+ } else {
125
+ console.log(`No Tooltip Hide event for ${trigger} trigger`);
126
+ }
127
+ });
128
+ };
129
+
130
+ unsetEventListeners(activator.value, props.triggers);
131
+ unsetEventListeners(floating.value, props.popperTriggers);
132
+ };
133
+
134
+ const { floatingStyles } = useFloating(activator, floating, {
135
+ // https://floating-ui.com/docs/middleware
136
+ middleware: [autoPlacement(), shift(), flip(), offset(8)],
58
137
  });
138
+
139
+ onMounted(() => subscribeTriggers());
140
+ onBeforeUnmount(() => unsubscribeTriggers());
59
141
  </script>
60
142
 
61
143
  <style lang="scss" scoped>
62
144
  .wt-tooltip {
63
145
  display: inline-block;
64
- //line-height: 0;
65
146
  height: fit-content;
147
+
148
+ &__activator {
149
+ line-height: 0;
150
+ }
151
+
152
+ &__floating {
153
+ @extend %typo-body-2;
154
+ padding: var(--spacing-2xs) var(--spacing-xs);
155
+ color: var(--contrast-color);
156
+ background: var(--main-color);
157
+ border-radius: var(--border-radius);
158
+ box-shadow: var(--elevation-10);
159
+ z-index: 1000;
160
+ transition: var(--transition);
161
+ }
162
+
163
+ &--contrast {
164
+ .wt-tooltip__floating {
165
+ color: var(--main-color);
166
+ background: var(--contrast-color);
167
+ }
168
+ }
169
+ }
170
+
171
+ .wt-tooltip {
172
+ .wt-tooltip__floating {
173
+ opacity: 0;
174
+ pointer-events: none;
175
+ }
176
+
177
+ &--visible {
178
+ .wt-tooltip__floating {
179
+ opacity: 1;
180
+ pointer-events: auto;
181
+ }
182
+ }
66
183
  }
67
184
  </style>
@@ -31,7 +31,7 @@
31
31
  :min="numberMin"
32
32
  :placeholder="placeholder || label"
33
33
  :type="inputType"
34
- :value="value || modelValue"
34
+ :value="inputValue"
35
35
  class="wt-input__input"
36
36
  @input="inputHandler"
37
37
  @keyup="$emit('keyup', $event)"
@@ -80,14 +80,12 @@ export default {
80
80
  props: {
81
81
  value: {
82
82
  type: [String, Number],
83
- default: '',
84
83
  },
85
84
  /**
86
85
  * Current input modelValue (`v-model`)
87
86
  */
88
87
  modelValue: {
89
88
  type: [String, Number],
90
- default: '',
91
89
  },
92
90
  /**
93
91
  * Form input label
@@ -199,6 +197,10 @@ export default {
199
197
  },
200
198
 
201
199
  computed: {
200
+ inputValue() {
201
+ return this.value !== undefined ? this.value : this.modelValue;
202
+ },
203
+
202
204
  hasLabel() {
203
205
  return !!(this.label || this.$slots.label);
204
206
  },