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.2-rc.3 to 0.1.2-rc.4

2

dist/index.js

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

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;
var e,t=require("@radix-ui/react-id").useId,o=require("@radix-ui/react-use-callback-ref").useCallbackRef,n=v({},require("@radix-ui/react-visually-hidden")),r=require("@radix-ui/react-slot").Slottable,i=require("@radix-ui/react-portal").Portal,a=require("@radix-ui/react-popper"),s=v({},a),c=a.createPopperScope,l=require("@radix-ui/react-primitive").Primitive,u=require("@radix-ui/react-presence").Presence,d=require("@radix-ui/react-use-rect").useRect,p=require("@radix-ui/react-use-previous").usePrevious,f=require("@radix-ui/react-use-layout-effect").useLayoutEffect,g=require("@radix-ui/react-use-escape-keydown").useEscapeKeydown,E=require("@radix-ui/react-use-controllable-state").useControllableState,x=require("@radix-ui/react-context").createContextScope,y=require("@radix-ui/react-compose-refs").useComposedRefs,C=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 _(e){return{type:"machine.actions.assign",assign:e}}let b,D;const h=_(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),q=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],a=s=>{var c,l;const u=e.states[n],d=s.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,s)){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,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:[_((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():b=window.setTimeout(r,n)},h,_((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(b)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[h],exit:[_((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;D=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(D)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[w,O]=x("Tooltip",[c]);exports.createTooltipScope=O;const M=c(),[P,R]=w("Tooltip"),S=e=>{const{__scopeTooltip:n,children:r,open:i,defaultOpen:a=!1,onOpenChange:c,delayDuration:l=700,skipDelayDuration:u=300}=e,d=M(n),[p,g]=T.useState(null),x=t(),[y=!1,C]=E({prop:i,defaultProp:a,onChange:c}),[m,v]=T.useState(i?"instant-open":"closed");T.useEffect((()=>q.subscribe((({state:e,context:t})=>{"open"===e&&t.id===x?C(!0):C(!1)}))),[x,C]),T.useEffect((()=>q.subscribe((({state:e,context:t})=>{t.id===x?v("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):v("closed")}))),[x]);const _=T.useCallback((()=>q.send({type:"FOCUS",id:x})),[x]),b=T.useCallback((()=>q.send({type:"OPEN",id:x,delayDuration:l})),[x,l]),D=o((()=>{q.send({type:"CLOSE",id:x,skipDelayDuration:u})}));return T.useEffect((()=>()=>D()),[D]),f((()=>{!0===i&&q.send({type:"OPEN",id:x})}),[x,i]),/*#__PURE__*/T.createElement(s.Root,d,/*#__PURE__*/T.createElement(P,{scope:n,contentId:x,open:y,stateAttribute:m,trigger:p,onTriggerChange:g,onFocus:_,onOpen:b,onClose:D},r))};exports.Tooltip=S;const k=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=R("TooltipTrigger",o),i=M(o),a=y(t,r.onTriggerChange);/*#__PURE__*/return T.createElement(s.Anchor,m({asChild:!0},i),/*#__PURE__*/T.createElement(l.button,m({type:"button","aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute},n,{ref:a,onMouseEnter:C(e.onMouseEnter,r.onOpen),onMouseLeave:C(e.onMouseLeave,r.onClose),onMouseDown:C(e.onMouseDown,r.onClose),onFocus:C(e.onFocus,r.onFocus),onBlur:C(e.onBlur,r.onClose),onClick:C(e.onClick,r.onClose)})))}));exports.TooltipTrigger=k;const A=/*#__PURE__*/T.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=R("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return T.createElement(u,{present:o||r.open},/*#__PURE__*/T.createElement(I,m({ref:t},n)))}));exports.TooltipContent=A;const I=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,children:a,"aria-label":c,portalled:l=!0,...u}=e,d=R("TooltipContent",o),p=M(o),f=l?i:T.Fragment;return g((()=>d.onClose())),/*#__PURE__*/T.createElement(f,null,/*#__PURE__*/T.createElement(N,{__scopeTooltip:o}),/*#__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(r,null,a),/*#__PURE__*/T.createElement(n.Root,{id:d.contentId,role:"tooltip"},c||a)))})),L=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=M(o);/*#__PURE__*/return T.createElement(s.Arrow,m({},r,n,{ref:t}))}));/*#__PURE__*/function N(e){const{__scopeTooltip:t}=e,o=R("CheckTriggerMoved",t),n=d(o.trigger),r=null==n?void 0:n.left,i=p(r),a=null==n?void 0:n.top,s=p(a),c=o.onClose;return T.useEffect((()=>{(void 0!==i&&i!==r||void 0!==s&&s!==a)&&c()}),[c,i,s,r,a]),null}exports.TooltipArrow=L;const F=S;exports.Root=F;const Y=k;exports.Trigger=Y;const K=A;exports.Content=K;const U=L;exports.Arrow=U;
//# 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 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;
import{useId as e}from"@radix-ui/react-id";import{useCallbackRef as t}from"@radix-ui/react-use-callback-ref";import*as o from"@radix-ui/react-visually-hidden";import{Slottable as n}from"@radix-ui/react-slot";import{Portal as r}from"@radix-ui/react-portal";import*as i from"@radix-ui/react-popper";import{createPopperScope as a}from"@radix-ui/react-popper";import{Primitive as s}from"@radix-ui/react-primitive";import{Presence as l}from"@radix-ui/react-presence";import{useRect as c}from"@radix-ui/react-use-rect";import{usePrevious as p}from"@radix-ui/react-use-previous";import{useLayoutEffect as u}from"@radix-ui/react-use-layout-effect";import{useEscapeKeydown as d}from"@radix-ui/react-use-escape-keydown";import{useControllableState as m}from"@radix-ui/react-use-controllable-state";import{createContextScope as f}from"@radix-ui/react-context";import{useComposedRefs as g}from"@radix-ui/react-compose-refs";import{composeEventHandlers as x}from"@radix-ui/primitive";import*as E from"react";import T from"@babel/runtime/helpers/esm/extends";function y(e){return{type:"machine.actions.assign",assign:e}}let C,v;const _=y(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),b=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():C=window.setTimeout(r,n)},_,y((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(C)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[_],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;v=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(v)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[D,w]=f("Tooltip",[a]);export{w as createTooltipScope};const h=a(),[O,A]=D("Tooltip");export const Tooltip=o=>{const{__scopeTooltip:n,children:r,open:a,defaultOpen:s=!1,onOpenChange:l,delayDuration:c=700,skipDelayDuration:p=300}=o,d=h(n),[f,g]=E.useState(null),x=e(),[T=!1,y]=m({prop:a,defaultProp:s,onChange:l}),[C,v]=E.useState(a?"instant-open":"closed");E.useEffect((()=>b.subscribe((({state:e,context:t})=>{"open"===e&&t.id===x?y(!0):y(!1)}))),[x,y]),E.useEffect((()=>b.subscribe((({state:e,context:t})=>{t.id===x?v("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):v("closed")}))),[x]);const _=E.useCallback((()=>b.send({type:"FOCUS",id:x})),[x]),D=E.useCallback((()=>b.send({type:"OPEN",id:x,delayDuration:c})),[x,c]),w=t((()=>{b.send({type:"CLOSE",id:x,skipDelayDuration:p})}));return E.useEffect((()=>()=>w()),[w]),u((()=>{!0===a&&b.send({type:"OPEN",id:x})}),[x,a]),/*#__PURE__*/E.createElement(i.Root,d,/*#__PURE__*/E.createElement(O,{scope:n,contentId:x,open:T,stateAttribute:C,trigger:f,onTriggerChange:g,onFocus:_,onOpen:D,onClose:w},r))};/*#__PURE__*/export const TooltipTrigger=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=A("TooltipTrigger",o),a=h(o),l=g(t,r.onTriggerChange);/*#__PURE__*/return E.createElement(i.Anchor,T({asChild:!0},a),/*#__PURE__*/E.createElement(s.button,T({type:"button","aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute},n,{ref:l,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),onClick:x(e.onClick,r.onClose)})))}));/*#__PURE__*/export const TooltipContent=/*#__PURE__*/E.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=A("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return E.createElement(l,{present:o||r.open},/*#__PURE__*/E.createElement(M,T({ref:t},n)))}));const M=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:a,children:s,"aria-label":l,portalled:c=!0,...p}=e,u=A("TooltipContent",a),m=h(a),f=c?r:E.Fragment;return d((()=>u.onClose())),/*#__PURE__*/E.createElement(f,null,/*#__PURE__*/E.createElement(k,{__scopeTooltip:a}),/*#__PURE__*/E.createElement(i.Content,T({"data-state":u.stateAttribute},m,p,{ref:t,style:{...p.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/E.createElement(n,null,s),/*#__PURE__*/E.createElement(o.Root,{id:u.contentId,role:"tooltip"},l||s)))}));/*#__PURE__*/export const TooltipArrow=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=h(o);/*#__PURE__*/return E.createElement(i.Arrow,T({},r,n,{ref:t}))}));/*#__PURE__*/function k(e){const{__scopeTooltip:t}=e,o=A("CheckTriggerMoved",t),n=c(o.trigger),r=null==n?void 0:n.left,i=p(r),a=null==n?void 0:n.top,s=p(a),l=o.onClose;return E.useEffect((()=>{(void 0!==i&&i!==r||void 0!==s&&s!==a)&&l()}),[l,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.2-rc.3",
"version": "0.1.2-rc.4",
"license": "MIT",

@@ -23,8 +23,9 @@ "source": "src/index.ts",

"@radix-ui/react-context": "0.1.1",
"@radix-ui/react-id": "0.1.1",
"@radix-ui/react-id": "0.1.2-rc.1",
"@radix-ui/react-popper": "0.1.1",
"@radix-ui/react-portal": "0.1.2-rc.12",
"@radix-ui/react-portal": "0.1.2-rc.13",
"@radix-ui/react-presence": "0.1.1",
"@radix-ui/react-primitive": "0.1.1",
"@radix-ui/react-slot": "0.1.1",
"@radix-ui/react-use-callback-ref": "0.1.0",
"@radix-ui/react-use-controllable-state": "0.1.0",

@@ -31,0 +32,0 @@ "@radix-ui/react-use-escape-keydown": "0.1.0",

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