@stackshift-ui/tooltip 1.0.0-beta.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 +373 -0
- package/README.md +24 -0
- package/dist/chunk-3EYN2AKU.mjs +1 -0
- package/dist/chunk-LARJZ6PU.mjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +51 -0
- package/dist/setupTests.mjs +51 -0
- package/dist/tooltip.d.ts +19 -0
- package/dist/tooltip.js +2 -0
- package/dist/tooltip.mjs +2 -0
- package/package.json +63 -0
- package/src/index.ts +4 -0
- package/src/setupTests.ts +4 -0
- package/src/tooltip.test.tsx +44 -0
- package/src/tooltip.tsx +75 -0
package/dist/tooltip.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var y=Object.create;var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var R=(o,t)=>{for(var i in t)l(o,i,{get:t[i],enumerable:!0})},m=(o,t,i,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of C(t))!x.call(o,n)&&n!==i&&l(o,n,{get:()=>t[n],enumerable:!(p=u(t,n))||p.enumerable});return o};var b=(o,t,i)=>(i=o!=null?y(N(o)):{},m(t||!o||!o.__esModule?l(i,"default",{value:o,enumerable:!0}):i,o)),z=o=>m(l({},"__esModule",{value:!0}),o);var h={};R(h,{Tooltip:()=>P,TooltipContent:()=>v,TooltipProvider:()=>s,TooltipTrigger:()=>g});module.exports=z(h);var e=b(require("@radix-ui/react-tooltip")),r=require("@stackshift-ui/system"),a=require("react/jsx-runtime"),d="Tooltip",c="TooltipProvider",f="TooltipTrigger",T="TooltipContent";function s({delayDuration:o=0,...t}){let{[c]:i=r.DefaultComponent}=(0,r.useStackShiftUIComponents)();return(0,a.jsx)(i,{as:e.Provider,"data-slot":"tooltip-provider",delayDuration:o,...t})}s.displayName=c;function P({...o}){let{[d]:t=r.DefaultComponent}=(0,r.useStackShiftUIComponents)();return(0,a.jsx)(s,{children:(0,a.jsx)(t,{as:e.Root,"data-slot":"tooltip",...o})})}P.displayName=d;function g({...o}){let{[f]:t=r.DefaultComponent}=(0,r.useStackShiftUIComponents)();return(0,a.jsx)(t,{as:e.Trigger,"data-slot":"tooltip-trigger",...o})}g.displayName=f;function v({className:o,sideOffset:t=0,children:i,...p}){let{[T]:n=r.DefaultComponent}=(0,r.useStackShiftUIComponents)();return(0,a.jsx)(e.Portal,{children:(0,a.jsxs)(n,{as:e.Content,"data-slot":"tooltip-content",sideOffset:t,className:(0,r.cn)("bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",o),...p,children:[i,(0,a.jsx)(e.Arrow,{className:"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}v.displayName=T;0&&(module.exports={Tooltip,TooltipContent,TooltipProvider,TooltipTrigger});
|
package/dist/tooltip.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stackshift-ui/tooltip",
|
|
3
|
+
"description": "A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.",
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/**",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"author": "WebriQ <info@webriq.com>",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
17
|
+
"@testing-library/react": "^16.0.1",
|
|
18
|
+
"@testing-library/user-event": "^14.6.1",
|
|
19
|
+
"@types/node": "^22.7.0",
|
|
20
|
+
"@types/react": "^18.3.9",
|
|
21
|
+
"@types/react-dom": "^18.3.0",
|
|
22
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
23
|
+
"@vitest/coverage-v8": "^2.1.1",
|
|
24
|
+
"esbuild-plugin-rdi": "^0.0.0",
|
|
25
|
+
"esbuild-plugin-react18": "^0.2.5",
|
|
26
|
+
"esbuild-plugin-react18-css": "^0.0.4",
|
|
27
|
+
"jsdom": "^25.0.1",
|
|
28
|
+
"react": "^18.3.1",
|
|
29
|
+
"react-dom": "^18.3.1",
|
|
30
|
+
"tsup": "^8.3.0",
|
|
31
|
+
"typescript": "^5.6.2",
|
|
32
|
+
"vite-tsconfig-paths": "^5.0.1",
|
|
33
|
+
"vitest": "^2.1.1",
|
|
34
|
+
"@stackshift-ui/eslint-config": "6.0.10",
|
|
35
|
+
"@stackshift-ui/typescript-config": "6.0.10"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@radix-ui/react-tooltip": "^1.2.7",
|
|
39
|
+
"classnames": "^2.5.1",
|
|
40
|
+
"@stackshift-ui/scripts": "6.1.0-beta.0",
|
|
41
|
+
"@stackshift-ui/system": "6.1.0-beta.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@stackshift-ui/system": ">=6.1.0-beta.0",
|
|
45
|
+
"@types/react": "16.8 - 19",
|
|
46
|
+
"next": "10 - 14",
|
|
47
|
+
"react": "16.8 - 19",
|
|
48
|
+
"react-dom": "16.8 - 19"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"next": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup && tsc -p tsconfig-build.json",
|
|
57
|
+
"clean": "rm -rf dist",
|
|
58
|
+
"dev": "tsup --watch && tsc -p tsconfig-build.json -w",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"lint": "eslint src/",
|
|
61
|
+
"test": "vitest run --coverage"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { afterEach, describe, test, vi } from "vitest";
|
|
4
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
|
|
5
|
+
|
|
6
|
+
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
7
|
+
observe: vi.fn(),
|
|
8
|
+
unobserve: vi.fn(),
|
|
9
|
+
disconnect: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe.concurrent("tooltip", () => {
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
cleanup();
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
vi.resetAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("Dummy test - test if renders without errors", async ({ expect }) => {
|
|
20
|
+
const clx = "my-class";
|
|
21
|
+
const user = userEvent.setup();
|
|
22
|
+
|
|
23
|
+
const { unmount } = render(
|
|
24
|
+
<Tooltip>
|
|
25
|
+
<TooltipTrigger asChild data-testid="tooltip-trigger">
|
|
26
|
+
<button>Hover me</button>
|
|
27
|
+
</TooltipTrigger>
|
|
28
|
+
<TooltipContent data-testid="tooltip" className={clx}>
|
|
29
|
+
<p>This is a tooltip</p>
|
|
30
|
+
</TooltipContent>
|
|
31
|
+
</Tooltip>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const tooltipTrigger = screen.getByTestId("tooltip-trigger");
|
|
35
|
+
expect(tooltipTrigger).toBeInTheDocument();
|
|
36
|
+
|
|
37
|
+
screen.debug(tooltipTrigger);
|
|
38
|
+
await user.hover(tooltipTrigger);
|
|
39
|
+
screen.debug(tooltipTrigger);
|
|
40
|
+
|
|
41
|
+
expect(await screen.findByTestId("tooltip")).toBeInTheDocument();
|
|
42
|
+
unmount();
|
|
43
|
+
});
|
|
44
|
+
});
|
package/src/tooltip.tsx
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import { cn, DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
7
|
+
|
|
8
|
+
const displayName = "Tooltip";
|
|
9
|
+
const displayNameProvider = "TooltipProvider";
|
|
10
|
+
const displayNameTrigger = "TooltipTrigger";
|
|
11
|
+
const displayNameContent = "TooltipContent";
|
|
12
|
+
|
|
13
|
+
function TooltipProvider({
|
|
14
|
+
delayDuration = 0,
|
|
15
|
+
...props
|
|
16
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
|
17
|
+
const { [displayNameProvider]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Component
|
|
21
|
+
as={TooltipPrimitive.Provider}
|
|
22
|
+
data-slot="tooltip-provider"
|
|
23
|
+
delayDuration={delayDuration}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
TooltipProvider.displayName = displayNameProvider;
|
|
29
|
+
|
|
30
|
+
function Tooltip({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
|
31
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<TooltipProvider>
|
|
35
|
+
<Component as={TooltipPrimitive.Root} data-slot="tooltip" {...props} />
|
|
36
|
+
</TooltipProvider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
Tooltip.displayName = displayName;
|
|
40
|
+
|
|
41
|
+
function TooltipTrigger({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
|
42
|
+
const { [displayNameTrigger]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
43
|
+
|
|
44
|
+
return <Component as={TooltipPrimitive.Trigger} data-slot="tooltip-trigger" {...props} />;
|
|
45
|
+
}
|
|
46
|
+
TooltipTrigger.displayName = displayNameTrigger;
|
|
47
|
+
|
|
48
|
+
function TooltipContent({
|
|
49
|
+
className,
|
|
50
|
+
sideOffset = 0,
|
|
51
|
+
children,
|
|
52
|
+
...props
|
|
53
|
+
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
|
54
|
+
const { [displayNameContent]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<TooltipPrimitive.Portal>
|
|
58
|
+
<Component
|
|
59
|
+
as={TooltipPrimitive.Content}
|
|
60
|
+
data-slot="tooltip-content"
|
|
61
|
+
sideOffset={sideOffset}
|
|
62
|
+
className={cn(
|
|
63
|
+
"bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
|
64
|
+
className,
|
|
65
|
+
)}
|
|
66
|
+
{...props}>
|
|
67
|
+
{children}
|
|
68
|
+
<TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
|
69
|
+
</Component>
|
|
70
|
+
</TooltipPrimitive.Portal>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
TooltipContent.displayName = displayNameContent;
|
|
74
|
+
|
|
75
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|