@checkstack/ui 1.6.1 → 1.7.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/CHANGELOG.md +120 -0
- package/package.json +5 -4
- package/src/components/Dialog.tsx +25 -15
- package/src/components/DynamicForm/MultiTypeEditorField.tsx +1 -1
- package/src/components/Menu.tsx +76 -0
- package/src/components/Popover.tsx +45 -0
- package/src/components/UserMenu.tsx +99 -59
- package/src/hooks/useIsMobile.ts +21 -0
- package/src/index.ts +3 -1
- package/tsconfig.json +12 -1
- package/src/components/DropdownMenu.tsx +0 -187
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,125 @@
|
|
|
1
1
|
# @checkstack/ui
|
|
2
2
|
|
|
3
|
+
## 1.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 50e5f5f: Runtime plugin system: install + uninstall plugins from npm, GitHub releases
|
|
8
|
+
(including private GitHub Enterprise instances), or tarball uploads at
|
|
9
|
+
runtime, with multi-package bundles, dependency-derived compatibility checks,
|
|
10
|
+
multi-instance coordination via a Postgres artifact store, and
|
|
11
|
+
single-coordinator destructive cleanup.
|
|
12
|
+
|
|
13
|
+
Highlights:
|
|
14
|
+
|
|
15
|
+
- New `PluginSource` discriminated union and `PluginInstaller` /
|
|
16
|
+
`PluginInstallerRegistry` interfaces in `@checkstack/backend-api`. The
|
|
17
|
+
GitHub variant accepts an optional `apiBaseUrl` so deployments backed by
|
|
18
|
+
GitHub Enterprise can install from `https://ghe.example.com/api/v3`
|
|
19
|
+
instead of `api.github.com`.
|
|
20
|
+
- New `installPackageMetadataSchema` (Zod) in `@checkstack/common` validates
|
|
21
|
+
every plugin's `package.json` at install time. Required fields: `name`,
|
|
22
|
+
`version`, `description`, `author`, `license`, `checkstack.type`,
|
|
23
|
+
`checkstack.pluginId`. Optional: `checkstack.bundle`,
|
|
24
|
+
`checkstack.usageInstructions`, `checkstack.allowInstallScripts`.
|
|
25
|
+
- New `pluginManagerContract` in `@checkstack/pluginmanager-common` with
|
|
26
|
+
`list`, `previewInstall`, `install`, `previewUninstall`, `uninstall`, and
|
|
27
|
+
`events` procedures.
|
|
28
|
+
- New `@checkstack/pluginmanager-frontend` admin UI: installed-plugins list
|
|
29
|
+
with per-row uninstall (typed-confirmation modal, schema/configs/cascade
|
|
30
|
+
toggles), install page with NPM / Tarball Upload / GitHub Release tabs
|
|
31
|
+
(Catalog tab disabled — coming soon), and an events page surfacing the
|
|
32
|
+
install/uninstall audit log.
|
|
33
|
+
- New `bunx @checkstack/scripts plugin-pack` CLI for plugin authors —
|
|
34
|
+
per-package mode produces an npm-shaped tarball; `--bundle` mode produces
|
|
35
|
+
an outer tarball containing every sibling declared in
|
|
36
|
+
`package.json#checkstack.bundle`. Published to npm so external authors
|
|
37
|
+
can `bunx` it directly without a workspace checkout.
|
|
38
|
+
- Compatibility derived from `package.json#dependencies` ranges
|
|
39
|
+
(`semver.satisfies` against the platform's loaded `@checkstack/*`
|
|
40
|
+
versions) — no separate `compatibility` field.
|
|
41
|
+
- Multi-instance: originator persists artifacts + `plugins` rows + broadcasts
|
|
42
|
+
install/uninstall; receiving instances do in-process register/unregister
|
|
43
|
+
only. Destructive ops (drop schema, delete plugin_configs, delete
|
|
44
|
+
artifacts, delete `plugins` rows) run exactly once on the originator.
|
|
45
|
+
- Fresh-instance bootstrap: `loadPlugins()` hydrates any
|
|
46
|
+
`is_uninstallable=true` plugin missing from `node_modules` from the
|
|
47
|
+
artifact store before normal Phase 1 register.
|
|
48
|
+
- New schema: `plugin_artifacts` (tarball storage), `plugin_install_events`
|
|
49
|
+
(audit/error log). `plugins` extended with `version`, `metadata`,
|
|
50
|
+
`source`, `bundle_id`, `is_primary`. Local plugin sync now writes
|
|
51
|
+
`version` from each plugin's `package.json` so the admin UI shows real
|
|
52
|
+
versions instead of `—`.
|
|
53
|
+
- Tarball-upload endpoint (`POST /api/pluginmanager/upload-tarball`) for
|
|
54
|
+
the install UI; access-gated by `pluginmanager.plugin.manage`.
|
|
55
|
+
- Plugin Manager menu link added to the user menu (main grid, alongside
|
|
56
|
+
Profile / Notification Settings / etc.).
|
|
57
|
+
|
|
58
|
+
Cross-cutting changes:
|
|
59
|
+
|
|
60
|
+
- Backend request/response logging now flows through `rootLogger` (winston)
|
|
61
|
+
instead of `hono/logger`. 5xx responses include the response body inline
|
|
62
|
+
so swallowed early-return errors are visible in the log.
|
|
63
|
+
- The `/api/:pluginId/*` dispatcher now logs which core service is missing
|
|
64
|
+
or which `pluginId` had no metadata when it 500s.
|
|
65
|
+
- New `registerCorePluginMetadata` on `PluginManager` for core routers
|
|
66
|
+
(like the plugin manager itself) that need their metadata visible to the
|
|
67
|
+
RPC dispatcher without going through the full plugin lifecycle.
|
|
68
|
+
- ESLint: `unicorn/no-null` is now disabled globally. Drizzle distinguishes
|
|
69
|
+
between `null` (writes a real SQL NULL) and `undefined` (skip the column
|
|
70
|
+
on insert), so treating them as interchangeable produced latent bugs at
|
|
71
|
+
the persistence boundary. The bulk of the patch-bumped packages above
|
|
72
|
+
reflect lint-fix touches that landed when this rule was relaxed.
|
|
73
|
+
- Workspace-wide license normalization to `Elastic-2.0` (matches
|
|
74
|
+
`LICENSE.md`). Every `package.json` in the workspace now declares the
|
|
75
|
+
same SPDX identifier; the patch bumps capture this.
|
|
76
|
+
|
|
77
|
+
Plugin packages (every `plugins/*`): added a `pack` npm script
|
|
78
|
+
(`bunx @checkstack/scripts plugin-pack`), mirrored each plugin's
|
|
79
|
+
`pluginId` from `plugin-metadata.ts` into `package.json#checkstack.pluginId`
|
|
80
|
+
so install-time validation passes, stubbed any missing required metadata
|
|
81
|
+
fields (`description`, `author`, `license`), and added
|
|
82
|
+
`checkstack.bundle` to multi-package plugin primaries (telegram, rcon, ssh,
|
|
83
|
+
jira, queue-bullmq, queue-memory, cache-memory).
|
|
84
|
+
|
|
85
|
+
Breaking changes:
|
|
86
|
+
|
|
87
|
+
- The legacy single-method `PluginInstaller` interface (`install(packageName)`)
|
|
88
|
+
is removed. Callers must use `coreServices.pluginInstallerRegistry`.
|
|
89
|
+
- The old `pluginAdminContract` and `createPluginAdminRouter` are removed.
|
|
90
|
+
Replaced by `pluginManagerContract` in `@checkstack/pluginmanager-common`
|
|
91
|
+
and `createPluginManagerRouter` in `core/backend`.
|
|
92
|
+
- `@checkstack/test-utils-backend` no longer exports
|
|
93
|
+
`createMockPluginInstaller` / `MockPluginInstaller` (the legacy interface
|
|
94
|
+
it shimmed is gone).
|
|
95
|
+
|
|
96
|
+
Note: bumps are limited to `minor` (for packages with new public API
|
|
97
|
+
surface) and `patch` (for downstream consumers, license normalization,
|
|
98
|
+
and lint fixes). No `major` bumps despite the `PluginInstaller` removal —
|
|
99
|
+
the legacy interface had no third-party consumers in the wild before this
|
|
100
|
+
runtime plugin system landed, and the contract surface is the same shape
|
|
101
|
+
modulo the rename.
|
|
102
|
+
|
|
103
|
+
- Updated dependencies [50e5f5f]
|
|
104
|
+
- @checkstack/common@0.8.0
|
|
105
|
+
- @checkstack/frontend-api@0.4.2
|
|
106
|
+
|
|
107
|
+
## 1.7.0
|
|
108
|
+
|
|
109
|
+
### Minor Changes
|
|
110
|
+
|
|
111
|
+
- 32d52c6: Fix several modal/sheet/overlay closing issues:
|
|
112
|
+
|
|
113
|
+
- Replace the custom `DropdownMenu` container with a Radix-based `Popover` (desktop) and `Sheet` (mobile). The previous mobile implementation suppressed outside-click closing, leaving the notification bell's panel only closable by clicking the bell again. `UserMenu` and `NotificationBell` were updated to the new pattern. Leaf primitives `DropdownMenuItem`, `DropdownMenuLabel`, and `DropdownMenuSeparator` are preserved (now backed by a `MenuCloseContext`) so existing call sites continue to work.
|
|
114
|
+
- Fix `Dialog` outside-click closing. The previous structure made `DialogPrimitive.Content` cover the full viewport, so Radix never registered clicks on the dimmed area as "outside" — only ESC could close the modal. The centering wrapper is now a non-Content `<div>` and the actual modal box is the Content, so outside-click closes correctly. A visible X button is now rendered by default; pass `hideCloseButton` to suppress it (e.g. for the search overlay where it would clash with a custom header).
|
|
115
|
+
- Export a standalone `useIsMobile` hook and a new `Popover` primitive.
|
|
116
|
+
- Prevent Radix's auto-focus-return on `NotificationBell` and `UserMenu` overlays. Closing via an item with a `<Link>` (e.g. "View all notifications") would synchronously refocus the trigger via `onCloseAutoFocus`, stealing focus from the link mid-click on pages where another element held focus and requiring a second click to navigate.
|
|
117
|
+
|
|
118
|
+
### Patch Changes
|
|
119
|
+
|
|
120
|
+
- Updated dependencies [32d52c6]
|
|
121
|
+
- @checkstack/frontend-api@0.4.1
|
|
122
|
+
|
|
3
123
|
## 1.6.1
|
|
4
124
|
|
|
5
125
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
|
+
"license": "Elastic-2.0",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "src/index.ts",
|
|
6
7
|
"dependencies": {
|
|
7
8
|
"@checkstack/common": "0.7.0",
|
|
8
|
-
"@checkstack/frontend-api": "0.
|
|
9
|
+
"@checkstack/frontend-api": "0.4.1",
|
|
9
10
|
"@monaco-editor/react": "^4.7.0",
|
|
10
11
|
"@radix-ui/react-accordion": "^1.2.12",
|
|
11
12
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
@@ -31,14 +32,14 @@
|
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@checkstack/scripts": "0.1.2",
|
|
33
34
|
"@checkstack/test-utils-frontend": "0.0.4",
|
|
34
|
-
"@checkstack/tsconfig": "0.0.
|
|
35
|
+
"@checkstack/tsconfig": "0.0.6",
|
|
35
36
|
"@testing-library/react": "^16.0.0",
|
|
36
37
|
"@types/react": "^18.2.0",
|
|
37
38
|
"@types/react-dom": "^19.2.3",
|
|
38
39
|
"typescript": "^5.0.0"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
|
-
"typecheck": "
|
|
42
|
+
"typecheck": "tsgo -b",
|
|
42
43
|
"lint": "bun run lint:code",
|
|
43
44
|
"lint:code": "eslint . --max-warnings 0",
|
|
44
45
|
"test": "bun test"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
3
3
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
4
|
+
import { X } from "lucide-react";
|
|
4
5
|
import { cn } from "../utils";
|
|
5
6
|
import { usePerformance } from "./PerformanceProvider";
|
|
6
7
|
|
|
@@ -54,33 +55,42 @@ interface DialogContentProps
|
|
|
54
55
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>,
|
|
55
56
|
VariantProps<typeof dialogContentVariants> {}
|
|
56
57
|
|
|
58
|
+
interface DialogContentExtraProps {
|
|
59
|
+
hideCloseButton?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
const DialogContent = React.forwardRef<
|
|
58
63
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
59
|
-
DialogContentProps
|
|
60
|
-
>(({ className, children, size, ...props }, ref) => {
|
|
64
|
+
DialogContentProps & DialogContentExtraProps
|
|
65
|
+
>(({ className, children, size, hideCloseButton, ...props }, ref) => {
|
|
61
66
|
const { isLowPower } = usePerformance();
|
|
62
67
|
return (
|
|
63
68
|
<DialogPortal>
|
|
64
69
|
<DialogOverlay />
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"fixed inset-0 z-50 flex items-center justify-center p-4",
|
|
69
|
-
!isLowPower && "duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
70
|
-
)}
|
|
71
|
-
{...props}
|
|
72
|
-
>
|
|
73
|
-
<div
|
|
70
|
+
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none">
|
|
71
|
+
<DialogPrimitive.Content
|
|
72
|
+
ref={ref}
|
|
74
73
|
className={cn(
|
|
74
|
+
"pointer-events-auto relative",
|
|
75
75
|
dialogContentVariants({ size }),
|
|
76
|
-
!isLowPower &&
|
|
76
|
+
!isLowPower &&
|
|
77
|
+
"duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
|
77
78
|
className,
|
|
78
79
|
)}
|
|
80
|
+
{...props}
|
|
79
81
|
>
|
|
80
|
-
{/* Wrapper with negative margin and positive padding to allow focus rings to extend */}
|
|
81
82
|
<div className="-mx-2 px-2">{children}</div>
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
{!hideCloseButton && (
|
|
84
|
+
<DialogPrimitive.Close
|
|
85
|
+
className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
|
|
86
|
+
aria-label="Close"
|
|
87
|
+
>
|
|
88
|
+
<X className="h-4 w-4" />
|
|
89
|
+
<span className="sr-only">Close</span>
|
|
90
|
+
</DialogPrimitive.Close>
|
|
91
|
+
)}
|
|
92
|
+
</DialogPrimitive.Content>
|
|
93
|
+
</div>
|
|
84
94
|
</DialogPortal>
|
|
85
95
|
);
|
|
86
96
|
});
|
|
@@ -123,7 +123,7 @@ export const MultiTypeEditorField: React.FC<MultiTypeEditorFieldProps> = ({
|
|
|
123
123
|
obj[pair.key] = pair.value;
|
|
124
124
|
}
|
|
125
125
|
try {
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
onChange(JSON.stringify(obj, null, 2));
|
|
128
128
|
return;
|
|
129
129
|
} catch {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { createContext, useContext } from "react";
|
|
2
|
+
import { cn } from "../utils";
|
|
3
|
+
|
|
4
|
+
export const MenuCloseContext = createContext<{ onClose?: () => void }>({});
|
|
5
|
+
|
|
6
|
+
export const DropdownMenuItem: React.FC<{
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
onClick?: () => void;
|
|
9
|
+
className?: string;
|
|
10
|
+
icon?: React.ReactNode;
|
|
11
|
+
description?: React.ReactNode;
|
|
12
|
+
closeOnClick?: boolean;
|
|
13
|
+
}> = ({
|
|
14
|
+
children,
|
|
15
|
+
onClick,
|
|
16
|
+
className,
|
|
17
|
+
icon,
|
|
18
|
+
description,
|
|
19
|
+
closeOnClick = true,
|
|
20
|
+
}) => {
|
|
21
|
+
const { onClose } = useContext(MenuCloseContext);
|
|
22
|
+
|
|
23
|
+
const handleClick = () => {
|
|
24
|
+
if (onClick) onClick();
|
|
25
|
+
if (closeOnClick && onClose) onClose();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<button
|
|
30
|
+
onClick={handleClick}
|
|
31
|
+
className={cn(
|
|
32
|
+
"flex flex-col items-start w-full px-4 py-2 text-sm text-popover-foreground hover:bg-accent hover:text-accent-foreground transition-colors rounded-sm overflow-hidden",
|
|
33
|
+
className,
|
|
34
|
+
)}
|
|
35
|
+
role="menuitem"
|
|
36
|
+
type="button"
|
|
37
|
+
>
|
|
38
|
+
<div className="flex items-center w-full overflow-hidden">
|
|
39
|
+
{icon && (
|
|
40
|
+
<span className="mr-3 text-muted-foreground shrink-0">{icon}</span>
|
|
41
|
+
)}
|
|
42
|
+
<span className="flex-1 text-left truncate">{children}</span>
|
|
43
|
+
</div>
|
|
44
|
+
{description && (
|
|
45
|
+
<span
|
|
46
|
+
className={cn(
|
|
47
|
+
"text-[10px] text-muted-foreground mt-1 leading-tight text-left truncate w-full",
|
|
48
|
+
icon ? "pl-7" : "",
|
|
49
|
+
)}
|
|
50
|
+
>
|
|
51
|
+
{description}
|
|
52
|
+
</span>
|
|
53
|
+
)}
|
|
54
|
+
</button>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const DropdownMenuSeparator: React.FC<{ className?: string }> = ({
|
|
59
|
+
className,
|
|
60
|
+
}) => (
|
|
61
|
+
<div className={cn("my-1 h-px bg-border col-span-full", className)} />
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export const DropdownMenuLabel: React.FC<{
|
|
65
|
+
children: React.ReactNode;
|
|
66
|
+
className?: string;
|
|
67
|
+
}> = ({ children, className }) => (
|
|
68
|
+
<div
|
|
69
|
+
className={cn(
|
|
70
|
+
"px-4 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider col-span-full",
|
|
71
|
+
className,
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
{children}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
3
|
+
import { cn } from "../utils";
|
|
4
|
+
import { usePerformance } from "./PerformanceProvider";
|
|
5
|
+
|
|
6
|
+
const Popover = PopoverPrimitive.Root;
|
|
7
|
+
const PopoverTrigger = PopoverPrimitive.Trigger;
|
|
8
|
+
const PopoverAnchor = PopoverPrimitive.Anchor;
|
|
9
|
+
const PopoverClose = PopoverPrimitive.Close;
|
|
10
|
+
|
|
11
|
+
type PopoverContentProps = React.ComponentPropsWithoutRef<
|
|
12
|
+
typeof PopoverPrimitive.Content
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
const PopoverContent = React.forwardRef<
|
|
16
|
+
React.ElementRef<typeof PopoverPrimitive.Content>,
|
|
17
|
+
PopoverContentProps
|
|
18
|
+
>(({ className, align = "end", sideOffset = 8, ...props }, ref) => {
|
|
19
|
+
const { isLowPower } = usePerformance();
|
|
20
|
+
return (
|
|
21
|
+
<PopoverPrimitive.Portal>
|
|
22
|
+
<PopoverPrimitive.Content
|
|
23
|
+
ref={ref}
|
|
24
|
+
align={align}
|
|
25
|
+
sideOffset={sideOffset}
|
|
26
|
+
className={cn(
|
|
27
|
+
"z-50 rounded-md border border-border bg-popover text-popover-foreground shadow-md outline-none",
|
|
28
|
+
!isLowPower &&
|
|
29
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
|
30
|
+
className,
|
|
31
|
+
)}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
</PopoverPrimitive.Portal>
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
PopoverContent.displayName = "PopoverContent";
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
Popover,
|
|
41
|
+
PopoverTrigger,
|
|
42
|
+
PopoverAnchor,
|
|
43
|
+
PopoverClose,
|
|
44
|
+
PopoverContent,
|
|
45
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
1
|
+
import React, { useMemo, useState } from "react";
|
|
2
2
|
import { User, ChevronDown } from "lucide-react";
|
|
3
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./Popover";
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./
|
|
5
|
+
Sheet,
|
|
6
|
+
SheetContent,
|
|
7
|
+
SheetHeader,
|
|
8
|
+
SheetTitle,
|
|
9
|
+
SheetTrigger,
|
|
10
|
+
} from "./Sheet";
|
|
11
|
+
import { MenuCloseContext, DropdownMenuLabel, DropdownMenuSeparator } from "./Menu";
|
|
12
|
+
import { useIsMobile } from "../hooks/useIsMobile";
|
|
10
13
|
import { cn } from "../utils";
|
|
11
14
|
|
|
12
15
|
interface UserMenuProps {
|
|
@@ -25,60 +28,97 @@ export const UserMenu: React.FC<UserMenuProps> = ({
|
|
|
25
28
|
className,
|
|
26
29
|
}) => {
|
|
27
30
|
const [isOpen, setIsOpen] = useState(false);
|
|
31
|
+
const isMobile = useIsMobile();
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</div>
|
|
50
|
-
<span className="text-sm font-medium text-foreground hidden sm:inline-block max-w-[120px] truncate">
|
|
51
|
-
{user.name || user.email}
|
|
52
|
-
</span>
|
|
53
|
-
<ChevronDown
|
|
54
|
-
size={14}
|
|
55
|
-
className={cn(
|
|
56
|
-
"text-muted-foreground transition-transform",
|
|
57
|
-
isOpen && "rotate-180"
|
|
58
|
-
)}
|
|
33
|
+
const closeContextValue = useMemo(
|
|
34
|
+
() => ({ onClose: () => setIsOpen(false) }),
|
|
35
|
+
[],
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const trigger = (
|
|
39
|
+
<button
|
|
40
|
+
className={cn(
|
|
41
|
+
"flex items-center gap-2 px-3 py-1.5 rounded-full hover:bg-accent transition-all border border-transparent hover:border-border",
|
|
42
|
+
isOpen && "bg-accent border-border",
|
|
43
|
+
className,
|
|
44
|
+
)}
|
|
45
|
+
type="button"
|
|
46
|
+
>
|
|
47
|
+
<div className="w-6 h-6 rounded-full bg-primary/10 flex items-center justify-center text-primary">
|
|
48
|
+
{user.image ? (
|
|
49
|
+
<img
|
|
50
|
+
src={user.image}
|
|
51
|
+
alt={user.name || "User"}
|
|
52
|
+
className="w-full h-full rounded-full object-cover"
|
|
59
53
|
/>
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
) : (
|
|
55
|
+
<User size={14} />
|
|
56
|
+
)}
|
|
57
|
+
</div>
|
|
58
|
+
<span className="text-sm font-medium text-foreground hidden sm:inline-block max-w-[120px] truncate">
|
|
59
|
+
{user.name || user.email}
|
|
60
|
+
</span>
|
|
61
|
+
<ChevronDown
|
|
62
|
+
size={14}
|
|
63
|
+
className={cn(
|
|
64
|
+
"text-muted-foreground transition-transform",
|
|
65
|
+
isOpen && "rotate-180",
|
|
66
|
+
)}
|
|
67
|
+
/>
|
|
68
|
+
</button>
|
|
69
|
+
);
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
className="
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
const userInfo = (
|
|
72
|
+
<DropdownMenuLabel>
|
|
73
|
+
<div className="flex flex-col">
|
|
74
|
+
<span className="text-sm font-bold text-foreground truncate">
|
|
75
|
+
{user.name || "User"}
|
|
76
|
+
</span>
|
|
77
|
+
<span className="text-xs font-normal text-muted-foreground truncate">
|
|
78
|
+
{user.email}
|
|
79
|
+
</span>
|
|
80
|
+
</div>
|
|
81
|
+
</DropdownMenuLabel>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (isMobile) {
|
|
85
|
+
return (
|
|
86
|
+
<MenuCloseContext.Provider value={closeContextValue}>
|
|
87
|
+
<Sheet open={isOpen} onOpenChange={setIsOpen}>
|
|
88
|
+
<SheetTrigger asChild>{trigger}</SheetTrigger>
|
|
89
|
+
<SheetContent
|
|
90
|
+
size="full"
|
|
91
|
+
className="flex flex-col p-0"
|
|
92
|
+
onCloseAutoFocus={(e) => e.preventDefault()}
|
|
93
|
+
>
|
|
94
|
+
<SheetHeader className="px-4 py-3 border-b border-border">
|
|
95
|
+
<SheetTitle className="text-base">Menu</SheetTitle>
|
|
96
|
+
</SheetHeader>
|
|
97
|
+
<div className="flex-1 overflow-y-auto p-2 grid grid-cols-1 gap-2">
|
|
98
|
+
{userInfo}
|
|
99
|
+
<DropdownMenuSeparator />
|
|
100
|
+
{children}
|
|
101
|
+
</div>
|
|
102
|
+
</SheetContent>
|
|
103
|
+
</Sheet>
|
|
104
|
+
</MenuCloseContext.Provider>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<MenuCloseContext.Provider value={closeContextValue}>
|
|
110
|
+
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
111
|
+
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
|
|
112
|
+
<PopoverContent
|
|
113
|
+
align="end"
|
|
114
|
+
className="w-[400px] md:w-[460px] p-2 grid grid-cols-1 sm:grid-cols-2 gap-1"
|
|
115
|
+
onCloseAutoFocus={(e) => e.preventDefault()}
|
|
116
|
+
>
|
|
117
|
+
{userInfo}
|
|
118
|
+
<DropdownMenuSeparator />
|
|
119
|
+
{children}
|
|
120
|
+
</PopoverContent>
|
|
121
|
+
</Popover>
|
|
122
|
+
</MenuCloseContext.Provider>
|
|
83
123
|
);
|
|
84
124
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const MOBILE_BREAKPOINT_QUERY = "(max-width: 640px)";
|
|
4
|
+
|
|
5
|
+
export function useIsMobile() {
|
|
6
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const mql = globalThis.matchMedia(MOBILE_BREAKPOINT_QUERY);
|
|
10
|
+
setIsMobile(mql.matches);
|
|
11
|
+
const handler = (e: MediaQueryListEvent) => {
|
|
12
|
+
setIsMobile(e.matches);
|
|
13
|
+
};
|
|
14
|
+
mql.addEventListener("change", handler);
|
|
15
|
+
return () => {
|
|
16
|
+
mql.removeEventListener("change", handler);
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return isMobile;
|
|
21
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ export * from "./components/SectionHeader";
|
|
|
10
10
|
export * from "./components/StatusCard";
|
|
11
11
|
export * from "./components/EmptyState";
|
|
12
12
|
export * from "./components/LoadingSpinner";
|
|
13
|
-
export * from "./components/
|
|
13
|
+
export * from "./components/Menu";
|
|
14
14
|
export * from "./components/UserMenu";
|
|
15
15
|
export * from "./components/EditableText";
|
|
16
16
|
export * from "./components/ConfirmationModal";
|
|
@@ -59,3 +59,5 @@ export * from "./hooks/useAnimatedNumber";
|
|
|
59
59
|
export * from "./components/IDELayout";
|
|
60
60
|
export * from "./components/MetricTile";
|
|
61
61
|
export * from "./components/Sheet";
|
|
62
|
+
export * from "./components/Popover";
|
|
63
|
+
export * from "./hooks/useIsMobile";
|
package/tsconfig.json
CHANGED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useEffect, createContext, useContext, useState } from "react";
|
|
2
|
-
import { createPortal } from "react-dom";
|
|
3
|
-
import { X } from "lucide-react";
|
|
4
|
-
import { cn } from "../utils";
|
|
5
|
-
import { usePerformance } from "./PerformanceProvider";
|
|
6
|
-
|
|
7
|
-
export const DropdownMenuContext = createContext<{ onClose?: () => void }>({});
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Custom hook to detect mobile viewport.
|
|
11
|
-
*/
|
|
12
|
-
export function useIsMobile() {
|
|
13
|
-
const [isMobile, setIsMobile] = useState(false);
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
// Initial check
|
|
17
|
-
const mql = globalThis.matchMedia("(max-width: 640px)");
|
|
18
|
-
setIsMobile(mql.matches);
|
|
19
|
-
|
|
20
|
-
// Listener for changes
|
|
21
|
-
const handler = (e: MediaQueryListEvent) => setIsMobile(e.matches);
|
|
22
|
-
mql.addEventListener("change", handler);
|
|
23
|
-
return () => mql.removeEventListener("change", handler);
|
|
24
|
-
}, []);
|
|
25
|
-
|
|
26
|
-
return isMobile;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const DropdownMenuRootContext = createContext<{ rootRef?: React.RefObject<HTMLDivElement> }>({});
|
|
31
|
-
|
|
32
|
-
export const DropdownMenu: React.FC<{ children: React.ReactNode }> = ({
|
|
33
|
-
children,
|
|
34
|
-
}) => {
|
|
35
|
-
const rootRef = useRef<HTMLDivElement>(null);
|
|
36
|
-
return (
|
|
37
|
-
<DropdownMenuRootContext.Provider value={{ rootRef }}>
|
|
38
|
-
<div ref={rootRef} className="relative inline-block text-left">{children}</div>
|
|
39
|
-
</DropdownMenuRootContext.Provider>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const DropdownMenuTrigger: React.FC<{
|
|
44
|
-
children: React.ReactNode;
|
|
45
|
-
asChild?: boolean;
|
|
46
|
-
onClick?: () => void;
|
|
47
|
-
}> = ({ children, onClick }) => {
|
|
48
|
-
return (
|
|
49
|
-
<div onClick={onClick} className="cursor-pointer">
|
|
50
|
-
{children}
|
|
51
|
-
</div>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const DropdownMenuContent: React.FC<{
|
|
56
|
-
children: React.ReactNode;
|
|
57
|
-
isOpen: boolean;
|
|
58
|
-
onClose: () => void;
|
|
59
|
-
className?: string;
|
|
60
|
-
innerClassName?: string;
|
|
61
|
-
}> = ({ children, isOpen, onClose, className, innerClassName }) => {
|
|
62
|
-
const { isLowPower } = usePerformance();
|
|
63
|
-
const contentRef = useRef<HTMLDivElement>(null);
|
|
64
|
-
const { rootRef } = useContext(DropdownMenuRootContext);
|
|
65
|
-
const isMobile = useIsMobile();
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
69
|
-
// Don't auto-close if clicking outside on mobile (full screen modal style)
|
|
70
|
-
if (isMobile) return;
|
|
71
|
-
|
|
72
|
-
const target = event.target as Node;
|
|
73
|
-
|
|
74
|
-
// Don't close if clicking inside the menu content
|
|
75
|
-
if (contentRef.current && contentRef.current.contains(target)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Don't close if clicking inside the wrapper (e.g. the trigger button)
|
|
80
|
-
// This allows the trigger's onClick to handle toggling the menu without conflict.
|
|
81
|
-
if (rootRef?.current && rootRef.current.contains(target)) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
onClose();
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (isOpen) {
|
|
89
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
90
|
-
// Lock body scroll on mobile
|
|
91
|
-
if (isMobile) {
|
|
92
|
-
document.body.style.overflow = "hidden";
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return () => {
|
|
96
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
97
|
-
if (isMobile) {
|
|
98
|
-
document.body.style.overflow = "";
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}, [isOpen, onClose, isMobile, rootRef]);
|
|
102
|
-
|
|
103
|
-
if (!isOpen) return <React.Fragment />;
|
|
104
|
-
|
|
105
|
-
const content = (
|
|
106
|
-
<div
|
|
107
|
-
ref={contentRef}
|
|
108
|
-
className={cn(
|
|
109
|
-
isMobile
|
|
110
|
-
? "fixed inset-0 z-[100] bg-background w-full h-full p-4 overflow-y-auto"
|
|
111
|
-
: "absolute right-0 mt-2 w-56 origin-top-right rounded-md bg-popover shadow-lg ring-1 ring-border focus:outline-none z-[100] max-h-[calc(100vh-4rem)] overflow-y-auto",
|
|
112
|
-
!isLowPower && "animate-in fade-in zoom-in-95 duration-100",
|
|
113
|
-
className
|
|
114
|
-
)}
|
|
115
|
-
>
|
|
116
|
-
<DropdownMenuContext.Provider value={{ onClose }}>
|
|
117
|
-
<div className={cn(isMobile ? "flex flex-col pt-4 pb-12" : "py-1", innerClassName)} role="none">
|
|
118
|
-
{isMobile && (
|
|
119
|
-
<div className="flex justify-between items-center mb-6 col-span-full px-2">
|
|
120
|
-
<h2 className="text-xl font-bold text-foreground">Menu</h2>
|
|
121
|
-
<button
|
|
122
|
-
onClick={onClose}
|
|
123
|
-
className="p-2 rounded-full hover:bg-accent text-muted-foreground transition-colors"
|
|
124
|
-
aria-label="Close menu"
|
|
125
|
-
>
|
|
126
|
-
<X className="w-6 h-6" />
|
|
127
|
-
</button>
|
|
128
|
-
</div>
|
|
129
|
-
)}
|
|
130
|
-
{children}
|
|
131
|
-
</div>
|
|
132
|
-
</DropdownMenuContext.Provider>
|
|
133
|
-
</div>
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
return isMobile ? createPortal(content, document.body) : content;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export const DropdownMenuItem: React.FC<{
|
|
140
|
-
children: React.ReactNode;
|
|
141
|
-
onClick?: () => void;
|
|
142
|
-
className?: string;
|
|
143
|
-
icon?: React.ReactNode;
|
|
144
|
-
description?: React.ReactNode;
|
|
145
|
-
closeOnClick?: boolean;
|
|
146
|
-
}> = ({ children, onClick, className, icon, description, closeOnClick = true }) => {
|
|
147
|
-
const { onClose } = useContext(DropdownMenuContext);
|
|
148
|
-
|
|
149
|
-
const handleClick = () => {
|
|
150
|
-
if (onClick) onClick();
|
|
151
|
-
if (closeOnClick && onClose) onClose();
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
<button
|
|
156
|
-
onClick={handleClick}
|
|
157
|
-
className={cn(
|
|
158
|
-
"flex flex-col items-start w-full px-4 py-2 text-sm text-popover-foreground hover:bg-accent hover:text-accent-foreground transition-colors rounded-sm overflow-hidden",
|
|
159
|
-
className
|
|
160
|
-
)}
|
|
161
|
-
role="menuitem"
|
|
162
|
-
>
|
|
163
|
-
<div className="flex items-center w-full overflow-hidden">
|
|
164
|
-
{icon && <span className="mr-3 text-muted-foreground shrink-0">{icon}</span>}
|
|
165
|
-
<span className="flex-1 text-left truncate">{children}</span>
|
|
166
|
-
</div>
|
|
167
|
-
{description && (
|
|
168
|
-
<span className={cn("text-[10px] text-muted-foreground mt-1 leading-tight text-left truncate w-full", icon ? "pl-7" : "")}>
|
|
169
|
-
{description}
|
|
170
|
-
</span>
|
|
171
|
-
)}
|
|
172
|
-
</button>
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export const DropdownMenuSeparator: React.FC<{ className?: string }> = ({ className }) => (
|
|
177
|
-
<div className={cn("my-1 h-px bg-border col-span-full", className)} />
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
export const DropdownMenuLabel: React.FC<{ children: React.ReactNode; className?: string }> = ({
|
|
181
|
-
children,
|
|
182
|
-
className
|
|
183
|
-
}) => (
|
|
184
|
-
<div className={cn("px-4 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider col-span-full", className)}>
|
|
185
|
-
{children}
|
|
186
|
-
</div>
|
|
187
|
-
);
|