Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-tooltip

Package Overview
Dependencies
Maintainers
8
Versions
268
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-tooltip - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2-rc.1

2

dist/index.js

@@ -1,2 +0,2 @@

var e,t=require("@radix-ui/react-id").useId,o=v({},require("@radix-ui/react-visually-hidden")),n=require("@radix-ui/react-slot").Slottable,r=require("@radix-ui/react-portal").Portal,i=require("@radix-ui/react-popper"),s=v({},i),a=i.createPopperScope,c=require("@radix-ui/react-primitive").Primitive,l=require("@radix-ui/react-presence").Presence,u=require("@radix-ui/react-use-rect").useRect,d=require("@radix-ui/react-use-previous").usePrevious,p=require("@radix-ui/react-use-layout-effect").useLayoutEffect,f=require("@radix-ui/react-use-escape-keydown").useEscapeKeydown,g=require("@radix-ui/react-use-controllable-state").useControllableState,E=require("@radix-ui/react-context").createContextScope,y=require("@radix-ui/react-compose-refs").useComposedRefs,x=require("@radix-ui/primitive").composeEventHandlers,T=v({},require("react")),m=(e=require("@babel/runtime/helpers/extends"))&&e.__esModule?e.default:e;function v(e,t){return Object.keys(t).forEach((function(o){"default"!==o&&"__esModule"!==o&&Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[o]}})})),e}function C(e){return{type:"machine.actions.assign",assign:e}}let _,b;const D=C(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),w=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],s=a=>{var c,l;const u=e.states[n],d=a.type,p=null===(c=e.on)||void 0===c?void 0:c[d],f=null===(l=u.on)||void 0===l?void 0:l[d],g=null!=p?p:f;if(void 0===g)o&&console.warn(`From state: "${n}", event "${d}" has no transition to any state`);else{const{target:o,actions:c=[],cond:l=(()=>!0)}=g,d=o?e.states[o]:{};if(l(r,a)){const e=(u.exit||[]).concat(c,d.entry||[]);r=function(e,t,o){let n=o;return null==e||e.forEach((e=>{"function"==typeof e?e(n,t,s):"machine.actions.assign"===e.type&&(n=e.assign(n,t))})),n}(e,a,r),o&&(n=o,t&&(console.group("event:",a),console.log("state:",n),console.log("context:",r),console.groupEnd()),i.forEach((e=>e({state:n,context:r}))))}}};return{subscribe:function(e){return i.push(e),()=>{i.splice(i.indexOf(e),1)}},send:s,getContext:function(){return r}}}({initial:"closed",context:{id:null,delayed:!1},on:{FOCUS:{target:"open"}},states:{closed:{entry:[C((e=>({...e,id:null})))],on:{OPEN:{target:"opening"}}},opening:{entry:[(e,t,o)=>{const n=t.delayDuration,r=()=>o({type:"DELAY_TIMER_END"});void 0===n?r():_=window.setTimeout(r,n)},D,C((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(_)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[D],exit:[C((e=>({...e,delayed:!1})))],on:{OPEN:{target:"open"},CLOSE:{target:"closing",cond:(e,t)=>e.id===t.id}}},closing:{entry:[(e,t,o)=>{var n;const r=null!==(n=t.skipDelayDuration)&&void 0!==n?n:300;b=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(b)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[h,O]=E("Tooltip",[a]);exports.createTooltipScope=O;const q=a(),[M,P]=h("Tooltip"),S=e=>{const{__scopeTooltip:o,children:n,open:r,defaultOpen:i=!1,onOpenChange:a,delayDuration:c=700,skipDelayDuration:l=300}=e,u=q(o),[d,f]=T.useState(null),E=t(),[y=!1,x]=g({prop:r,defaultProp:i,onChange:a}),[m,v]=T.useState(r?"instant-open":"closed");T.useEffect((()=>w.subscribe((({state:e,context:t})=>{"open"===e&&t.id===E?x(!0):x(!1)}))),[E,x]),T.useEffect((()=>w.subscribe((({state:e,context:t})=>{t.id===E?v("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):v("closed")}))),[E]);const C=T.useCallback((()=>w.send({type:"FOCUS",id:E})),[E]),_=T.useCallback((()=>w.send({type:"OPEN",id:E,delayDuration:c})),[E,c]),b=T.useCallback((()=>w.send({type:"CLOSE",id:E,skipDelayDuration:l})),[l,E]);return T.useEffect((()=>()=>b()),[b]),p((()=>{!0===r&&w.send({type:"OPEN",id:E})}),[E,r]),/*#__PURE__*/T.createElement(s.Root,u,/*#__PURE__*/T.createElement(M,{scope:o,contentId:E,open:y,stateAttribute:m,trigger:d,onTriggerChange:f,onFocus:C,onOpen:_,onClose:b},n))};exports.Tooltip=S;const R=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=P("TooltipTrigger",o),i=q(o),a=y(t,r.onTriggerChange);/*#__PURE__*/return T.createElement(s.Anchor,m({asChild:!0},i),/*#__PURE__*/T.createElement(c.button,m({type:"button","aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute},n,{ref:a,onMouseEnter:x(e.onMouseEnter,r.onOpen),onMouseLeave:x(e.onMouseLeave,r.onClose),onMouseDown:x(e.onMouseDown,r.onClose),onFocus:x(e.onFocus,r.onFocus),onBlur:x(e.onBlur,r.onClose),onKeyDown:x(e.onKeyDown,(e=>{"Enter"!==e.key&&" "!==e.key||r.onClose()}))})))}));exports.TooltipTrigger=R;const k=/*#__PURE__*/T.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=P("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return T.createElement(l,{present:o||r.open},/*#__PURE__*/T.createElement(A,m({ref:t},n)))}));exports.TooltipContent=k;const A=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:i,children:a,"aria-label":c,portalled:l=!0,...u}=e,d=P("TooltipContent",i),p=q(i),g=l?r:T.Fragment;return f((()=>d.onClose())),/*#__PURE__*/T.createElement(g,null,/*#__PURE__*/T.createElement(L,{__scopeTooltip:i}),/*#__PURE__*/T.createElement(s.Content,m({"data-state":d.stateAttribute},p,u,{ref:t,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/T.createElement(n,null,a),/*#__PURE__*/T.createElement(o.Root,{id:d.contentId,role:"tooltip"},c||a)))})),I=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=q(o);/*#__PURE__*/return T.createElement(s.Arrow,m({},r,n,{ref:t}))}));/*#__PURE__*/function L(e){const{__scopeTooltip:t}=e,o=P("CheckTriggerMoved",t),n=u(o.trigger),r=null==n?void 0:n.left,i=d(r),s=null==n?void 0:n.top,a=d(s),c=o.onClose;return T.useEffect((()=>{(void 0!==i&&i!==r||void 0!==a&&a!==s)&&c()}),[c,i,a,r,s]),null}exports.TooltipArrow=I;const N=S;exports.Root=N;const F=R;exports.Trigger=F;const K=k;exports.Content=K;const Y=I;exports.Arrow=Y;
var e,t=require("@radix-ui/react-id").useId,o=m({},require("@radix-ui/react-visually-hidden")),n=require("@radix-ui/react-slot").Slottable,r=require("@radix-ui/react-portal").Portal,i=require("@radix-ui/react-popper"),s=m({},i),a=i.createPopperScope,c=require("@radix-ui/react-primitive").Primitive,l=require("@radix-ui/react-presence").Presence,u=require("@radix-ui/react-use-rect").useRect,d=require("@radix-ui/react-use-previous").usePrevious,p=require("@radix-ui/react-use-layout-effect").useLayoutEffect,f=require("@radix-ui/react-use-escape-keydown").useEscapeKeydown,g=require("@radix-ui/react-use-controllable-state").useControllableState,E=require("@radix-ui/react-context").createContextScope,x=require("@radix-ui/react-compose-refs").useComposedRefs,y=require("@radix-ui/primitive").composeEventHandlers,C=m({},require("react")),T=(e=require("@babel/runtime/helpers/extends"))&&e.__esModule?e.default:e;function m(e,t){return Object.keys(t).forEach((function(o){"default"!==o&&"__esModule"!==o&&Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[o]}})})),e}function v(e){return{type:"machine.actions.assign",assign:e}}let _,b;const D=v(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),h=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],s=a=>{var c,l;const u=e.states[n],d=a.type,p=null===(c=e.on)||void 0===c?void 0:c[d],f=null===(l=u.on)||void 0===l?void 0:l[d],g=null!=p?p:f;if(void 0===g)o&&console.warn(`From state: "${n}", event "${d}" has no transition to any state`);else{const{target:o,actions:c=[],cond:l=(()=>!0)}=g,d=o?e.states[o]:{};if(l(r,a)){const e=(u.exit||[]).concat(c,d.entry||[]);r=function(e,t,o){let n=o;return null==e||e.forEach((e=>{"function"==typeof e?e(n,t,s):"machine.actions.assign"===e.type&&(n=e.assign(n,t))})),n}(e,a,r),o&&(n=o,t&&(console.group("event:",a),console.log("state:",n),console.log("context:",r),console.groupEnd()),i.forEach((e=>e({state:n,context:r}))))}}};return{subscribe:function(e){return i.push(e),()=>{i.splice(i.indexOf(e),1)}},send:s,getContext:function(){return r}}}({initial:"closed",context:{id:null,delayed:!1},on:{FOCUS:{target:"open"}},states:{closed:{entry:[v((e=>({...e,id:null})))],on:{OPEN:{target:"opening"}}},opening:{entry:[(e,t,o)=>{const n=t.delayDuration,r=()=>o({type:"DELAY_TIMER_END"});void 0===n?r():_=window.setTimeout(r,n)},D,v((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(_)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[D],exit:[v((e=>({...e,delayed:!1})))],on:{OPEN:{target:"open"},CLOSE:{target:"closing",cond:(e,t)=>e.id===t.id}}},closing:{entry:[(e,t,o)=>{var n;const r=null!==(n=t.skipDelayDuration)&&void 0!==n?n:300;b=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(b)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[w,O]=E("Tooltip",[a]);exports.createTooltipScope=O;const q=a(),[M,P]=w("Tooltip"),S=e=>{const{__scopeTooltip:o,children:n,open:r,defaultOpen:i=!1,onOpenChange:a,delayDuration:c=700,skipDelayDuration:l=300}=e,u=q(o),[d,f]=C.useState(null),E=t(),[x=!1,y]=g({prop:r,defaultProp:i,onChange:a}),[T,m]=C.useState(r?"instant-open":"closed");C.useEffect((()=>h.subscribe((({state:e,context:t})=>{"open"===e&&t.id===E?y(!0):y(!1)}))),[E,y]),C.useEffect((()=>h.subscribe((({state:e,context:t})=>{t.id===E?m("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):m("closed")}))),[E]);const v=C.useCallback((()=>h.send({type:"FOCUS",id:E})),[E]),_=C.useCallback((()=>h.send({type:"OPEN",id:E,delayDuration:c})),[E,c]),b=C.useCallback((()=>h.send({type:"CLOSE",id:E,skipDelayDuration:l})),[l,E]);return C.useEffect((()=>()=>b()),[b]),p((()=>{!0===r&&h.send({type:"OPEN",id:E})}),[E,r]),/*#__PURE__*/C.createElement(s.Root,u,/*#__PURE__*/C.createElement(M,{scope:o,contentId:E,open:x,stateAttribute:T,trigger:d,onTriggerChange:f,onFocus:v,onOpen:_,onClose:b},n))};exports.Tooltip=S;const R=/*#__PURE__*/C.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=P("TooltipTrigger",o),i=q(o),a=x(t,r.onTriggerChange);/*#__PURE__*/return C.createElement(s.Anchor,T({asChild:!0},i),/*#__PURE__*/C.createElement(c.button,T({type:"button","aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute},n,{ref:a,onMouseEnter:y(e.onMouseEnter,r.onOpen),onMouseLeave:y(e.onMouseLeave,r.onClose),onMouseDown:y(e.onMouseDown,r.onClose),onFocus:y(e.onFocus,r.onFocus),onBlur:y(e.onBlur,r.onClose),onClick:y(e.onClick,r.onClose)})))}));exports.TooltipTrigger=R;const k=/*#__PURE__*/C.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=P("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return C.createElement(l,{present:o||r.open},/*#__PURE__*/C.createElement(A,T({ref:t},n)))}));exports.TooltipContent=k;const A=/*#__PURE__*/C.forwardRef(((e,t)=>{const{__scopeTooltip:i,children:a,"aria-label":c,portalled:l=!0,...u}=e,d=P("TooltipContent",i),p=q(i),g=l?r:C.Fragment;return f((()=>d.onClose())),/*#__PURE__*/C.createElement(g,null,/*#__PURE__*/C.createElement(L,{__scopeTooltip:i}),/*#__PURE__*/C.createElement(s.Content,T({"data-state":d.stateAttribute},p,u,{ref:t,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/C.createElement(n,null,a),/*#__PURE__*/C.createElement(o.Root,{id:d.contentId,role:"tooltip"},c||a)))})),I=/*#__PURE__*/C.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=q(o);/*#__PURE__*/return C.createElement(s.Arrow,T({},r,n,{ref:t}))}));/*#__PURE__*/function L(e){const{__scopeTooltip:t}=e,o=P("CheckTriggerMoved",t),n=u(o.trigger),r=null==n?void 0:n.left,i=d(r),s=null==n?void 0:n.top,a=d(s),c=o.onClose;return C.useEffect((()=>{(void 0!==i&&i!==r||void 0!==a&&a!==s)&&c()}),[c,i,a,r,s]),null}exports.TooltipArrow=I;const N=S;exports.Root=N;const F=R;exports.Trigger=F;const Y=k;exports.Content=Y;const K=I;exports.Arrow=K;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{useId as e}from"@radix-ui/react-id";import*as t from"@radix-ui/react-visually-hidden";import{Slottable as o}from"@radix-ui/react-slot";import{Portal as n}from"@radix-ui/react-portal";import*as r from"@radix-ui/react-popper";import{createPopperScope as i}from"@radix-ui/react-popper";import{Primitive as a}from"@radix-ui/react-primitive";import{Presence as s}from"@radix-ui/react-presence";import{useRect as l}from"@radix-ui/react-use-rect";import{usePrevious as c}from"@radix-ui/react-use-previous";import{useLayoutEffect as p}from"@radix-ui/react-use-layout-effect";import{useEscapeKeydown as u}from"@radix-ui/react-use-escape-keydown";import{useControllableState as d}from"@radix-ui/react-use-controllable-state";import{createContextScope as m}from"@radix-ui/react-context";import{useComposedRefs as f}from"@radix-ui/react-compose-refs";import{composeEventHandlers as g}from"@radix-ui/primitive";import*as E from"react";import x from"@babel/runtime/helpers/esm/extends";function y(e){return{type:"machine.actions.assign",assign:e}}let T,C;const v=y(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),_=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],a=s=>{var l,c;const p=e.states[n],u=s.type,d=null===(l=e.on)||void 0===l?void 0:l[u],m=null===(c=p.on)||void 0===c?void 0:c[u],f=null!=d?d:m;if(void 0===f)o&&console.warn(`From state: "${n}", event "${u}" has no transition to any state`);else{const{target:o,actions:l=[],cond:c=(()=>!0)}=f,u=o?e.states[o]:{};if(c(r,s)){const e=(p.exit||[]).concat(l,u.entry||[]);r=function(e,t,o){let n=o;return null==e||e.forEach((e=>{"function"==typeof e?e(n,t,a):"machine.actions.assign"===e.type&&(n=e.assign(n,t))})),n}(e,s,r),o&&(n=o,t&&(console.group("event:",s),console.log("state:",n),console.log("context:",r),console.groupEnd()),i.forEach((e=>e({state:n,context:r}))))}}};return{subscribe:function(e){return i.push(e),()=>{i.splice(i.indexOf(e),1)}},send:a,getContext:function(){return r}}}({initial:"closed",context:{id:null,delayed:!1},on:{FOCUS:{target:"open"}},states:{closed:{entry:[y((e=>({...e,id:null})))],on:{OPEN:{target:"opening"}}},opening:{entry:[(e,t,o)=>{const n=t.delayDuration,r=()=>o({type:"DELAY_TIMER_END"});void 0===n?r():T=window.setTimeout(r,n)},v,y((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(T)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[v],exit:[y((e=>({...e,delayed:!1})))],on:{OPEN:{target:"open"},CLOSE:{target:"closing",cond:(e,t)=>e.id===t.id}}},closing:{entry:[(e,t,o)=>{var n;const r=null!==(n=t.skipDelayDuration)&&void 0!==n?n:300;C=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(C)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[b,D]=m("Tooltip",[i]);export{D as createTooltipScope};const w=i(),[h,O]=b("Tooltip");export const Tooltip=t=>{const{__scopeTooltip:o,children:n,open:i,defaultOpen:a=!1,onOpenChange:s,delayDuration:l=700,skipDelayDuration:c=300}=t,u=w(o),[m,f]=E.useState(null),g=e(),[x=!1,y]=d({prop:i,defaultProp:a,onChange:s}),[T,C]=E.useState(i?"instant-open":"closed");E.useEffect((()=>_.subscribe((({state:e,context:t})=>{"open"===e&&t.id===g?y(!0):y(!1)}))),[g,y]),E.useEffect((()=>_.subscribe((({state:e,context:t})=>{t.id===g?C("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):C("closed")}))),[g]);const v=E.useCallback((()=>_.send({type:"FOCUS",id:g})),[g]),b=E.useCallback((()=>_.send({type:"OPEN",id:g,delayDuration:l})),[g,l]),D=E.useCallback((()=>_.send({type:"CLOSE",id:g,skipDelayDuration:c})),[c,g]);return E.useEffect((()=>()=>D()),[D]),p((()=>{!0===i&&_.send({type:"OPEN",id:g})}),[g,i]),/*#__PURE__*/E.createElement(r.Root,u,/*#__PURE__*/E.createElement(h,{scope:o,contentId:g,open:x,stateAttribute:T,trigger:m,onTriggerChange:f,onFocus:v,onOpen:b,onClose:D},n))};/*#__PURE__*/export const TooltipTrigger=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,i=O("TooltipTrigger",o),s=w(o),l=f(t,i.onTriggerChange);/*#__PURE__*/return E.createElement(r.Anchor,x({asChild:!0},s),/*#__PURE__*/E.createElement(a.button,x({type:"button","aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute},n,{ref:l,onMouseEnter:g(e.onMouseEnter,i.onOpen),onMouseLeave:g(e.onMouseLeave,i.onClose),onMouseDown:g(e.onMouseDown,i.onClose),onFocus:g(e.onFocus,i.onFocus),onBlur:g(e.onBlur,i.onClose),onKeyDown:g(e.onKeyDown,(e=>{"Enter"!==e.key&&" "!==e.key||i.onClose()}))})))}));/*#__PURE__*/export const TooltipContent=/*#__PURE__*/E.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=O("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return E.createElement(s,{present:o||r.open},/*#__PURE__*/E.createElement(A,x({ref:t},n)))}));const A=/*#__PURE__*/E.forwardRef(((e,i)=>{const{__scopeTooltip:a,children:s,"aria-label":l,portalled:c=!0,...p}=e,d=O("TooltipContent",a),m=w(a),f=c?n:E.Fragment;return u((()=>d.onClose())),/*#__PURE__*/E.createElement(f,null,/*#__PURE__*/E.createElement(M,{__scopeTooltip:a}),/*#__PURE__*/E.createElement(r.Content,x({"data-state":d.stateAttribute},m,p,{ref:i,style:{...p.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/E.createElement(o,null,s),/*#__PURE__*/E.createElement(t.Root,{id:d.contentId,role:"tooltip"},l||s)))}));/*#__PURE__*/export const TooltipArrow=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,i=w(o);/*#__PURE__*/return E.createElement(r.Arrow,x({},i,n,{ref:t}))}));/*#__PURE__*/function M(e){const{__scopeTooltip:t}=e,o=O("CheckTriggerMoved",t),n=l(o.trigger),r=null==n?void 0:n.left,i=c(r),a=null==n?void 0:n.top,s=c(a),p=o.onClose;return E.useEffect((()=>{(void 0!==i&&i!==r||void 0!==s&&s!==a)&&p()}),[p,i,s,r,a]),null}export const Root=Tooltip;export const Trigger=TooltipTrigger;export const Content=TooltipContent;export const Arrow=TooltipArrow;
import{useId as e}from"@radix-ui/react-id";import*as t from"@radix-ui/react-visually-hidden";import{Slottable as o}from"@radix-ui/react-slot";import{Portal as n}from"@radix-ui/react-portal";import*as r from"@radix-ui/react-popper";import{createPopperScope as i}from"@radix-ui/react-popper";import{Primitive as a}from"@radix-ui/react-primitive";import{Presence as s}from"@radix-ui/react-presence";import{useRect as l}from"@radix-ui/react-use-rect";import{usePrevious as c}from"@radix-ui/react-use-previous";import{useLayoutEffect as p}from"@radix-ui/react-use-layout-effect";import{useEscapeKeydown as u}from"@radix-ui/react-use-escape-keydown";import{useControllableState as d}from"@radix-ui/react-use-controllable-state";import{createContextScope as m}from"@radix-ui/react-context";import{useComposedRefs as f}from"@radix-ui/react-compose-refs";import{composeEventHandlers as g}from"@radix-ui/primitive";import*as x from"react";import E from"@babel/runtime/helpers/esm/extends";function T(e){return{type:"machine.actions.assign",assign:e}}let y,C;const v=T(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),_=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],a=s=>{var l,c;const p=e.states[n],u=s.type,d=null===(l=e.on)||void 0===l?void 0:l[u],m=null===(c=p.on)||void 0===c?void 0:c[u],f=null!=d?d:m;if(void 0===f)o&&console.warn(`From state: "${n}", event "${u}" has no transition to any state`);else{const{target:o,actions:l=[],cond:c=(()=>!0)}=f,u=o?e.states[o]:{};if(c(r,s)){const e=(p.exit||[]).concat(l,u.entry||[]);r=function(e,t,o){let n=o;return null==e||e.forEach((e=>{"function"==typeof e?e(n,t,a):"machine.actions.assign"===e.type&&(n=e.assign(n,t))})),n}(e,s,r),o&&(n=o,t&&(console.group("event:",s),console.log("state:",n),console.log("context:",r),console.groupEnd()),i.forEach((e=>e({state:n,context:r}))))}}};return{subscribe:function(e){return i.push(e),()=>{i.splice(i.indexOf(e),1)}},send:a,getContext:function(){return r}}}({initial:"closed",context:{id:null,delayed:!1},on:{FOCUS:{target:"open"}},states:{closed:{entry:[T((e=>({...e,id:null})))],on:{OPEN:{target:"opening"}}},opening:{entry:[(e,t,o)=>{const n=t.delayDuration,r=()=>o({type:"DELAY_TIMER_END"});void 0===n?r():y=window.setTimeout(r,n)},v,T((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(y)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[v],exit:[T((e=>({...e,delayed:!1})))],on:{OPEN:{target:"open"},CLOSE:{target:"closing",cond:(e,t)=>e.id===t.id}}},closing:{entry:[(e,t,o)=>{var n;const r=null!==(n=t.skipDelayDuration)&&void 0!==n?n:300;C=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(C)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[b,D]=m("Tooltip",[i]);export{D as createTooltipScope};const w=i(),[h,O]=b("Tooltip");export const Tooltip=t=>{const{__scopeTooltip:o,children:n,open:i,defaultOpen:a=!1,onOpenChange:s,delayDuration:l=700,skipDelayDuration:c=300}=t,u=w(o),[m,f]=x.useState(null),g=e(),[E=!1,T]=d({prop:i,defaultProp:a,onChange:s}),[y,C]=x.useState(i?"instant-open":"closed");x.useEffect((()=>_.subscribe((({state:e,context:t})=>{"open"===e&&t.id===g?T(!0):T(!1)}))),[g,T]),x.useEffect((()=>_.subscribe((({state:e,context:t})=>{t.id===g?C("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):C("closed")}))),[g]);const v=x.useCallback((()=>_.send({type:"FOCUS",id:g})),[g]),b=x.useCallback((()=>_.send({type:"OPEN",id:g,delayDuration:l})),[g,l]),D=x.useCallback((()=>_.send({type:"CLOSE",id:g,skipDelayDuration:c})),[c,g]);return x.useEffect((()=>()=>D()),[D]),p((()=>{!0===i&&_.send({type:"OPEN",id:g})}),[g,i]),/*#__PURE__*/x.createElement(r.Root,u,/*#__PURE__*/x.createElement(h,{scope:o,contentId:g,open:E,stateAttribute:y,trigger:m,onTriggerChange:f,onFocus:v,onOpen:b,onClose:D},n))};/*#__PURE__*/export const TooltipTrigger=/*#__PURE__*/x.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,i=O("TooltipTrigger",o),s=w(o),l=f(t,i.onTriggerChange);/*#__PURE__*/return x.createElement(r.Anchor,E({asChild:!0},s),/*#__PURE__*/x.createElement(a.button,E({type:"button","aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute},n,{ref:l,onMouseEnter:g(e.onMouseEnter,i.onOpen),onMouseLeave:g(e.onMouseLeave,i.onClose),onMouseDown:g(e.onMouseDown,i.onClose),onFocus:g(e.onFocus,i.onFocus),onBlur:g(e.onBlur,i.onClose),onClick:g(e.onClick,i.onClose)})))}));/*#__PURE__*/export const TooltipContent=/*#__PURE__*/x.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=O("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return x.createElement(s,{present:o||r.open},/*#__PURE__*/x.createElement(A,E({ref:t},n)))}));const A=/*#__PURE__*/x.forwardRef(((e,i)=>{const{__scopeTooltip:a,children:s,"aria-label":l,portalled:c=!0,...p}=e,d=O("TooltipContent",a),m=w(a),f=c?n:x.Fragment;return u((()=>d.onClose())),/*#__PURE__*/x.createElement(f,null,/*#__PURE__*/x.createElement(M,{__scopeTooltip:a}),/*#__PURE__*/x.createElement(r.Content,E({"data-state":d.stateAttribute},m,p,{ref:i,style:{...p.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/x.createElement(o,null,s),/*#__PURE__*/x.createElement(t.Root,{id:d.contentId,role:"tooltip"},l||s)))}));/*#__PURE__*/export const TooltipArrow=/*#__PURE__*/x.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,i=w(o);/*#__PURE__*/return x.createElement(r.Arrow,E({},i,n,{ref:t}))}));/*#__PURE__*/function M(e){const{__scopeTooltip:t}=e,o=O("CheckTriggerMoved",t),n=l(o.trigger),r=null==n?void 0:n.left,i=c(r),a=null==n?void 0:n.top,s=c(a),p=o.onClose;return x.useEffect((()=>{(void 0!==i&&i!==r||void 0!==s&&s!==a)&&p()}),[p,i,s,r,a]),null}export const Root=Tooltip;export const Trigger=TooltipTrigger;export const Content=TooltipContent;export const Arrow=TooltipArrow;
//# sourceMappingURL=index.module.js.map
{
"name": "@radix-ui/react-tooltip",
"version": "0.1.1",
"version": "0.1.2-rc.1",
"license": "MIT",

@@ -25,3 +25,3 @@ "source": "src/index.ts",

"@radix-ui/react-popper": "0.1.1",
"@radix-ui/react-portal": "0.1.1",
"@radix-ui/react-portal": "0.1.2-rc.10",
"@radix-ui/react-presence": "0.1.1",

@@ -48,3 +48,4 @@ "@radix-ui/react-primitive": "0.1.1",

"url": "https://github.com/radix-ui/primitives/issues"
}
},
"stableVersion": "0.1.1"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc