@redseed/redseed-ui-vue3 8.13.5 → 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/index.js CHANGED
@@ -41,4 +41,5 @@ export * from './src/components/Sorting'
41
41
  export * from './src/components/Switcher'
42
42
  export * from './src/components/Table'
43
43
  export * from './src/components/Toggle'
44
+ export * from './src/components/Tooltip'
44
45
  export * from './src/helpers'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redseed/redseed-ui-vue3",
3
- "version": "8.13.5",
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",
@@ -0,0 +1,213 @@
1
+ <script setup>
2
+ import { ref, computed, watch, nextTick, onMounted, onUnmounted } from 'vue'
3
+ import { InformationCircleIcon } from '@heroicons/vue/24/outline'
4
+
5
+ const props = defineProps({
6
+ position: {
7
+ type: String,
8
+ default: 'top',
9
+ validator: (value) => ['top', 'right', 'bottom', 'left'].includes(value),
10
+ },
11
+ xs: {
12
+ type: Boolean,
13
+ default: false,
14
+ },
15
+ sm: {
16
+ type: Boolean,
17
+ default: false,
18
+ },
19
+ md: {
20
+ type: Boolean,
21
+ default: false,
22
+ },
23
+ secondary: {
24
+ type: Boolean,
25
+ default: false,
26
+ },
27
+ info: {
28
+ type: Boolean,
29
+ default: false,
30
+ },
31
+ success: {
32
+ type: Boolean,
33
+ default: false,
34
+ },
35
+ warning: {
36
+ type: Boolean,
37
+ default: false,
38
+ },
39
+ error: {
40
+ type: Boolean,
41
+ default: false,
42
+ },
43
+ skillscheck: {
44
+ type: Boolean,
45
+ default: false,
46
+ },
47
+ coach: {
48
+ type: Boolean,
49
+ default: false,
50
+ },
51
+ })
52
+
53
+ const isOpen = ref(false)
54
+ const tooltipRef = ref(null)
55
+ const contentRef = ref(null)
56
+ const contentStyle = ref({})
57
+ let hoverTimeout = null
58
+
59
+ const defaultSize = computed(() => !props.xs && !props.sm && !props.md)
60
+
61
+ const defaultColor = computed(
62
+ () =>
63
+ !props.secondary &&
64
+ !props.info &&
65
+ !props.success &&
66
+ !props.warning &&
67
+ !props.error &&
68
+ !props.skillscheck &&
69
+ !props.coach,
70
+ )
71
+
72
+ const triggerClass = computed(() => [
73
+ 'rsui-tooltip__trigger',
74
+ {
75
+ 'rsui-tooltip__trigger--xs': props.xs,
76
+ 'rsui-tooltip__trigger--sm': props.sm || defaultSize.value,
77
+ 'rsui-tooltip__trigger--md': props.md,
78
+ 'rsui-tooltip__trigger--secondary': props.secondary || defaultColor.value,
79
+ 'rsui-tooltip__trigger--info': props.info,
80
+ 'rsui-tooltip__trigger--success': props.success,
81
+ 'rsui-tooltip__trigger--warning': props.warning,
82
+ 'rsui-tooltip__trigger--error': props.error,
83
+ 'rsui-tooltip__trigger--skillscheck': props.skillscheck,
84
+ 'rsui-tooltip__trigger--coach': props.coach,
85
+ },
86
+ ])
87
+
88
+ function open() {
89
+ clearTimeout(hoverTimeout)
90
+ isOpen.value = true
91
+ }
92
+
93
+ function close() {
94
+ clearTimeout(hoverTimeout)
95
+ isOpen.value = false
96
+ }
97
+
98
+ function onMouseEnter() {
99
+ clearTimeout(hoverTimeout)
100
+ hoverTimeout = setTimeout(() => {
101
+ isOpen.value = true
102
+ }, 100)
103
+ }
104
+
105
+ function onMouseLeave() {
106
+ clearTimeout(hoverTimeout)
107
+ hoverTimeout = setTimeout(() => {
108
+ isOpen.value = false
109
+ }, 150)
110
+ }
111
+
112
+ function toggle() {
113
+ isOpen.value = !isOpen.value
114
+ }
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
+
152
+ function closeOnEscape(e) {
153
+ if (isOpen.value && e.key === 'Escape') {
154
+ isOpen.value = false
155
+ }
156
+ }
157
+
158
+ onMounted(() => document.addEventListener('keydown', closeOnEscape))
159
+ onUnmounted(() => {
160
+ document.removeEventListener('keydown', closeOnEscape)
161
+ clearTimeout(hoverTimeout)
162
+ })
163
+ </script>
164
+ <template>
165
+ <div
166
+ ref="tooltipRef"
167
+ class="rsui-tooltip"
168
+ @mouseenter="onMouseEnter"
169
+ @mouseleave="onMouseLeave"
170
+ >
171
+ <slot name="trigger" :toggle="toggle" :open="open" :close="close">
172
+ <button
173
+ :class="triggerClass"
174
+ type="button"
175
+ @click="toggle"
176
+ @focus="open"
177
+ @blur="close"
178
+ aria-label="More information"
179
+ >
180
+ <InformationCircleIcon />
181
+ </button>
182
+ </slot>
183
+
184
+ <Teleport to="body">
185
+ <div
186
+ v-show="isOpen"
187
+ class="rsui-tooltip__overlay"
188
+ @click="close"
189
+ ></div>
190
+ </Teleport>
191
+
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"
200
+ >
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>
212
+ </div>
213
+ </template>
@@ -0,0 +1,5 @@
1
+ import Tooltip from './Tooltip.vue'
2
+
3
+ export {
4
+ Tooltip
5
+ }