@redseed/redseed-ui-vue3 8.14.0 → 8.14.1

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": "@redseed/redseed-ui-vue3",
3
- "version": "8.14.0",
3
+ "version": "8.14.1",
4
4
  "description": "RedSeed UI Vue 3 components",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/redseedtraining/redseed-ui",
@@ -1,5 +1,5 @@
1
1
  <script setup>
2
- import { ref, computed, onMounted, onUnmounted } from 'vue'
2
+ import { ref, computed, watch, nextTick, onMounted, onUnmounted } from 'vue'
3
3
  import { InformationCircleIcon } from '@heroicons/vue/24/outline'
4
4
 
5
5
  const props = defineProps({
@@ -52,6 +52,8 @@ const props = defineProps({
52
52
 
53
53
  const isOpen = ref(false)
54
54
  const tooltipRef = ref(null)
55
+ const contentRef = ref(null)
56
+ const contentStyle = ref({})
55
57
  let hoverTimeout = null
56
58
 
57
59
  const defaultSize = computed(() => !props.xs && !props.sm && !props.md)
@@ -83,11 +85,6 @@ const triggerClass = computed(() => [
83
85
  },
84
86
  ])
85
87
 
86
- const contentClass = computed(() => [
87
- 'rsui-tooltip__content',
88
- `rsui-tooltip__content--${props.position}`,
89
- ])
90
-
91
88
  function open() {
92
89
  clearTimeout(hoverTimeout)
93
90
  isOpen.value = true
@@ -116,6 +113,42 @@ function toggle() {
116
113
  isOpen.value = !isOpen.value
117
114
  }
118
115
 
116
+ function updatePosition() {
117
+ if (!tooltipRef.value) return
118
+ const rect = tooltipRef.value.getBoundingClientRect()
119
+ const style = { position: 'fixed', zIndex: 50 }
120
+
121
+ if (props.position === 'top') {
122
+ style.left = `${rect.left + rect.width / 2}px`
123
+ style.top = `${rect.top}px`
124
+ style.transform = 'translate(-50%, -100%)'
125
+ style.marginTop = '-8px'
126
+ } else if (props.position === 'bottom') {
127
+ style.left = `${rect.left + rect.width / 2}px`
128
+ style.top = `${rect.bottom}px`
129
+ style.transform = 'translate(-50%, 0)'
130
+ style.marginTop = '8px'
131
+ } else if (props.position === 'left') {
132
+ style.left = `${rect.left}px`
133
+ style.top = `${rect.top + rect.height / 2}px`
134
+ style.transform = 'translate(-100%, -50%)'
135
+ style.marginLeft = '-8px'
136
+ } else if (props.position === 'right') {
137
+ style.left = `${rect.right}px`
138
+ style.top = `${rect.top + rect.height / 2}px`
139
+ style.transform = 'translate(0, -50%)'
140
+ style.marginLeft = '8px'
141
+ }
142
+
143
+ contentStyle.value = style
144
+ }
145
+
146
+ watch(isOpen, (val) => {
147
+ if (val) {
148
+ nextTick(() => updatePosition())
149
+ }
150
+ })
151
+
119
152
  function closeOnEscape(e) {
120
153
  if (isOpen.value && e.key === 'Escape') {
121
154
  isOpen.value = false
@@ -156,21 +189,25 @@ onUnmounted(() => {
156
189
  ></div>
157
190
  </Teleport>
158
191
 
159
- <transition
160
- enter-active-class="rsui-tooltip__transition--enter-active"
161
- enter-from-class="rsui-tooltip__transition--enter-from"
162
- enter-to-class="rsui-tooltip__transition--enter-to"
163
- leave-active-class="rsui-tooltip__transition--leave-active"
164
- leave-from-class="rsui-tooltip__transition--leave-from"
165
- leave-to-class="rsui-tooltip__transition--leave-to"
166
- >
167
- <div
168
- v-show="isOpen"
169
- :class="contentClass"
170
- role="tooltip"
192
+ <Teleport to="body">
193
+ <transition
194
+ enter-active-class="rsui-tooltip__transition--enter-active"
195
+ enter-from-class="rsui-tooltip__transition--enter-from"
196
+ enter-to-class="rsui-tooltip__transition--enter-to"
197
+ leave-active-class="rsui-tooltip__transition--leave-active"
198
+ leave-from-class="rsui-tooltip__transition--leave-from"
199
+ leave-to-class="rsui-tooltip__transition--leave-to"
171
200
  >
172
- <slot></slot>
173
- </div>
174
- </transition>
201
+ <div
202
+ v-show="isOpen"
203
+ ref="contentRef"
204
+ class="rsui-tooltip__content"
205
+ :style="contentStyle"
206
+ role="tooltip"
207
+ >
208
+ <slot></slot>
209
+ </div>
210
+ </transition>
211
+ </Teleport>
175
212
  </div>
176
213
  </template>