@redseed/redseed-ui-vue3 8.13.4 → 8.14.0

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.4",
3
+ "version": "8.14.0",
4
4
  "description": "RedSeed UI Vue 3 components",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/redseedtraining/redseed-ui",
@@ -46,7 +46,7 @@ const props = defineProps({
46
46
  type: Boolean,
47
47
  default: false,
48
48
  },
49
- redseedClassic: {
49
+ classic: {
50
50
  type: Boolean,
51
51
  default: false,
52
52
  },
@@ -68,7 +68,7 @@ const defaultColor = computed(
68
68
  !props.info &&
69
69
  !props.ai &&
70
70
  !props.skillscheck &&
71
- !props.redseedClassic &&
71
+ !props.classic &&
72
72
  !props.coach,
73
73
  )
74
74
 
@@ -86,7 +86,7 @@ const badgeClass = computed(() => [
86
86
  'rsui-badge--info': props.info,
87
87
  'rsui-badge--ai': props.ai,
88
88
  'rsui-badge--skillscheck': props.skillscheck,
89
- 'rsui-badge--redseed-classic': props.redseedClassic,
89
+ 'rsui-badge--classic': props.classic,
90
90
  'rsui-badge--coach': props.coach,
91
91
  },
92
92
  ])
@@ -0,0 +1,176 @@
1
+ <script setup>
2
+ import { ref, computed, 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
+ let hoverTimeout = null
56
+
57
+ const defaultSize = computed(() => !props.xs && !props.sm && !props.md)
58
+
59
+ const defaultColor = computed(
60
+ () =>
61
+ !props.secondary &&
62
+ !props.info &&
63
+ !props.success &&
64
+ !props.warning &&
65
+ !props.error &&
66
+ !props.skillscheck &&
67
+ !props.coach,
68
+ )
69
+
70
+ const triggerClass = computed(() => [
71
+ 'rsui-tooltip__trigger',
72
+ {
73
+ 'rsui-tooltip__trigger--xs': props.xs,
74
+ 'rsui-tooltip__trigger--sm': props.sm || defaultSize.value,
75
+ 'rsui-tooltip__trigger--md': props.md,
76
+ 'rsui-tooltip__trigger--secondary': props.secondary || defaultColor.value,
77
+ 'rsui-tooltip__trigger--info': props.info,
78
+ 'rsui-tooltip__trigger--success': props.success,
79
+ 'rsui-tooltip__trigger--warning': props.warning,
80
+ 'rsui-tooltip__trigger--error': props.error,
81
+ 'rsui-tooltip__trigger--skillscheck': props.skillscheck,
82
+ 'rsui-tooltip__trigger--coach': props.coach,
83
+ },
84
+ ])
85
+
86
+ const contentClass = computed(() => [
87
+ 'rsui-tooltip__content',
88
+ `rsui-tooltip__content--${props.position}`,
89
+ ])
90
+
91
+ function open() {
92
+ clearTimeout(hoverTimeout)
93
+ isOpen.value = true
94
+ }
95
+
96
+ function close() {
97
+ clearTimeout(hoverTimeout)
98
+ isOpen.value = false
99
+ }
100
+
101
+ function onMouseEnter() {
102
+ clearTimeout(hoverTimeout)
103
+ hoverTimeout = setTimeout(() => {
104
+ isOpen.value = true
105
+ }, 100)
106
+ }
107
+
108
+ function onMouseLeave() {
109
+ clearTimeout(hoverTimeout)
110
+ hoverTimeout = setTimeout(() => {
111
+ isOpen.value = false
112
+ }, 150)
113
+ }
114
+
115
+ function toggle() {
116
+ isOpen.value = !isOpen.value
117
+ }
118
+
119
+ function closeOnEscape(e) {
120
+ if (isOpen.value && e.key === 'Escape') {
121
+ isOpen.value = false
122
+ }
123
+ }
124
+
125
+ onMounted(() => document.addEventListener('keydown', closeOnEscape))
126
+ onUnmounted(() => {
127
+ document.removeEventListener('keydown', closeOnEscape)
128
+ clearTimeout(hoverTimeout)
129
+ })
130
+ </script>
131
+ <template>
132
+ <div
133
+ ref="tooltipRef"
134
+ class="rsui-tooltip"
135
+ @mouseenter="onMouseEnter"
136
+ @mouseleave="onMouseLeave"
137
+ >
138
+ <slot name="trigger" :toggle="toggle" :open="open" :close="close">
139
+ <button
140
+ :class="triggerClass"
141
+ type="button"
142
+ @click="toggle"
143
+ @focus="open"
144
+ @blur="close"
145
+ aria-label="More information"
146
+ >
147
+ <InformationCircleIcon />
148
+ </button>
149
+ </slot>
150
+
151
+ <Teleport to="body">
152
+ <div
153
+ v-show="isOpen"
154
+ class="rsui-tooltip__overlay"
155
+ @click="close"
156
+ ></div>
157
+ </Teleport>
158
+
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"
171
+ >
172
+ <slot></slot>
173
+ </div>
174
+ </transition>
175
+ </div>
176
+ </template>
@@ -0,0 +1,5 @@
1
+ import Tooltip from './Tooltip.vue'
2
+
3
+ export {
4
+ Tooltip
5
+ }