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
6
Versions
259
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.0.1 to 0.0.2

2

dist/index.js

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

var e=require("@radix-ui/react-visually-hidden").VisuallyHidden,t=require("@radix-ui/react-portal").Portal,n=O({},require("@radix-ui/react-popper")),r=require("@radix-ui/react-polymorphic").forwardRefWithAs,o=require("@radix-ui/react-utils"),i=o.createContext,u=o.useComposedRefs,a=o.useId,c=o.composeEventHandlers,s=o.useRect,l=o.usePrevious,d=o.useControlledState,f=o.useLayoutEffect,p=o.extendComponent,v=require("@radix-ui/utils").getPartDataAttrObj,E=O({},require("react"));function O(e,t){return Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e}var S,m,y={initial:"CLOSED",context:{id:null},states:{CLOSED:{on:{mouseEntered:"WAITING_FOR_REST",focused:"OPEN"}},WAITING_FOR_REST:{onEnterState:function(e){clearTimeout(S),S=window.setTimeout((function(){return e("restTimerElapsed")}),300)},onLeaveState:function(){clearTimeout(S)},on:{restTimerElapsed:"OPEN",mouseMoved:"WAITING_FOR_REST",mouseLeft:"CLOSED",activated:"DISMISSED",unmounted:"CLOSED"}},OPEN:{on:{mouseLeft:"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD",mouseEntered:"OPEN",mouseMoved:"OPEN",activated:"DISMISSED",blurred:"CLOSED",triggerMoved:"CLOSED",unmounted:"CLOSED"}},CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD:{onEnterState:function(e){clearTimeout(m),m=window.setTimeout((function(){return e("skipRestTimerElapsed")}),300)},onLeaveState:function(){clearTimeout(m)},on:{skipRestTimerElapsed:"CLOSED",mouseEntered:"OPEN",focused:"OPEN",activated:"DISMISSED",unmounted:"CLOSED"}},DISMISSED:{on:{mouseLeft:"CLOSED",blurred:"CLOSED",unmounted:"CLOSED"}}}};function b(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?b(Object(n),!0).forEach((function(t){T(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):b(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function T(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C(){return(C=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function D(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return w(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return w(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var x=h(i("TooltipContext","Tooltip"),2),L=x[0],I=x[1],P=function(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=r.debug,i=void 0!==o&&o,u=r.warnOnUnknownTransitions,a=void 0!==u&&u,c=e.initial,s=e.context,l=[];function d(e){return l.push(e),function(){l.splice(l.indexOf(e),1)}}function f(){l.forEach((function(e){return e({state:c,previousState:t,context:s})}))}var p=function r(o,u){var l=e.states[c],d=l.on&&l.on[o];if(void 0===d)a&&console.warn('From state: "'.concat(c,'", event "').concat(o,'" does not lead to any state'));else{t=c,n=s,l.onLeaveState&&l.onLeaveState(r);var p=e.states[d];p.onEnterState&&p.onEnterState(r),c=d,void 0!==u&&(s=u),i&&console.log({previousState:t,previousContext:n,event:o,state:c,context:s}),f()}};function v(){return c}function E(){return s}return{subscribe:d,transition:p,getState:v,getContext:E}}(y),R=function(e){var t=e.children,n=e.open,r=e.defaultOpen,o=void 0!==r&&r,i=e.onOpenChange,u=E.useRef(null),c="tooltip-".concat(a()),s=h(d({prop:n,defaultProp:o,onChange:i}),2),l=s[0],p=void 0!==l&&l,v=s[1],O=h(E.useState(n?"instant-open":"closed"),2),S=O[0],m=O[1];E.useEffect((function(){return P.subscribe((function(e){var t=e.state,n=e.context;"OPEN"===t&&n.id===c?v(!0):v(!1)}))}),[c,v]),E.useEffect((function(){return P.subscribe((function(e){var t=e.state,n=e.previousState;"OPEN"===t&&("WAITING_FOR_REST"===n&&m("delayed-open"),"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD"!==n&&"CLOSED"!==n||m("instant-open")),"CLOSED"===t&&m("closed")}))}),[]),E.useEffect((function(){return function(){P.transition("unmounted",{id:c})}}),[c]),f((function(){!0===n&&P.transition("mouseEntered",{id:c})}),[c,n]);var y=E.useMemo((function(){return{triggerRef:u,id:c,open:p,stateAttribute:S}}),[c,p,S]);return E.createElement(L.Provider,{value:y},t)};exports.Tooltip=R,R.displayName="Tooltip";var M=r((function(e,t){var n=e.as,r=void 0===n?"button":n,o=e.onMouseEnter,i=e.onMouseMove,a=e.onMouseLeave,s=e.onFocus,l=e.onBlur,d=e.onMouseDown,f=e.onKeyDown,p=D(e,["as","onMouseEnter","onMouseMove","onMouseLeave","onFocus","onBlur","onMouseDown","onKeyDown"]),O=I("TooltipTrigger"),S=u(t,O.triggerRef);return E.createElement(r,C({},v("TooltipTrigger"),{ref:S,type:"button","aria-describedby":O.open?O.id:void 0,onMouseEnter:c(o,(function(){return P.transition("mouseEntered",{id:O.id})})),onMouseMove:c(i,(function(){return P.transition("mouseMoved",{id:O.id})})),onMouseLeave:c(a,(function(){P.getContext().id===O.id&&P.transition("mouseLeft",{id:O.id})})),onFocus:c(s,(function(){return P.transition("focused",{id:O.id})})),onBlur:c(l,(function(){P.getContext().id===O.id&&P.transition("blurred",{id:O.id})})),onMouseDown:c(d,(function(){return P.transition("activated",{id:O.id})})),onKeyDown:c(f,(function(e){"Escape"!==e.key&&"Enter"!==e.key&&" "!==e.key||P.transition("activated",{id:O.id})}))},p))}));exports.TooltipTrigger=M,M.displayName="TooltipTrigger";var j=r((function(e,t){return I("TooltipContent").open?E.createElement(_,C({ref:t},e)):null}));exports.TooltipContent=j;var _=r((function(r,o){var i=r.children,u=r["aria-label"],a=r.anchorRef,c=r.portalled,s=void 0===c||c,l=D(r,["children","aria-label","anchorRef","portalled"]),d=I("TooltipContent"),f=s?t:E.Fragment;return E.createElement(f,null,E.createElement(A,null),E.createElement(n.Root,C({},v("TooltipContent"),l,{"data-state":d.stateAttribute,ref:o,anchorRef:a||d.triggerRef,style:g(g({},l.style),{},T({},"--radix-tooltip-content-transform-origin","var(--radix-popper-transform-origin)"))}),i,E.createElement(e,{id:d.id,role:"tooltip"},u||i)))}));j.displayName="TooltipContent";var N=p(n.Arrow,"TooltipArrow");function A(){var e=I("CheckTriggerMoved"),t=e.triggerRef,n=e.id,r=s(t),o=null==r?void 0:r.left,i=l(o),u=null==r?void 0:r.top,a=l(u);return E.useEffect((function(){(void 0!==i&&i!==o||void 0!==a&&a!==u)&&P.transition("triggerMoved",{id:n})}),[n,i,a,o,u]),null}exports.TooltipArrow=N;var H=R;exports.Root=H;var F=M;exports.Trigger=F;var k=j;exports.Content=k;var K=N;exports.Arrow=K;
var e=require("@radix-ui/react-visually-hidden").VisuallyHidden,t=require("@radix-ui/react-portal").Portal,r=O({},require("@radix-ui/react-popper")),n=require("@radix-ui/react-primitive").Primitive,o=require("@radix-ui/react-utils"),i=o.createContext,u=o.useComposedRefs,a=o.useId,c=o.composeEventHandlers,s=o.useRect,l=o.usePrevious,d=o.useControlledState,f=o.useLayoutEffect,p=o.extendComponent,v=require("@radix-ui/utils").getSelector,E=O({},require("react"));function O(e,t){return Object.keys(t).forEach((function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e}var S,m,b={initial:"CLOSED",context:{id:null},states:{CLOSED:{on:{mouseEntered:"WAITING_FOR_REST",focused:"OPEN"}},WAITING_FOR_REST:{onEnterState:function(e){clearTimeout(S),S=window.setTimeout((function(){return e("restTimerElapsed")}),300)},onLeaveState:function(){clearTimeout(S)},on:{restTimerElapsed:"OPEN",mouseMoved:"WAITING_FOR_REST",mouseLeft:"CLOSED",activated:"DISMISSED",unmounted:"CLOSED"}},OPEN:{on:{mouseLeft:"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD",mouseEntered:"OPEN",mouseMoved:"OPEN",activated:"DISMISSED",blurred:"CLOSED",triggerMoved:"CLOSED",unmounted:"CLOSED"}},CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD:{onEnterState:function(e){clearTimeout(m),m=window.setTimeout((function(){return e("skipRestTimerElapsed")}),300)},onLeaveState:function(){clearTimeout(m)},on:{skipRestTimerElapsed:"CLOSED",mouseEntered:"OPEN",focused:"OPEN",activated:"DISMISSED",unmounted:"CLOSED"}},DISMISSED:{on:{mouseLeft:"CLOSED",blurred:"CLOSED",unmounted:"CLOSED"}}}};function y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?y(Object(r),!0).forEach((function(t){T(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function T(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function C(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function D(){return(D=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return w(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return w(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var x=h(i("TooltipContext","Tooltip"),2),L=x[0],R=x[1],I=function(e){var t,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n.debug,i=void 0!==o&&o,u=n.warnOnUnknownTransitions,a=void 0!==u&&u,c=e.initial,s=e.context,l=[];function d(e){return l.push(e),function(){l.splice(l.indexOf(e),1)}}function f(){l.forEach((function(e){return e({state:c,previousState:t,context:s})}))}var p=function n(o,u){var l=e.states[c],d=l.on&&l.on[o];if(void 0===d)a&&console.warn('From state: "'.concat(c,'", event "').concat(o,'" does not lead to any state'));else{t=c,r=s,l.onLeaveState&&l.onLeaveState(n);var p=e.states[d];p.onEnterState&&p.onEnterState(n),c=d,void 0!==u&&(s=u),i&&console.log({previousState:t,previousContext:r,event:o,state:c,context:s}),f()}};function v(){return c}function E(){return s}return{subscribe:d,transition:p,getState:v,getContext:E}}(b),P=function(e){var t=e.children,r=e.open,n=e.defaultOpen,o=void 0!==n&&n,i=e.onOpenChange,u=E.useRef(null),c="tooltip-".concat(a()),s=h(d({prop:r,defaultProp:o,onChange:i}),2),l=s[0],p=void 0!==l&&l,v=s[1],O=h(E.useState(r?"instant-open":"closed"),2),S=O[0],m=O[1];E.useEffect((function(){return I.subscribe((function(e){var t=e.state,r=e.context;"OPEN"===t&&r.id===c?v(!0):v(!1)}))}),[c,v]),E.useEffect((function(){return I.subscribe((function(e){var t=e.state,r=e.previousState;"OPEN"===t&&("WAITING_FOR_REST"===r&&m("delayed-open"),"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD"!==r&&"CLOSED"!==r||m("instant-open")),"CLOSED"===t&&m("closed")}))}),[]),E.useEffect((function(){return function(){I.transition("unmounted",{id:c})}}),[c]),f((function(){!0===r&&I.transition("mouseEntered",{id:c})}),[c,r]);var b=E.useMemo((function(){return{triggerRef:u,id:c,open:p,stateAttribute:S}}),[c,p,S]);return E.createElement(L.Provider,{value:b},t)};exports.Tooltip=P,P.displayName="Tooltip";var _=E.forwardRef((function(e,t){var r=R("TooltipTrigger"),o=u(t,r.triggerRef);return E.createElement(n,D({as:"button",selector:v("TooltipTrigger"),type:"button","aria-describedby":r.open?r.id:void 0},e,{ref:o,onMouseEnter:c(e.onMouseEnter,(function(){return I.transition("mouseEntered",{id:r.id})})),onMouseMove:c(e.onMouseMove,(function(){return I.transition("mouseMoved",{id:r.id})})),onMouseLeave:c(e.onMouseLeave,(function(){I.getContext().id===r.id&&I.transition("mouseLeft",{id:r.id})})),onFocus:c(e.onFocus,(function(){return I.transition("focused",{id:r.id})})),onBlur:c(e.onBlur,(function(){I.getContext().id===r.id&&I.transition("blurred",{id:r.id})})),onMouseDown:c(e.onMouseDown,(function(){return I.transition("activated",{id:r.id})})),onKeyDown:c(e.onKeyDown,(function(e){"Escape"!==e.key&&"Enter"!==e.key&&" "!==e.key||I.transition("activated",{id:r.id})}))}))}));exports.TooltipTrigger=_,_.displayName="TooltipTrigger";var j=E.forwardRef((function(e,t){return R("TooltipContent").open?E.createElement(M,D({ref:t},e)):null}));exports.TooltipContent=j;var M=E.forwardRef((function(n,o){var i=n.children,u=n["aria-label"],a=n.anchorRef,c=n.portalled,s=void 0===c||c,l=C(n,["children","aria-label","anchorRef","portalled"]),d=R("TooltipContent"),f=s?t:E.Fragment;return E.createElement(f,null,E.createElement(A,null),E.createElement(r.Root,D({selector:v("TooltipContent")},l,{"data-state":d.stateAttribute,ref:o,anchorRef:a||d.triggerRef,style:g(g({},l.style),{},T({},"--radix-tooltip-content-transform-origin","var(--radix-popper-transform-origin)"))}),i,E.createElement(e,{id:d.id,role:"tooltip"},u||i)))}));j.displayName="TooltipContent";var N=p(r.Arrow,"TooltipArrow");function A(){var e=R("CheckTriggerMoved"),t=e.triggerRef,r=e.id,n=s(t),o=null==n?void 0:n.left,i=l(o),u=null==n?void 0:n.top,a=l(u);return E.useEffect((function(){(void 0!==i&&i!==o||void 0!==a&&a!==u)&&I.transition("triggerMoved",{id:r})}),[r,i,a,o,u]),null}exports.TooltipArrow=N;var H=P;exports.Root=H;var F=_;exports.Trigger=F;var k=j;exports.Content=k;var K=N;exports.Arrow=K;
//# sourceMappingURL=index.js.map

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

import{VisuallyHidden as e}from"@radix-ui/react-visually-hidden";import{Portal as t}from"@radix-ui/react-portal";import*as o from"@radix-ui/react-popper";import{forwardRefWithAs as n}from"@radix-ui/react-polymorphic";import{createContext as r,useComposedRefs as i,useId as a,composeEventHandlers as s,useRect as u,usePrevious as c,useControlledState as l,useLayoutEffect as p,extendComponent as d}from"@radix-ui/react-utils";import{getPartDataAttrObj as f}from"@radix-ui/utils";import*as E from"react";const O={initial:"CLOSED",context:{id:null},states:{CLOSED:{on:{mouseEntered:"WAITING_FOR_REST",focused:"OPEN"}},WAITING_FOR_REST:{onEnterState:function(e){clearTimeout(m),m=window.setTimeout((()=>e("restTimerElapsed")),300)},onLeaveState:function(){clearTimeout(m)},on:{restTimerElapsed:"OPEN",mouseMoved:"WAITING_FOR_REST",mouseLeft:"CLOSED",activated:"DISMISSED",unmounted:"CLOSED"}},OPEN:{on:{mouseLeft:"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD",mouseEntered:"OPEN",mouseMoved:"OPEN",activated:"DISMISSED",blurred:"CLOSED",triggerMoved:"CLOSED",unmounted:"CLOSED"}},CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD:{onEnterState:function(e){clearTimeout(S),S=window.setTimeout((()=>e("skipRestTimerElapsed")),300)},onLeaveState:function(){clearTimeout(S)},on:{skipRestTimerElapsed:"CLOSED",mouseEntered:"OPEN",focused:"OPEN",activated:"DISMISSED",unmounted:"CLOSED"}},DISMISSED:{on:{mouseLeft:"CLOSED",blurred:"CLOSED",unmounted:"CLOSED"}}}};let m,S;function T(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function g(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?T(Object(o),!0).forEach((function(t){v(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):T(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function v(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e}).apply(this,arguments)}function y(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}const[D,C]=r("TooltipContext","Tooltip"),L=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n,r,i=e.initial,a=e.context;const s=[],u=(c,l)=>{const p=e.states[i],d=p.on&&p.on[c];if(void 0===d)o&&console.warn('From state: "'.concat(i,'", event "').concat(c,'" does not lead to any state'));else{n=i,r=a,p.onLeaveState&&p.onLeaveState(u);const o=e.states[d];o.onEnterState&&o.onEnterState(u),i=d,void 0!==l&&(a=l),t&&console.log({previousState:n,previousContext:r,event:c,state:i,context:a}),s.forEach((e=>e({state:i,previousState:n,context:a})))}};return{subscribe:function(e){return s.push(e),()=>{s.splice(s.indexOf(e),1)}},transition:u,getState:function(){return i},getContext:function(){return a}}}(O);export const Tooltip=e=>{const{children:t,open:o,defaultOpen:n=!1,onOpenChange:r}=e,i=E.useRef(null),s="tooltip-".concat(a()),[u=!1,c]=l({prop:o,defaultProp:n,onChange:r}),[d,f]=E.useState(o?"instant-open":"closed");E.useEffect((()=>L.subscribe((({state:e,context:t})=>{"OPEN"===e&&t.id===s?c(!0):c(!1)}))),[s,c]),E.useEffect((()=>L.subscribe((({state:e,previousState:t})=>{"OPEN"===e&&("WAITING_FOR_REST"===t&&f("delayed-open"),"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD"!==t&&"CLOSED"!==t||f("instant-open")),"CLOSED"===e&&f("closed")}))),[]),E.useEffect((()=>()=>{L.transition("unmounted",{id:s})}),[s]),p((()=>{!0===o&&L.transition("mouseEntered",{id:s})}),[s,o]);const O=E.useMemo((()=>({triggerRef:i,id:s,open:u,stateAttribute:d})),[s,u,d]);return E.createElement(D.Provider,{value:O},t)};Tooltip.displayName="Tooltip";const x="button";export const TooltipTrigger=n(((e,t)=>{const{as:o=x,onMouseEnter:n,onMouseMove:r,onMouseLeave:a,onFocus:u,onBlur:c,onMouseDown:l,onKeyDown:p}=e,d=y(e,["as","onMouseEnter","onMouseMove","onMouseLeave","onFocus","onBlur","onMouseDown","onKeyDown"]),O=C("TooltipTrigger"),m=i(t,O.triggerRef);return E.createElement(o,b({},f("TooltipTrigger"),{ref:m,type:"button","aria-describedby":O.open?O.id:void 0,onMouseEnter:s(n,(()=>L.transition("mouseEntered",{id:O.id}))),onMouseMove:s(r,(()=>L.transition("mouseMoved",{id:O.id}))),onMouseLeave:s(a,(()=>{L.getContext().id===O.id&&L.transition("mouseLeft",{id:O.id})})),onFocus:s(u,(()=>L.transition("focused",{id:O.id}))),onBlur:s(c,(()=>{L.getContext().id===O.id&&L.transition("blurred",{id:O.id})})),onMouseDown:s(l,(()=>L.transition("activated",{id:O.id}))),onKeyDown:s(p,(e=>{"Escape"!==e.key&&"Enter"!==e.key&&" "!==e.key||L.transition("activated",{id:O.id})}))},d))}));TooltipTrigger.displayName="TooltipTrigger";export const TooltipContent=n(((e,t)=>C("TooltipContent").open?E.createElement(w,b({ref:t},e)):null));const w=n(((n,r)=>{const{children:i,"aria-label":a,anchorRef:s,portalled:u=!0}=n,c=y(n,["children","aria-label","anchorRef","portalled"]),l=C("TooltipContent"),p=u?t:E.Fragment;return E.createElement(p,null,E.createElement(I,null),E.createElement(o.Root,b({},f("TooltipContent"),c,{"data-state":l.stateAttribute,ref:r,anchorRef:s||l.triggerRef,style:g(g({},c.style),{},{"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"})}),i,E.createElement(e,{id:l.id,role:"tooltip"},a||i)))}));TooltipContent.displayName="TooltipContent";export const TooltipArrow=d(o.Arrow,"TooltipArrow");function I(){const{triggerRef:e,id:t}=C("CheckTriggerMoved"),o=u(e),n=null==o?void 0:o.left,r=c(n),i=null==o?void 0:o.top,a=c(i);return E.useEffect((()=>{(void 0!==r&&r!==n||void 0!==a&&a!==i)&&L.transition("triggerMoved",{id:t})}),[t,r,a,n,i]),null}export const Root=Tooltip;export const Trigger=TooltipTrigger;export const Content=TooltipContent;export const Arrow=TooltipArrow;
import{VisuallyHidden as e}from"@radix-ui/react-visually-hidden";import{Portal as t}from"@radix-ui/react-portal";import*as o from"@radix-ui/react-popper";import{Primitive as n}from"@radix-ui/react-primitive";import{createContext as r,useComposedRefs as i,useId as a,composeEventHandlers as s,useRect as u,usePrevious as l,useControlledState as c,useLayoutEffect as d,extendComponent as p}from"@radix-ui/react-utils";import{getSelector as f}from"@radix-ui/utils";import*as E from"react";const O={initial:"CLOSED",context:{id:null},states:{CLOSED:{on:{mouseEntered:"WAITING_FOR_REST",focused:"OPEN"}},WAITING_FOR_REST:{onEnterState:function(e){clearTimeout(m),m=window.setTimeout((()=>e("restTimerElapsed")),300)},onLeaveState:function(){clearTimeout(m)},on:{restTimerElapsed:"OPEN",mouseMoved:"WAITING_FOR_REST",mouseLeft:"CLOSED",activated:"DISMISSED",unmounted:"CLOSED"}},OPEN:{on:{mouseLeft:"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD",mouseEntered:"OPEN",mouseMoved:"OPEN",activated:"DISMISSED",blurred:"CLOSED",triggerMoved:"CLOSED",unmounted:"CLOSED"}},CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD:{onEnterState:function(e){clearTimeout(S),S=window.setTimeout((()=>e("skipRestTimerElapsed")),300)},onLeaveState:function(){clearTimeout(S)},on:{skipRestTimerElapsed:"CLOSED",mouseEntered:"OPEN",focused:"OPEN",activated:"DISMISSED",unmounted:"CLOSED"}},DISMISSED:{on:{mouseLeft:"CLOSED",blurred:"CLOSED",unmounted:"CLOSED"}}}};let m,S;function T(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function g(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?T(Object(o),!0).forEach((function(t){v(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):T(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function v(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function b(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e}).apply(this,arguments)}const[C,D]=r("TooltipContext","Tooltip"),L=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n,r,i=e.initial,a=e.context;const s=[],u=(l,c)=>{const d=e.states[i],p=d.on&&d.on[l];if(void 0===p)o&&console.warn('From state: "'.concat(i,'", event "').concat(l,'" does not lead to any state'));else{n=i,r=a,d.onLeaveState&&d.onLeaveState(u);const o=e.states[p];o.onEnterState&&o.onEnterState(u),i=p,void 0!==c&&(a=c),t&&console.log({previousState:n,previousContext:r,event:l,state:i,context:a}),s.forEach((e=>e({state:i,previousState:n,context:a})))}};return{subscribe:function(e){return s.push(e),()=>{s.splice(s.indexOf(e),1)}},transition:u,getState:function(){return i},getContext:function(){return a}}}(O);export const Tooltip=e=>{const{children:t,open:o,defaultOpen:n=!1,onOpenChange:r}=e,i=E.useRef(null),s="tooltip-".concat(a()),[u=!1,l]=c({prop:o,defaultProp:n,onChange:r}),[p,f]=E.useState(o?"instant-open":"closed");E.useEffect((()=>L.subscribe((({state:e,context:t})=>{"OPEN"===e&&t.id===s?l(!0):l(!1)}))),[s,l]),E.useEffect((()=>L.subscribe((({state:e,previousState:t})=>{"OPEN"===e&&("WAITING_FOR_REST"===t&&f("delayed-open"),"CHECKING_IF_SHOULD_SKIP_REST_THRESHOLD"!==t&&"CLOSED"!==t||f("instant-open")),"CLOSED"===e&&f("closed")}))),[]),E.useEffect((()=>()=>{L.transition("unmounted",{id:s})}),[s]),d((()=>{!0===o&&L.transition("mouseEntered",{id:s})}),[s,o]);const O=E.useMemo((()=>({triggerRef:i,id:s,open:u,stateAttribute:p})),[s,u,p]);return E.createElement(C.Provider,{value:O},t)};Tooltip.displayName="Tooltip";export const TooltipTrigger=E.forwardRef(((e,t)=>{const o=D("TooltipTrigger"),r=i(t,o.triggerRef);return E.createElement(n,y({as:"button",selector:f("TooltipTrigger"),type:"button","aria-describedby":o.open?o.id:void 0},e,{ref:r,onMouseEnter:s(e.onMouseEnter,(()=>L.transition("mouseEntered",{id:o.id}))),onMouseMove:s(e.onMouseMove,(()=>L.transition("mouseMoved",{id:o.id}))),onMouseLeave:s(e.onMouseLeave,(()=>{L.getContext().id===o.id&&L.transition("mouseLeft",{id:o.id})})),onFocus:s(e.onFocus,(()=>L.transition("focused",{id:o.id}))),onBlur:s(e.onBlur,(()=>{L.getContext().id===o.id&&L.transition("blurred",{id:o.id})})),onMouseDown:s(e.onMouseDown,(()=>L.transition("activated",{id:o.id}))),onKeyDown:s(e.onKeyDown,(e=>{"Escape"!==e.key&&"Enter"!==e.key&&" "!==e.key||L.transition("activated",{id:o.id})}))}))}));TooltipTrigger.displayName="TooltipTrigger";export const TooltipContent=E.forwardRef(((e,t)=>D("TooltipContent").open?E.createElement(w,y({ref:t},e)):null));const w=E.forwardRef(((n,r)=>{const{children:i,"aria-label":a,anchorRef:s,portalled:u=!0}=n,l=b(n,["children","aria-label","anchorRef","portalled"]),c=D("TooltipContent"),d=u?t:E.Fragment;return E.createElement(d,null,E.createElement(x,null),E.createElement(o.Root,y({selector:f("TooltipContent")},l,{"data-state":c.stateAttribute,ref:r,anchorRef:s||c.triggerRef,style:g(g({},l.style),{},{"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"})}),i,E.createElement(e,{id:c.id,role:"tooltip"},a||i)))}));TooltipContent.displayName="TooltipContent";export const TooltipArrow=p(o.Arrow,"TooltipArrow");function x(){const{triggerRef:e,id:t}=D("CheckTriggerMoved"),o=u(e),n=null==o?void 0:o.left,r=l(n),i=null==o?void 0:o.top,a=l(i);return E.useEffect((()=>{(void 0!==r&&r!==n||void 0!==a&&a!==i)&&L.transition("triggerMoved",{id:t})}),[t,r,a,n,i]),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.0.1",
"version": "0.0.2",
"license": "MIT",

@@ -21,12 +21,10 @@ "source": "src/index.ts",

"dependencies": {
"@radix-ui/react-polymorphic": "0.0.1",
"@radix-ui/react-popper": "0.0.1",
"@radix-ui/react-portal": "0.0.1",
"@radix-ui/react-utils": "0.0.1",
"@radix-ui/react-visually-hidden": "0.0.1",
"@radix-ui/utils": "0.0.1"
"@radix-ui/react-polymorphic": "0.0.2",
"@radix-ui/react-popper": "0.0.2",
"@radix-ui/react-portal": "0.0.2",
"@radix-ui/react-primitive": "0.0.1",
"@radix-ui/react-utils": "0.0.2",
"@radix-ui/react-visually-hidden": "0.0.2",
"@radix-ui/utils": "0.0.2"
},
"devDependencies": {
"parcel": "^2.0.0-beta.1"
},
"peerDependencies": {

@@ -33,0 +31,0 @@ "react": "^16.8 || ^17.0"

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