@vue-interface/tooltip 1.0.0-beta.9 → 2.0.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/LICENSE +21 -0
- package/dist/index.d.ts +3 -3
- package/dist/src/Tooltip.vue.d.ts +64 -78
- package/dist/src/TooltipPlugin.d.ts +4 -11
- package/dist/tooltip.js +161 -180
- package/dist/tooltip.js.map +1 -1
- package/dist/tooltip.umd.cjs +1 -1
- package/dist/tooltip.umd.cjs.map +1 -1
- package/index.css +71 -0
- package/index.ts +2 -1
- package/package.json +27 -34
- package/dist/src/Popper.d.ts +0 -82
- package/dist/style.css +0 -1
- package/dist/vite.d.ts +0 -5
- package/src/Popper.ts +0 -118
- package/src/Tooltip.vue +0 -32
- package/src/TooltipPlugin.ts +0 -185
- package/tailwindcss/index.cjs +0 -162
- package/tailwindcss/safelist.cjs +0 -12
package/src/TooltipPlugin.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { App } from 'vue';
|
|
2
|
-
import { h, render } from 'vue';
|
|
3
|
-
import Tooltip from './Tooltip.vue';
|
|
4
|
-
|
|
5
|
-
type TooltipPluginOptions = {
|
|
6
|
-
delay?: number,
|
|
7
|
-
prefix: string,
|
|
8
|
-
triggers: {
|
|
9
|
-
open: string[],
|
|
10
|
-
close: string[],
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default function (app: App, opts: Partial<TooltipPluginOptions> = {}) {
|
|
15
|
-
const tooltips: Map<string,Function> = new Map;
|
|
16
|
-
|
|
17
|
-
const options: TooltipPluginOptions = Object.assign({
|
|
18
|
-
delay: undefined,
|
|
19
|
-
prefix: 'data-tooltip',
|
|
20
|
-
triggers: {
|
|
21
|
-
open: ['mouseover:350'],
|
|
22
|
-
close: ['mouseout:100'],
|
|
23
|
-
}
|
|
24
|
-
}, opts);
|
|
25
|
-
|
|
26
|
-
const prefix = options.prefix.replace(/[-]+$/, '');
|
|
27
|
-
const prefixRegExp = new RegExp(`^${prefix}\-`);
|
|
28
|
-
|
|
29
|
-
function getAttributes(el: Element): Record<string,any> {
|
|
30
|
-
return Array.from(el.attributes)
|
|
31
|
-
.map(a => [a.name, a.value])
|
|
32
|
-
.filter(([key]) => key === 'title' || key.match(prefixRegExp))
|
|
33
|
-
.map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])
|
|
34
|
-
.reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function createTooltip(target: Element, props: Record<string,any> = {}, hash: string): Function {
|
|
38
|
-
const container = document.createElement('template');
|
|
39
|
-
|
|
40
|
-
const vnode = h(Tooltip, Object.assign({
|
|
41
|
-
target,
|
|
42
|
-
show: true
|
|
43
|
-
}, props));
|
|
44
|
-
|
|
45
|
-
render(vnode, container);
|
|
46
|
-
|
|
47
|
-
const [el] = [...container.children];
|
|
48
|
-
|
|
49
|
-
document.body.append(el);
|
|
50
|
-
|
|
51
|
-
return () => {
|
|
52
|
-
tooltips.delete(hash);
|
|
53
|
-
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
vnode.component?.ctx.close();
|
|
56
|
-
|
|
57
|
-
// @todo: Make the animation rate (150) dynamic. Should get value
|
|
58
|
-
// from the CSS transition duration.
|
|
59
|
-
setTimeout(() => el.remove(), 150);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function init(target: Element, props = {}) {
|
|
64
|
-
const properties: Record<string,any> = Object.assign({
|
|
65
|
-
title: target.getAttribute(prefix) || target.getAttribute('title')
|
|
66
|
-
}, props, getAttributes(target));
|
|
67
|
-
|
|
68
|
-
// If the properties don't have a title, ignore this target.
|
|
69
|
-
if(!properties.title || target.hasAttribute(`${prefix}-id`)) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Create a unique "hash" to show the node has been initialized.
|
|
74
|
-
// This prevents double initializing on the same element.
|
|
75
|
-
const hash = Math.random().toString(36).slice(2, 7);
|
|
76
|
-
|
|
77
|
-
// Create the instance vars.
|
|
78
|
-
let tooltip: Function|null, timer: number;
|
|
79
|
-
|
|
80
|
-
//target.setAttribute(prefix, properties.title);
|
|
81
|
-
target.setAttribute(`${prefix}-id`, hash);
|
|
82
|
-
// target.removeAttribute('title');
|
|
83
|
-
|
|
84
|
-
function open(delay = 0) {
|
|
85
|
-
clearTimeout(timer);
|
|
86
|
-
|
|
87
|
-
if(!tooltip) {
|
|
88
|
-
timer = setTimeout(() => {
|
|
89
|
-
// Do a check before creating the tooltip to ensure the dom
|
|
90
|
-
// element still exists. Its possible for the element to
|
|
91
|
-
// be removed after the timeout delay runs.
|
|
92
|
-
if(document.contains(target)) {
|
|
93
|
-
tooltip = createTooltip(target, properties, hash);
|
|
94
|
-
tooltips.set(hash, tooltip);
|
|
95
|
-
}
|
|
96
|
-
}, delay);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function close(delay = 0) {
|
|
101
|
-
clearTimeout(timer);
|
|
102
|
-
|
|
103
|
-
if(tooltip) {
|
|
104
|
-
timer = setTimeout(() => {
|
|
105
|
-
tooltip && tooltip();
|
|
106
|
-
tooltip = null;
|
|
107
|
-
}, delay);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function addEventListener(trigger: string, fn: Function) {
|
|
112
|
-
const [ event, delayString ] = trigger.split(':');
|
|
113
|
-
|
|
114
|
-
target.addEventListener(event, () => fn(Number(delayString || 0)));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
(target.getAttribute(`${prefix}-trigger-open`)?.split(',') || options.triggers.open)
|
|
118
|
-
.map(trigger => addEventListener(trigger, open));
|
|
119
|
-
|
|
120
|
-
(target.getAttribute(`${prefix}-trigger-close`)?.split(',') || options.triggers.close)
|
|
121
|
-
.map(trigger => addEventListener(trigger, close));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
app.mixin({
|
|
125
|
-
mounted() {
|
|
126
|
-
let el = this.$el;
|
|
127
|
-
|
|
128
|
-
if(this.$el instanceof Text) {
|
|
129
|
-
el = this.$el.parentNode;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if(el instanceof HTMLElement) {
|
|
133
|
-
init(el);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Create the tree walker.
|
|
137
|
-
const walker = document.createTreeWalker(
|
|
138
|
-
el,
|
|
139
|
-
NodeFilter.SHOW_ALL,
|
|
140
|
-
(node: Node) => {
|
|
141
|
-
if(!(node instanceof Element)) {
|
|
142
|
-
return NodeFilter.FILTER_REJECT;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return NodeFilter.FILTER_ACCEPT;
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
// Step through and alert all child nodes
|
|
150
|
-
while(walker.nextNode()) {
|
|
151
|
-
if(walker.currentNode instanceof Element) {
|
|
152
|
-
init(<Element> walker.currentNode);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const observer = new MutationObserver((changes) => {
|
|
157
|
-
for(const { removedNodes } of changes) {
|
|
158
|
-
for(const node of removedNodes) {
|
|
159
|
-
for(const el of (node as Element).querySelectorAll(`[${prefix}-id]`)) {
|
|
160
|
-
const tooltip = tooltips.get(
|
|
161
|
-
el.getAttribute(`${prefix}-id`) as string
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
tooltip && tooltip();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
observer.observe(el, { childList: true });
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
app.directive('tooltip', {
|
|
175
|
-
beforeMount(target, binding) {
|
|
176
|
-
init(target, Object.assign({}, binding.modifiers, binding.value));
|
|
177
|
-
},
|
|
178
|
-
beforeUnmount(target) {
|
|
179
|
-
const id = target.getAttribute(`${prefix}-id`);
|
|
180
|
-
const tooltip = tooltips.get(id);
|
|
181
|
-
|
|
182
|
-
tooltip && tooltip();
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
package/tailwindcss/index.cjs
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
const plugin = require('tailwindcss/plugin');
|
|
2
|
-
const { colors } = require('tailwindcss/defaultTheme');
|
|
3
|
-
|
|
4
|
-
module.exports = plugin(function({ addComponents, theme }) {
|
|
5
|
-
const tooltipTop = {
|
|
6
|
-
'.bs-tooltip-top': {
|
|
7
|
-
padding: `${theme('tooltip.arrow.height')} 0`,
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
'.bs-tooltip-top .tooltip-arrow': {
|
|
11
|
-
bottom: '1px',
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
'.bs-tooltip-top .tooltip-arrow::before': {
|
|
15
|
-
bottom: '1px',
|
|
16
|
-
borderWidth: `${theme('tooltip.arrow.height')} calc(${theme('tooltip.arrow.width')} / 2) 0`,
|
|
17
|
-
borderTopColor: theme('tooltip.arrow.color'),
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const tooltipBottom = {
|
|
22
|
-
'.bs-tooltip-bottom': {
|
|
23
|
-
padding: `${theme('tooltip.arrow.height')} 0`,
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
'.bs-tooltip-bottom .tooltip-arrow': {
|
|
27
|
-
top: '1px'
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
'.bs-tooltip-bottom .tooltip-arrow::before': {
|
|
31
|
-
top: '1px',
|
|
32
|
-
borderWidth: `0 calc(${theme('tooltip.arrow.width')} / 2) ${theme('tooltip.arrow.height')}`,
|
|
33
|
-
borderBottomColor: theme('tooltip.arrow.color'),
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const tooltipLeft = {
|
|
38
|
-
'.bs-tooltip-left': {
|
|
39
|
-
padding: `0 ${theme('tooltip.arrow.height')}`
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
'.bs-tooltip-left .tooltip-arrow': {
|
|
43
|
-
right: '1px',
|
|
44
|
-
width: theme('tooltip.arrow.height'),
|
|
45
|
-
height: theme('tooltip.arrow.width')
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
'.bs-tooltip-left .tooltip-arrow::before': {
|
|
49
|
-
right: '1px',
|
|
50
|
-
borderWidth: `calc(${theme('tooltip.arrow.width')} / 2) 0 calc(${theme('tooltip.arrow.width')} / 2) ${theme('tooltip.arrow.height')}`,
|
|
51
|
-
borderLeftColor: theme('tooltip.arrow.color')
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const tooltipRight = {
|
|
56
|
-
'.bs-tooltip-right': {
|
|
57
|
-
padding: `0 ${theme('tooltip.arrow.height')}`
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
'.bs-tooltip-right .tooltip-arrow': {
|
|
61
|
-
left: '1px',
|
|
62
|
-
width: theme('tooltip.arrow.height'),
|
|
63
|
-
height: theme('tooltip.arrow.width'),
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
'.bs-tooltip-right .tooltip-arrow::before': {
|
|
67
|
-
left: '1px',
|
|
68
|
-
borderWidth: `calc(${theme('tooltip.arrow.width')} / 2) ${theme('tooltip.arrow.height')} calc(${theme('tooltip.arrow.width')} / 2) 0`,
|
|
69
|
-
borderRightColor: theme('tooltip.arrow.color'),
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const tooltip = {
|
|
74
|
-
// Base class
|
|
75
|
-
'.tooltip': {
|
|
76
|
-
position: 'absolute',
|
|
77
|
-
zIndex: theme('tooltip.zIndex'),
|
|
78
|
-
display: 'block',
|
|
79
|
-
margin: theme('tooltip.margin'),
|
|
80
|
-
// Our parent element can be arbitrary since tooltips are by default inserted as a sibling of their target element.
|
|
81
|
-
// So reset our font and text properties to avoid inheriting weird values.
|
|
82
|
-
fontSize: theme('tooltip.fontSize'),
|
|
83
|
-
// Allow breaking very long words so they don't overflow the tooltip's bounds
|
|
84
|
-
wordWrap: 'break-word',
|
|
85
|
-
opacity: 0,
|
|
86
|
-
transition: theme('tooltip.transition')
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
'.tooltip.show': { opacity: theme('tooltip.opacity') },
|
|
90
|
-
|
|
91
|
-
'.tooltip .tooltip-arrow': {
|
|
92
|
-
position: 'absolute',
|
|
93
|
-
display: 'block',
|
|
94
|
-
width: theme('tooltip.arrow.width'),
|
|
95
|
-
height: theme('tooltip.arrow.height'),
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
'.tooltip .tooltip-arrow::before': {
|
|
99
|
-
position: 'absolute',
|
|
100
|
-
content: '""',
|
|
101
|
-
borderColor: 'transparent',
|
|
102
|
-
borderStyle: 'solid',
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
...tooltipTop,
|
|
106
|
-
...tooltipBottom,
|
|
107
|
-
...tooltipLeft,
|
|
108
|
-
...tooltipRight,
|
|
109
|
-
|
|
110
|
-
'.bs-tooltip-auto[x-placement^="top"]': {
|
|
111
|
-
...tooltipTop
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
'.bs-tooltip-auto[x-placement^="bottom"]': {
|
|
115
|
-
...tooltipBottom
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
'.bs-tooltip-auto[x-placement^="left"]': {
|
|
119
|
-
...tooltipLeft
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
'.bs-tooltip-auto[x-placement^="right"]': {
|
|
123
|
-
...tooltipRight
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
// Wrapper for the tooltip content
|
|
127
|
-
'.tooltip-inner': {
|
|
128
|
-
maxWidth: theme('tooltip.maxWidth'),
|
|
129
|
-
padding: `${theme('tooltip.paddingY')} ${theme('tooltip.paddingX')}`,
|
|
130
|
-
color: theme('tooltip.color'),
|
|
131
|
-
textAlign: 'center',
|
|
132
|
-
backgroundColor: theme('tooltip.backgroundColor'),
|
|
133
|
-
borderRadius: theme('tooltip.borderRadius')
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
addComponents(tooltip);
|
|
138
|
-
}, {
|
|
139
|
-
theme: {
|
|
140
|
-
tooltip: theme => {
|
|
141
|
-
return {
|
|
142
|
-
fontSize: '.875rem',
|
|
143
|
-
maxWidth: '200px',
|
|
144
|
-
color: theme('colors.white', colors.white),
|
|
145
|
-
backgroundColor: theme('colors.black', colors.black),
|
|
146
|
-
borderRadius: '.25rem',
|
|
147
|
-
opacity: .9,
|
|
148
|
-
paddingY: '.25rem',
|
|
149
|
-
paddingX: '.5rem',
|
|
150
|
-
margin: 0,
|
|
151
|
-
zIndex: theme('interface.zIndex.tooltip', 1070),
|
|
152
|
-
transition: 'opacity .15s ease-out',
|
|
153
|
-
|
|
154
|
-
arrow: {
|
|
155
|
-
width: '.8rem',
|
|
156
|
-
height: '.4rem',
|
|
157
|
-
color: theme('colors.black', colors.black),
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
package/tailwindcss/safelist.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const plugin = require('tailwindcss/plugin');
|
|
2
|
-
const { colors } = require('tailwindcss/defaultTheme');
|
|
3
|
-
|
|
4
|
-
module.exports = () => [
|
|
5
|
-
'tooltip',
|
|
6
|
-
'tooltip-arrow',
|
|
7
|
-
'tooltip-inner',
|
|
8
|
-
'bs-tooltip-top',
|
|
9
|
-
'bs-tooltip-left',
|
|
10
|
-
'bs-tooltip-right',
|
|
11
|
-
'bs-tooltip-bottom',
|
|
12
|
-
]
|