@vvedantb/ui 0.4.4 → 0.5.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/README.md +104 -1
- package/app/README.md +100 -0
- package/package.json +12 -11
- package/shell/src/AppShell.tsx +99 -0
- package/shell/src/AppSidebar.tsx +168 -0
- package/shell/src/SidebarAccountMenu.tsx +121 -0
- package/shell/src/SidebarIconTooltip.tsx +34 -0
- package/shell/src/SidebarPanel.tsx +71 -0
- package/shell/src/SidebarRail.tsx +157 -0
- package/shell/src/SidebarResize.tsx +257 -0
- package/shell/src/SignOutDialog.tsx +93 -0
- package/shell/src/app-shell-classes.ts +44 -0
- package/shell/src/index.ts +31 -0
- package/src/index.ts +34 -0
- package/src/motion/panel-transition.tsx +12 -1
- package/tokens/README.md +98 -0
- package/shell/src/SessionsHoverCard.test.tsx +0 -256
package/src/index.ts
CHANGED
|
@@ -120,6 +120,40 @@ export type {
|
|
|
120
120
|
SessionsHoverCardSurface,
|
|
121
121
|
} from "../shell/src/SessionsHoverCard";
|
|
122
122
|
|
|
123
|
+
// App shell: sidebar and main page layout. Widths come from the
|
|
124
|
+
// `--app-shell-*` CSS variables that `AppShell` sets.
|
|
125
|
+
export { AppShell } from "../shell/src/AppShell";
|
|
126
|
+
export type { AppShellProps } from "../shell/src/AppShell";
|
|
127
|
+
export { AppSidebar } from "../shell/src/AppSidebar";
|
|
128
|
+
export type { AppSidebarProps } from "../shell/src/AppSidebar";
|
|
129
|
+
export { SidebarRail, RailTile, RailDivider } from "../shell/src/SidebarRail";
|
|
130
|
+
export type { SidebarRailProps, RailTileProps, RailDividerProps } from "../shell/src/SidebarRail";
|
|
131
|
+
export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize";
|
|
132
|
+
export type {
|
|
133
|
+
AppShellResize,
|
|
134
|
+
SidebarResizeHandleProps,
|
|
135
|
+
SidebarResizeOptions,
|
|
136
|
+
} from "../shell/src/SidebarResize";
|
|
137
|
+
export { SidebarIconTooltip } from "../shell/src/SidebarIconTooltip";
|
|
138
|
+
export type { SidebarIconTooltipProps } from "../shell/src/SidebarIconTooltip";
|
|
139
|
+
export { SidebarPanel } from "../shell/src/SidebarPanel";
|
|
140
|
+
export type { SidebarPanelProps } from "../shell/src/SidebarPanel";
|
|
141
|
+
export { SidebarAccountMenu, SidebarAccountMenuPlaceholder } from "../shell/src/SidebarAccountMenu";
|
|
142
|
+
export type {
|
|
143
|
+
SidebarAccountMenuProps,
|
|
144
|
+
SidebarAccountMenuPlaceholderProps,
|
|
145
|
+
} from "../shell/src/SidebarAccountMenu";
|
|
146
|
+
export { SignOutDialog } from "../shell/src/SignOutDialog";
|
|
147
|
+
export type { SignOutDialogProps } from "../shell/src/SignOutDialog";
|
|
148
|
+
export {
|
|
149
|
+
railBadgeClass,
|
|
150
|
+
railTileClass,
|
|
151
|
+
railTileStateClass,
|
|
152
|
+
sidebarNavLinkTextClass,
|
|
153
|
+
sidebarNavRowClass,
|
|
154
|
+
sidebarSectionLabelClass,
|
|
155
|
+
} from "../shell/src/app-shell-classes";
|
|
156
|
+
|
|
123
157
|
// App helpers: confirm skip, update watcher, settings chrome, stable auth.
|
|
124
158
|
export * from "../app/src/index";
|
|
125
159
|
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ComponentType, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/** The `ViewTransition` props used here. Typed locally so consumers on `@types/react` without `ViewTransition` still typecheck. */
|
|
5
|
+
type ViewTransitionLikeProps = {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
default?: string;
|
|
8
|
+
enter?: string;
|
|
9
|
+
exit?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const ViewTransition: ComponentType<ViewTransitionLikeProps> = Reflect.get(React, "ViewTransition");
|
|
2
13
|
|
|
3
14
|
export interface PanelTransitionProps {
|
|
4
15
|
children?: ReactNode;
|
package/tokens/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# `@vvedantb/ui/tokens`
|
|
2
|
+
|
|
3
|
+
Design tokens and shared Tailwind v4 CSS for the vvedantb web apps. The CSS and Tailwind preset are subpaths of `@vvedantb/ui`; the native JS tokens are named exports of the root (`tokens`, `Tokens`). Source-exported: no build step. Paths in the `File` column are relative to `packages/ui/tokens/`.
|
|
4
|
+
|
|
5
|
+
## Exports
|
|
6
|
+
|
|
7
|
+
| Export | File | What it is |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `@vvedantb/ui/tokens`, `@vvedantb/ui/tokens/tokens.css` | `src/tokens.css` | Colour, radius, shadow, ease and font tokens (`@theme`), light/dark variables, `dark` variant, `*` border and `body` defaults. In 0.2.1 it also defines shadcn-style aliases (`primary`, `muted-foreground`, `secondary`, `destructive`, `card`, `popover`, `input`, `ring`) that point at the same tokens. |
|
|
10
|
+
| `tokens` and `Tokens` from `@vvedantb/ui` | `src/native.ts` | JS colours, radii and spacing for React Native. `@vvedantb/native-ui` keeps its own copy in `src/tokens.ts`; a test keeps the two equal. |
|
|
11
|
+
| `@vvedantb/ui/tokens/css/base.css` | `src/css/base.css` | `html` touch/accent, `::selection`, control transitions, pointer cursor, range accent (`@layer base`). |
|
|
12
|
+
| `@vvedantb/ui/tokens/css/dialog.css` | `src/css/dialog.css` | Unlayered `max-width: none` for `@vvedantb/ui` compact (bottom-sheet) dialogs. |
|
|
13
|
+
| `@vvedantb/ui/tokens/css/modal.css` | `src/css/modal.css` | `.t-modal`, `.is-open`, `.is-closing` and `t-modal-presence-wait` (`@layer components`). |
|
|
14
|
+
| `@vvedantb/ui/tokens/css/tabs.css` | `src/css/tabs.css` | `.t-tab`, active colour, `.t-tabs-pill`, small-screen `.t-tabs` scrolling. |
|
|
15
|
+
| `@vvedantb/ui/tokens/css/tabs-pills.css` | `src/css/tabs-pills.css` | `--tabs-*` colour variables, `.t-tabs--segmented`, `.t-tabs--pills` and pill hover / active fills. |
|
|
16
|
+
| `@vvedantb/ui/tokens/css/utilities.css` | `src/css/utilities.css` | `@utility hit-target`, `@utility reveal-on-hover` and `@utility rounded-surface` (`clamp(0.75rem, var(--radius), 1rem)`). |
|
|
17
|
+
| `@vvedantb/ui/tokens/css/scrollbar-thin.css` | `src/css/scrollbar-thin.css` | `.scrollbar-thin` (`@layer utilities`, always emitted). |
|
|
18
|
+
| `@vvedantb/ui/tokens/css/animations.css` | `src/css/animations.css` | `animate-aurora`, `animate-fade-in-up`, `animate-indeterminate` as `@theme` (CSS-first apps). |
|
|
19
|
+
| `@vvedantb/ui/tokens/css/compat-shadcn-rgb.css`, `@vvedantb/ui/tokens/compat/shadcn-rgb.css` | `src/css/compat-shadcn-rgb.css` | Replaces `tokens.css` for apps with shadcn-style `R G B` channel variables. Defines only the UI-only `--color-*` names as `rgb(var(--x) / alpha)` references, `--radius-field`, `--scrollbar`, `--field-radius` and a `glass-panel-strong` fallback. Import it **or** `tokens.css`, never both. |
|
|
20
|
+
| `@vvedantb/ui/tokens/css/index.css` | `src/css/index.css` | base + dialog + utilities + scrollbar-thin + animations, for new CSS-first apps. |
|
|
21
|
+
| `@vvedantb/ui/tokens/tailwind-preset` | `src/tailwind-preset.mjs` (+ `.d.mts`) | Tailwind preset for apps that load a JS config with `@config`. |
|
|
22
|
+
|
|
23
|
+
Every file was extracted because the same rule (same at-rule context, selector and body) sits in 3 or more of the five apps. The measured duplication is in `verify/ANALYSIS.md`, and the proof that each app compiles to the same CSS after migrating is in `verify/RESULTS.md`. Blocks that only 2 apps share, or that drift in a way that would change an app's CSS, stay in the apps; `verify/ANALYSIS.md` lists them.
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
CSS-first app (no `tailwind.config`):
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
@import "tailwindcss";
|
|
31
|
+
@import "@vvedantb/ui/tokens";
|
|
32
|
+
@import "@vvedantb/ui/tokens/css/animations.css";
|
|
33
|
+
@import "@vvedantb/ui/tokens/css/base.css";
|
|
34
|
+
/* ...app @layer base rules... */
|
|
35
|
+
@import "@vvedantb/ui/tokens/css/modal.css";
|
|
36
|
+
@import "@vvedantb/ui/tokens/css/tabs.css";
|
|
37
|
+
/* ...app @layer components rules... */
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
App with a JS config (`@config "../tailwind.config.ts"`):
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { tokensPreset } from "@vvedantb/ui/tokens/tailwind-preset";
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
presets: [tokensPreset()],
|
|
47
|
+
// or tokensPreset({ color: (name) => `color-mix(in oklch, var(--${name}) calc(<alpha-value> * 100%), transparent)` })
|
|
48
|
+
content: ["./src/**/*.{ts,tsx}"],
|
|
49
|
+
theme: { extend: { /* app-only colours, fonts, animations */ } },
|
|
50
|
+
plugins: [tailwindcssAnimate],
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The preset holds `darkMode: "class"`, the shared colour map (`border`, `surface.*`, `danger.*`, `field.*`, shadcn aliases `primary`/`secondary`/`destructive`/`card`/`popover`/`input` ...), `borderRadius` lg/md/sm/field, `boxShadow` soft/panel/insetSoft, `ease-smooth`, `screens` xs to 2xl in px, and the aurora / fade-in-up / indeterminate / accordion keyframes. It does not hold plugins, `content`, fonts, `accent`/`muted`/`ring`/`sidebar` (they differ per app) or accordion timings.
|
|
55
|
+
|
|
56
|
+
Do not import `css/animations.css` in an app that uses the preset: the preset already defines the same keyframes and animations.
|
|
57
|
+
|
|
58
|
+
### Where to put the imports
|
|
59
|
+
|
|
60
|
+
Tailwind inlines an `@import` where it sits, even in the middle of a file (it must be at top level, not inside an `@layer` block). Put each import where the app's own copy of the rules was. Within one layer, later rules win at equal specificity, so moving shared rules above or below app rules can flip the result for elements matched by both. `examples/migration.md` gives the exact position for each app, and `pnpm --filter @vvedantb/ui verify` checks it.
|
|
61
|
+
|
|
62
|
+
### Variables each file needs
|
|
63
|
+
|
|
64
|
+
| File | Needs | Provided by |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `base.css` | `--accent`, `--foreground` | tokens.css or the app theme |
|
|
67
|
+
| `dialog.css` | none | |
|
|
68
|
+
| `modal.css` | `--modal-open-dur`, `--modal-close-dur`, `--modal-scale`, `--modal-scale-close`, `--modal-ease` | app `:root` |
|
|
69
|
+
| `tabs.css` | `--tabs-dur`, `--tabs-ease` (app `:root`); `--tabs-text-muted`, `--tabs-text-active`, `--tabs-pill-bg` | colours: tabs-pills.css or the app theme |
|
|
70
|
+
| `tabs-pills.css` | `--muted`, `--segment`, `--segment-foreground`, `--default` | tokens.css or the app theme |
|
|
71
|
+
| `utilities.css` | `--breakpoint-sm` (Tailwind default or app theme) | Tailwind |
|
|
72
|
+
| `scrollbar-thin.css` | `--scrollbar` | tokens.css or the app theme |
|
|
73
|
+
| `animations.css` | none | |
|
|
74
|
+
| `tailwind-preset` | the CSS variables named in its colour map, `--radius`, `--field-radius` | tokens.css or the app theme |
|
|
75
|
+
|
|
76
|
+
### Using an existing shadcn RGB theme
|
|
77
|
+
|
|
78
|
+
See the package `README.md`. With the compat file, `base.css`, `scrollbar-thin.css`, `utilities.css`, `dialog.css`, `modal.css` and `tabs.css` need no `tokens.css`. `base.css` reads `--accent` and `--foreground` and `tabs-pills.css` reads `--muted`, `--segment` and `--default`. Those are not channel-compatible, so skip `tabs-pills.css` and `index.css` (which includes `base.css`) unless the app defines those variables as full colours.
|
|
79
|
+
|
|
80
|
+
### Parameters
|
|
81
|
+
|
|
82
|
+
Where apps share a rule but drifted in one value, the value is a custom property whose fallback is the most common value. Set it on `:root` to keep a different value.
|
|
83
|
+
|
|
84
|
+
| File | Property | Default | Set by |
|
|
85
|
+
| --- | --- | --- | --- |
|
|
86
|
+
| `base.css` | `--tokens-control-transition-property` | `background-color, border-color, color, box-shadow, transform, opacity` | app-c: `background-color, color, transform, opacity` |
|
|
87
|
+
| `base.css` | `--tokens-control-transition-duration` | `240ms` | app-c: `100ms` |
|
|
88
|
+
|
|
89
|
+
## Develop
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
pnpm --filter @vvedantb/ui build # export targets exist + tsc (primitives, shell, app)
|
|
93
|
+
pnpm --filter @vvedantb/ui test # vitest (app helpers) + offline node --test: exports, CSS structure, Tailwind compile, preset
|
|
94
|
+
pnpm --filter @vvedantb/ui analyze # rule-level duplication across the app clones -> verify/ANALYSIS.tables.md
|
|
95
|
+
pnpm --filter @vvedantb/ui verify # before/after compile of every app -> verify/RESULTS.md, examples/migration.md
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`analyze` and `verify` need the app clones (`APPS_DIR`, default `/workspace/cvx`; name or symlink the clones `app-a` to `app-e` inside it) and network access the first time: they install Tailwind 4.3.3, the plugins, postcss and jiti into a scratch directory (`VERIFY_DIR`, default `/workspace/pk-tokens-verify`, outside the repo). The migration for each app is data in `verify/migrations/<app>.json`. Each removed block must equal the shared file's block with the same context and selector, or the run fails.
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
// @vitest-environment happy-dom
|
|
2
|
-
import { act, createRef } from "react";
|
|
3
|
-
import { createRoot, type Root } from "react-dom/client";
|
|
4
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
import { SessionsHoverCard } from "./SessionsHoverCard";
|
|
6
|
-
|
|
7
|
-
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
-
|
|
9
|
-
let root: Root | null = null;
|
|
10
|
-
let host: HTMLElement | null = null;
|
|
11
|
-
|
|
12
|
-
async function mount(node: React.ReactNode) {
|
|
13
|
-
host = document.createElement("div");
|
|
14
|
-
document.body.appendChild(host);
|
|
15
|
-
root = createRoot(host);
|
|
16
|
-
await act(async () => {
|
|
17
|
-
root!.render(node);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
afterEach(async () => {
|
|
22
|
-
await act(async () => root?.unmount());
|
|
23
|
-
host?.remove();
|
|
24
|
-
document.body.innerHTML = "";
|
|
25
|
-
root = null;
|
|
26
|
-
host = null;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("SessionsHoverCard", () => {
|
|
30
|
-
it("renders header, body and footer slots when open", async () => {
|
|
31
|
-
await mount(
|
|
32
|
-
<SessionsHoverCard open header="Head" body="Body text" footer="Foot">
|
|
33
|
-
<button type="button">Row</button>
|
|
34
|
-
</SessionsHoverCard>,
|
|
35
|
-
);
|
|
36
|
-
const text = document.body.textContent ?? "";
|
|
37
|
-
expect(text).toContain("Row");
|
|
38
|
-
expect(text).toContain("Head");
|
|
39
|
-
expect(text).toContain("Body text");
|
|
40
|
-
expect(text).toContain("Foot");
|
|
41
|
-
expect(document.body.innerHTML).toContain("w-64");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("does not call the body render prop or loadContent while closed", async () => {
|
|
45
|
-
const body = vi.fn(() => "x");
|
|
46
|
-
const loadContent = vi.fn(() => "y");
|
|
47
|
-
await mount(
|
|
48
|
-
<>
|
|
49
|
-
<SessionsHoverCard open={false} body={body}>
|
|
50
|
-
<button type="button">A</button>
|
|
51
|
-
</SessionsHoverCard>
|
|
52
|
-
<SessionsHoverCard open={false} loadContent={loadContent}>
|
|
53
|
-
<button type="button">B</button>
|
|
54
|
-
</SessionsHoverCard>
|
|
55
|
-
</>,
|
|
56
|
-
);
|
|
57
|
-
expect(body).not.toHaveBeenCalled();
|
|
58
|
-
expect(loadContent).not.toHaveBeenCalled();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("calls the render prop with open true and loads content once when open", async () => {
|
|
62
|
-
const body = vi.fn((ctx: { open: boolean }) => `open=${ctx.open}`);
|
|
63
|
-
const loadContent = vi.fn(async () => "Loaded preview");
|
|
64
|
-
await mount(
|
|
65
|
-
<>
|
|
66
|
-
<SessionsHoverCard open body={body}>
|
|
67
|
-
<button type="button">A</button>
|
|
68
|
-
</SessionsHoverCard>
|
|
69
|
-
<SessionsHoverCard open loadContent={loadContent} loadingFallback="Loading">
|
|
70
|
-
<button type="button">B</button>
|
|
71
|
-
</SessionsHoverCard>
|
|
72
|
-
</>,
|
|
73
|
-
);
|
|
74
|
-
expect(body).toHaveBeenCalledWith({ open: true });
|
|
75
|
-
expect(document.body.textContent).toContain("open=true");
|
|
76
|
-
expect(loadContent).toHaveBeenCalledTimes(1);
|
|
77
|
-
expect(document.body.textContent).toContain("Loaded preview");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("portals the content to document.body by default", async () => {
|
|
81
|
-
await mount(
|
|
82
|
-
<div id="clip" style={{ overflow: "hidden" }}>
|
|
83
|
-
<SessionsHoverCard open body="Body text">
|
|
84
|
-
<button type="button">Row</button>
|
|
85
|
-
</SessionsHoverCard>
|
|
86
|
-
</div>,
|
|
87
|
-
);
|
|
88
|
-
const content = document.querySelector("[data-radix-popper-content-wrapper]");
|
|
89
|
-
expect(content).not.toBeNull();
|
|
90
|
-
expect(document.getElementById("clip")!.contains(content)).toBe(false);
|
|
91
|
-
expect(document.body.textContent).toContain("Body text");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("keeps the content in place with portal={false}", async () => {
|
|
95
|
-
await mount(
|
|
96
|
-
<div id="clip" style={{ overflow: "hidden" }}>
|
|
97
|
-
<SessionsHoverCard open portal={false} body="Body text">
|
|
98
|
-
<button type="button">Row</button>
|
|
99
|
-
</SessionsHoverCard>
|
|
100
|
-
</div>,
|
|
101
|
-
);
|
|
102
|
-
const content = document.querySelector("[data-radix-popper-content-wrapper]");
|
|
103
|
-
expect(document.getElementById("clip")!.contains(content)).toBe(true);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("swaps the surface without keeping the default one", async () => {
|
|
107
|
-
await mount(
|
|
108
|
-
<>
|
|
109
|
-
<SessionsHoverCard open surface="glass" body="G" className="p-5">
|
|
110
|
-
<button type="button">A</button>
|
|
111
|
-
</SessionsHoverCard>
|
|
112
|
-
</>,
|
|
113
|
-
);
|
|
114
|
-
const card = document.querySelector("[data-state=open][data-side]") as HTMLElement;
|
|
115
|
-
expect(card.className).toContain("glass-panel-strong");
|
|
116
|
-
expect(card.className).toContain("rounded-surface");
|
|
117
|
-
expect(card.className).not.toContain("bg-overlay");
|
|
118
|
-
expect(card.className).not.toContain("rounded-lg");
|
|
119
|
-
expect(card.className).toContain("p-5");
|
|
120
|
-
expect(card.className).not.toContain("p-3");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("uses the floating overlay surface by default", async () => {
|
|
124
|
-
await mount(
|
|
125
|
-
<SessionsHoverCard open body="B">
|
|
126
|
-
<button type="button">A</button>
|
|
127
|
-
</SessionsHoverCard>,
|
|
128
|
-
);
|
|
129
|
-
const card = document.querySelector("[data-state=open][data-side]") as HTMLElement;
|
|
130
|
-
expect(card.className).toContain("bg-overlay");
|
|
131
|
-
expect(card.className).toContain("rounded-lg");
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("forwards the ref and props to the child trigger and keeps its handlers", async () => {
|
|
135
|
-
const ref = createRef<HTMLButtonElement>();
|
|
136
|
-
const onClick = vi.fn();
|
|
137
|
-
await mount(
|
|
138
|
-
<SessionsHoverCard ref={ref as never} data-testid="row" body="B">
|
|
139
|
-
<button type="button" onClick={onClick}>
|
|
140
|
-
Row
|
|
141
|
-
</button>
|
|
142
|
-
</SessionsHoverCard>,
|
|
143
|
-
);
|
|
144
|
-
const button = document.querySelector("button") as HTMLButtonElement;
|
|
145
|
-
expect(ref.current).toBe(button);
|
|
146
|
-
expect(button.getAttribute("data-testid")).toBe("row");
|
|
147
|
-
await act(async () => button.click());
|
|
148
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("renders its own trigger element with asChild={false}", async () => {
|
|
152
|
-
await mount(
|
|
153
|
-
<SessionsHoverCard asChild={false} body="B">
|
|
154
|
-
<span>Row</span>
|
|
155
|
-
</SessionsHoverCard>,
|
|
156
|
-
);
|
|
157
|
-
const trigger = document.querySelector("[data-state]") as HTMLElement;
|
|
158
|
-
expect(trigger.tagName).toBe("A");
|
|
159
|
-
expect(trigger.textContent).toBe("Row");
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe("focus and pointer", () => {
|
|
163
|
-
function setFocusVisible(el: HTMLElement, value: boolean) {
|
|
164
|
-
const orig = el.matches.bind(el);
|
|
165
|
-
el.matches = (sel: string) => (sel === ":focus-visible" ? value : orig(sel));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
it("does not open on pointer-driven focus after a context menu", async () => {
|
|
169
|
-
const onOpenChange = vi.fn();
|
|
170
|
-
await mount(
|
|
171
|
-
<SessionsHoverCard openDelay={0} header="Head" onOpenChange={onOpenChange}>
|
|
172
|
-
<button type="button">Row</button>
|
|
173
|
-
</SessionsHoverCard>,
|
|
174
|
-
);
|
|
175
|
-
const row = document.querySelector("button")!;
|
|
176
|
-
setFocusVisible(row, false);
|
|
177
|
-
await act(async () => {
|
|
178
|
-
row.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
|
|
179
|
-
row.dispatchEvent(new FocusEvent("focus", { bubbles: false }));
|
|
180
|
-
row.dispatchEvent(new FocusEvent("focusin", { bubbles: true }));
|
|
181
|
-
});
|
|
182
|
-
await act(async () => new Promise((r) => setTimeout(r, 20)));
|
|
183
|
-
expect(onOpenChange).not.toHaveBeenCalledWith(true);
|
|
184
|
-
expect(document.body.textContent).not.toContain("Head");
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("opens on keyboard focus-visible", async () => {
|
|
188
|
-
const onOpenChange = vi.fn();
|
|
189
|
-
await mount(
|
|
190
|
-
<SessionsHoverCard openDelay={0} header="Head" onOpenChange={onOpenChange}>
|
|
191
|
-
<button type="button">Row</button>
|
|
192
|
-
</SessionsHoverCard>,
|
|
193
|
-
);
|
|
194
|
-
const row = document.querySelector("button")!;
|
|
195
|
-
setFocusVisible(row, true);
|
|
196
|
-
await act(async () => {
|
|
197
|
-
row.dispatchEvent(new FocusEvent("focusin", { bubbles: true }));
|
|
198
|
-
});
|
|
199
|
-
await act(async () => new Promise((r) => setTimeout(r, 20)));
|
|
200
|
-
expect(onOpenChange).toHaveBeenCalledWith(true);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
// React derives onPointerLeave from native pointerout (with a null or outside
|
|
204
|
-
// relatedTarget). A native pointerleave event does not reach the handler.
|
|
205
|
-
function leave(el: HTMLElement) {
|
|
206
|
-
return act(async () => {
|
|
207
|
-
el.dispatchEvent(new PointerEvent("pointerout", { pointerType: "mouse", bubbles: true, relatedTarget: null }));
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
it("closes on pointer leave when stuck open by non-focus-visible focus", async () => {
|
|
212
|
-
const onOpenChange = vi.fn();
|
|
213
|
-
await mount(
|
|
214
|
-
<SessionsHoverCard defaultOpen header="Head" onOpenChange={onOpenChange}>
|
|
215
|
-
<button type="button">Row</button>
|
|
216
|
-
</SessionsHoverCard>,
|
|
217
|
-
);
|
|
218
|
-
const row = document.querySelector("button")!;
|
|
219
|
-
setFocusVisible(row, false);
|
|
220
|
-
row.focus();
|
|
221
|
-
await leave(row);
|
|
222
|
-
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
223
|
-
await act(async () => new Promise((r) => setTimeout(r, 20)));
|
|
224
|
-
expect(document.body.textContent).not.toContain("Head");
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("stays open on pointer leave with keyboard focus-visible", async () => {
|
|
228
|
-
const onOpenChange = vi.fn();
|
|
229
|
-
await mount(
|
|
230
|
-
<SessionsHoverCard defaultOpen header="Head" onOpenChange={onOpenChange}>
|
|
231
|
-
<button type="button">Row</button>
|
|
232
|
-
</SessionsHoverCard>,
|
|
233
|
-
);
|
|
234
|
-
const row = document.querySelector("button")!;
|
|
235
|
-
setFocusVisible(row, true);
|
|
236
|
-
row.focus();
|
|
237
|
-
await leave(row);
|
|
238
|
-
await act(async () => new Promise((r) => setTimeout(r, 20)));
|
|
239
|
-
expect(onOpenChange).not.toHaveBeenCalledWith(false);
|
|
240
|
-
expect(document.body.textContent).toContain("Head");
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("does not force-close on pointer leave without focus (Radix owns hover close)", async () => {
|
|
244
|
-
const onOpenChange = vi.fn();
|
|
245
|
-
await mount(
|
|
246
|
-
<SessionsHoverCard defaultOpen closeDelay={1000} header="Head" onOpenChange={onOpenChange}>
|
|
247
|
-
<button type="button">Row</button>
|
|
248
|
-
</SessionsHoverCard>,
|
|
249
|
-
);
|
|
250
|
-
const row = document.querySelector("button")!;
|
|
251
|
-
await leave(row);
|
|
252
|
-
expect(onOpenChange).not.toHaveBeenCalledWith(false);
|
|
253
|
-
expect(document.body.textContent).toContain("Head");
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|