@data-slot/tooltip 0.1.0 → 0.1.2
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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +17 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)];let n=0;const r=(e,t)=>e.id||=`${t}-${++n}`,i=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),a=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let o=0;const s=300;function c(t,n={}){let{delay:c=300,skipDelayDuration:l=s,onOpenChange:u}=n,d=e(t,`tooltip-trigger`),f=e(t,`tooltip-content`);if(!d||!f)throw Error(`Tooltip requires trigger and content slots`);let p=n.position??f.dataset.position??`top`,m=!1,h=null,g=[],_=r(f,`tooltip-content`);d.setAttribute(`aria-describedby`,_),f.setAttribute(`role`,`tooltip`),f.setAttribute(`data-position`,p);let v=(e,n=!1)=>{m!==e&&(m=e,f.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),n&&m?f.setAttribute(`data-instant`,``):f.removeAttribute(`data-instant`),a(t,`tooltip:change`,{open:m}),u?.(m))},y=()=>{if(h)return;let e=Date.now();if(e<o){v(!0,!0);return}h=setTimeout(()=>{v(!0,!1),h=null},c)},b=()=>{h&&(clearTimeout(h),h=null),m&&l>0&&(o=Date.now()+l),v(!1)};f.hidden=!0,t.setAttribute(`data-state`,`closed`),g.push(i(d,`mouseenter`,y),i(d,`mouseleave`,b),i(d,`focus`,y),i(d,`blur`,b)),g.push(i(document,`keydown`,e=>{m&&e.key===`Escape`&&b()}));let x={show:()=>{h&&(clearTimeout(h),h=null),v(!0)},hide:b,get isOpen(){return m},destroy:()=>{h&&clearTimeout(h),g.forEach(e=>e()),g.length=0}};return x}const l=new WeakSet;function u(e=document){let n=[];for(let r of t(e,`tooltip`)){if(l.has(r))continue;l.add(r),n.push(c(r))}return n}exports.create=u,exports.createTooltip=c;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)];let n=0;const r=(e,t)=>e.id||=`${t}-${++n}`,i=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),a=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let o=0;const s=300;function c(t,n={}){let{delay:c=300,skipDelayDuration:l=s,onOpenChange:u}=n,d=e(t,`tooltip-trigger`),f=e(t,`tooltip-content`);if(!d||!f)throw Error(`Tooltip requires trigger and content slots`);let p=n.position??f.dataset.position??`top`,m=!1,h=null,g=[],_=r(f,`tooltip-content`);d.setAttribute(`aria-describedby`,_),f.setAttribute(`role`,`tooltip`),f.setAttribute(`data-position`,p);let v=(e,n=!1)=>{m!==e&&(m=e,f.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),n&&m?f.setAttribute(`data-instant`,``):f.removeAttribute(`data-instant`),a(t,`tooltip:change`,{open:m}),u?.(m))},y=()=>{if(h)return;let e=Date.now();if(e<o){v(!0,!0);return}h=setTimeout(()=>{v(!0,!1),h=null},c)},b=()=>{h&&(clearTimeout(h),h=null),m&&l>0&&(o=Date.now()+l),v(!1)};f.hidden=!0,t.setAttribute(`data-state`,`closed`),g.push(i(d,`mouseenter`,y),i(d,`mouseleave`,b),i(d,`focus`,y),i(d,`blur`,b)),g.push(i(document,`keydown`,e=>{m&&e.key===`Escape`&&b()}));let x={show:()=>{h&&(clearTimeout(h),h=null),v(!0)},hide:b,get isOpen(){return m},destroy:()=>{h&&clearTimeout(h),g.forEach(e=>e()),g.length=0}};return x}const l=new WeakSet;function u(e=document){let n=[];for(let r of t(e,`tooltip`)){if(l.has(r))continue;l.add(r),n.push(c(r))}return n}export{u as create,c as createTooltip};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-slot/tooltip",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,13 +18,26 @@
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
"files": [
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
22
24
|
"scripts": {
|
|
23
25
|
"build": "tsdown"
|
|
24
26
|
},
|
|
25
|
-
"
|
|
27
|
+
"devDependencies": {
|
|
26
28
|
"@data-slot/core": "workspace:*"
|
|
27
29
|
},
|
|
28
|
-
"
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/bejamas/data-slot",
|
|
33
|
+
"directory": "packages/tooltip"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"headless",
|
|
37
|
+
"ui",
|
|
38
|
+
"tooltip",
|
|
39
|
+
"vanilla",
|
|
40
|
+
"data-slot"
|
|
41
|
+
],
|
|
29
42
|
"license": "MIT"
|
|
30
43
|
}
|