@open-lakehouse/ui-kit 0.0.0-stage → 0.0.2
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 +14 -0
- package/DESIGN.md +105 -0
- package/README.md +48 -2
- package/dist/ThemeProvider.d.ts +11 -0
- package/dist/ThemeProvider.d.ts.map +1 -0
- package/dist/ThemeProvider.js +40 -0
- package/dist/ThemeProvider.js.map +1 -0
- package/dist/badge.d.ts +10 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +22 -0
- package/dist/badge.js.map +1 -0
- package/dist/button.d.ts +12 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +34 -0
- package/dist/button.js.map +1 -0
- package/dist/card.d.ts +9 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +20 -0
- package/dist/card.js.map +1 -0
- package/dist/commit-history.d.ts +76 -0
- package/dist/commit-history.d.ts.map +1 -0
- package/dist/commit-history.js +121 -0
- package/dist/commit-history.js.map +1 -0
- package/dist/dialog.d.ts +22 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +27 -0
- package/dist/dialog.js.map +1 -0
- package/dist/dropdown-menu.d.ts +16 -0
- package/dist/dropdown-menu.d.ts.map +1 -0
- package/dist/dropdown-menu.js +23 -0
- package/dist/dropdown-menu.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +4 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +11 -0
- package/dist/input.js.map +1 -0
- package/dist/label.d.ts +5 -0
- package/dist/label.d.ts.map +1 -0
- package/dist/label.js +8 -0
- package/dist/label.js.map +1 -0
- package/dist/resizable.d.ts +29 -0
- package/dist/resizable.d.ts.map +1 -0
- package/dist/resizable.js +54 -0
- package/dist/resizable.js.map +1 -0
- package/dist/select.d.ts +10 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +23 -0
- package/dist/select.js.map +1 -0
- package/dist/separator.d.ts +6 -0
- package/dist/separator.d.ts.map +1 -0
- package/dist/separator.js +7 -0
- package/dist/separator.js.map +1 -0
- package/dist/sheet.d.ts +23 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +37 -0
- package/dist/sheet.js.map +1 -0
- package/dist/sonner.d.ts +3 -0
- package/dist/sonner.d.ts.map +1 -0
- package/dist/sonner.js +15 -0
- package/dist/sonner.js.map +1 -0
- package/dist/switch.d.ts +8 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +9 -0
- package/dist/switch.js.map +1 -0
- package/dist/tabs.d.ts +8 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +13 -0
- package/dist/tabs.js.map +1 -0
- package/dist/textarea.d.ts +4 -0
- package/dist/textarea.d.ts.map +1 -0
- package/dist/textarea.js +11 -0
- package/dist/textarea.js.map +1 -0
- package/dist/tooltip.d.ts +8 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +11 -0
- package/dist/tooltip.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -0
- package/package.json +54 -4
- package/src/ThemeProvider.tsx +57 -0
- package/src/badge.tsx +34 -0
- package/src/button.tsx +56 -0
- package/src/card.tsx +87 -0
- package/src/commit-history.tsx +339 -0
- package/src/dialog.tsx +119 -0
- package/src/dropdown-menu.tsx +99 -0
- package/src/index.ts +87 -0
- package/src/input.tsx +27 -0
- package/src/label.tsx +21 -0
- package/src/resizable.tsx +95 -0
- package/src/select.tsx +127 -0
- package/src/separator.tsx +25 -0
- package/src/sheet.tsx +131 -0
- package/src/sonner.tsx +26 -0
- package/src/switch.tsx +47 -0
- package/src/tabs.tsx +53 -0
- package/src/textarea.tsx +25 -0
- package/src/tooltip.tsx +28 -0
- package/src/utils.ts +6 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tooltip as TooltipPrimitive } from "radix-ui";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
declare const TooltipProvider: React.FC<TooltipPrimitive.TooltipProviderProps>;
|
|
4
|
+
declare const Tooltip: React.FC<TooltipPrimitive.TooltipProps>;
|
|
5
|
+
declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipPrimitive.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
declare const TooltipContent: React.ForwardRefExoticComponent<Omit<TooltipPrimitive.TooltipContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
8
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../src/tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,QAAA,MAAM,eAAe,iDAA4B,CAAC;AAClD,QAAA,MAAM,OAAO,yCAAwB,CAAC;AACtC,QAAA,MAAM,cAAc,gHAA2B,CAAC;AAEhD,QAAA,MAAM,cAAc,gKAelB,CAAC;AAGH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/tooltip.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip as TooltipPrimitive } from "radix-ui";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "./utils.js";
|
|
5
|
+
const TooltipProvider = TooltipPrimitive.Provider;
|
|
6
|
+
const Tooltip = TooltipPrimitive.Root;
|
|
7
|
+
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
8
|
+
const TooltipContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn("z-50 overflow-hidden rounded-md border bg-popover px-2 py-1 text-xs text-popover-foreground shadow-md data-[state=delayed-open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=delayed-open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=delayed-open]:zoom-in-95", className), ...props }) })));
|
|
9
|
+
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
|
10
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
11
|
+
//# sourceMappingURL=tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../src/tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAEhC,MAAM,eAAe,GAAG,gBAAgB,CAAC,QAAQ,CAAC;AAClD,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC;AACtC,MAAM,cAAc,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAEhD,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAGrC,CAAC,EAAE,SAAS,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAClD,KAAC,gBAAgB,CAAC,MAAM,cACtB,KAAC,gBAAgB,CAAC,OAAO,IACvB,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,EAAE,CACX,oTAAoT,EACpT,SAAS,CACV,KACG,KAAK,GACT,GACsB,CAC3B,CAAC,CAAC;AACH,cAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,MAAM,CAAC;AAG7C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,UAAU,EAAE,CAAC,GAAG,MAAoB;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-lakehouse/ui-kit",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Headless, theme-agnostic React primitives (Radix + CVA + Tailwind) and the shared Open Lakehouse design-token contract",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/open-lakehouse/trestle.git",
|
|
10
|
+
"directory": "node/ui-kit"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"src",
|
|
15
|
+
"!src/**/*.test.ts",
|
|
16
|
+
"!src/**/*.test.tsx",
|
|
17
|
+
"!src/**/*.stories.tsx",
|
|
18
|
+
"README.md",
|
|
19
|
+
"DESIGN.md",
|
|
20
|
+
"CHANGELOG.md"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"source": "./src/index.ts",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "bun ../scripts/build-package.ts",
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"class-variance-authority": "^0.7.1",
|
|
37
|
+
"clsx": "^2.1.1",
|
|
38
|
+
"lucide-react": "^1.55.0",
|
|
39
|
+
"radix-ui": "^1.7.0",
|
|
40
|
+
"sonner": "^2.0.8",
|
|
41
|
+
"tailwind-merge": "^3.6.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"react-dom": "^19.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@storybook/react-vite": "^10.6.0",
|
|
49
|
+
"@types/react": "^19.0.0",
|
|
50
|
+
"@types/react-dom": "^19.0.0",
|
|
51
|
+
"react": "^19.0.0",
|
|
52
|
+
"react-dom": "^19.0.0",
|
|
53
|
+
"storybook": "^10.6.0",
|
|
54
|
+
"typescript": "^5.7.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
type Theme = "dark" | "light" | "system";
|
|
4
|
+
|
|
5
|
+
interface ThemeContextValue {
|
|
6
|
+
theme: Theme;
|
|
7
|
+
setTheme: (theme: Theme) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ThemeContext = createContext<ThemeContextValue>({
|
|
11
|
+
theme: "system",
|
|
12
|
+
setTheme: () => {},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
16
|
+
const [theme, setThemeState] = useState<Theme>("system");
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const stored = localStorage.getItem("theme") as Theme | null;
|
|
20
|
+
if (stored) setThemeState(stored);
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const root = document.documentElement;
|
|
25
|
+
|
|
26
|
+
if (theme === "dark") {
|
|
27
|
+
root.classList.add("dark");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (theme === "light") {
|
|
31
|
+
root.classList.remove("dark");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// "system": follow the OS preference and keep following it live.
|
|
36
|
+
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
37
|
+
const apply = () => root.classList.toggle("dark", media.matches);
|
|
38
|
+
apply();
|
|
39
|
+
media.addEventListener("change", apply);
|
|
40
|
+
return () => media.removeEventListener("change", apply);
|
|
41
|
+
}, [theme]);
|
|
42
|
+
|
|
43
|
+
function setTheme(t: Theme) {
|
|
44
|
+
setThemeState(t);
|
|
45
|
+
localStorage.setItem("theme", t);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<ThemeContext.Provider value={{ theme, setTheme }}>
|
|
50
|
+
{children}
|
|
51
|
+
</ThemeContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function useTheme() {
|
|
56
|
+
return useContext(ThemeContext);
|
|
57
|
+
}
|
package/src/badge.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import type * as React from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
const badgeVariants = cva(
|
|
7
|
+
"inline-flex items-center rounded border px-1.5 py-0.5 text-xs font-medium uppercase tracking-wide transition-colors",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "border-transparent bg-muted text-muted-foreground",
|
|
12
|
+
primary: "border-transparent bg-primary/15 text-primary",
|
|
13
|
+
success: "border-transparent bg-success/15 text-success",
|
|
14
|
+
outline: "border-border text-muted-foreground",
|
|
15
|
+
destructive: "border-transparent bg-destructive/15 text-destructive",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: {
|
|
19
|
+
variant: "default",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export interface BadgeProps
|
|
25
|
+
extends React.HTMLAttributes<HTMLSpanElement>,
|
|
26
|
+
VariantProps<typeof badgeVariants> {}
|
|
27
|
+
|
|
28
|
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
29
|
+
return (
|
|
30
|
+
<span className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { Badge, badgeVariants };
|
package/src/button.tsx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { Slot as SlotPrimitive } from "radix-ui";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
13
|
+
destructive:
|
|
14
|
+
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
15
|
+
outline:
|
|
16
|
+
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
17
|
+
secondary:
|
|
18
|
+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
20
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
21
|
+
},
|
|
22
|
+
size: {
|
|
23
|
+
default: "h-10 px-4 py-2",
|
|
24
|
+
sm: "h-9 rounded-md px-3",
|
|
25
|
+
lg: "h-11 rounded-md px-8",
|
|
26
|
+
icon: "h-10 w-10",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
variant: "default",
|
|
31
|
+
size: "default",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export interface ButtonProps
|
|
37
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
38
|
+
VariantProps<typeof buttonVariants> {
|
|
39
|
+
asChild?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
43
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
44
|
+
const Comp = asChild ? SlotPrimitive.Slot : "button";
|
|
45
|
+
return (
|
|
46
|
+
<Comp
|
|
47
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
48
|
+
ref={ref}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
Button.displayName = "Button";
|
|
55
|
+
|
|
56
|
+
export { Button, buttonVariants };
|
package/src/card.tsx
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
// A raised surface for grouping content (the module/capability picker tiles, panels).
|
|
6
|
+
// Headless with respect to theme: it emits `bg-card`/`text-card-foreground`/`border`
|
|
7
|
+
// semantic utilities and owns no color values, per the ui-kit DESIGN.md contract.
|
|
8
|
+
|
|
9
|
+
const Card = React.forwardRef<
|
|
10
|
+
HTMLDivElement,
|
|
11
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
12
|
+
>(({ className, ...props }, ref) => (
|
|
13
|
+
<div
|
|
14
|
+
ref={ref}
|
|
15
|
+
className={cn(
|
|
16
|
+
"rounded-lg border bg-card text-card-foreground shadow-sm",
|
|
17
|
+
className,
|
|
18
|
+
)}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
));
|
|
22
|
+
Card.displayName = "Card";
|
|
23
|
+
|
|
24
|
+
const CardHeader = React.forwardRef<
|
|
25
|
+
HTMLDivElement,
|
|
26
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
27
|
+
>(({ className, ...props }, ref) => (
|
|
28
|
+
<div
|
|
29
|
+
ref={ref}
|
|
30
|
+
className={cn("flex flex-col gap-1 p-4", className)}
|
|
31
|
+
{...props}
|
|
32
|
+
/>
|
|
33
|
+
));
|
|
34
|
+
CardHeader.displayName = "CardHeader";
|
|
35
|
+
|
|
36
|
+
const CardTitle = React.forwardRef<
|
|
37
|
+
HTMLDivElement,
|
|
38
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
39
|
+
>(({ className, ...props }, ref) => (
|
|
40
|
+
<div
|
|
41
|
+
ref={ref}
|
|
42
|
+
className={cn("text-sm font-semibold leading-none", className)}
|
|
43
|
+
{...props}
|
|
44
|
+
/>
|
|
45
|
+
));
|
|
46
|
+
CardTitle.displayName = "CardTitle";
|
|
47
|
+
|
|
48
|
+
const CardDescription = React.forwardRef<
|
|
49
|
+
HTMLDivElement,
|
|
50
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
51
|
+
>(({ className, ...props }, ref) => (
|
|
52
|
+
<div
|
|
53
|
+
ref={ref}
|
|
54
|
+
className={cn("text-xs text-muted-foreground", className)}
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
));
|
|
58
|
+
CardDescription.displayName = "CardDescription";
|
|
59
|
+
|
|
60
|
+
const CardContent = React.forwardRef<
|
|
61
|
+
HTMLDivElement,
|
|
62
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
63
|
+
>(({ className, ...props }, ref) => (
|
|
64
|
+
<div ref={ref} className={cn("p-4 pt-0", className)} {...props} />
|
|
65
|
+
));
|
|
66
|
+
CardContent.displayName = "CardContent";
|
|
67
|
+
|
|
68
|
+
const CardFooter = React.forwardRef<
|
|
69
|
+
HTMLDivElement,
|
|
70
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
71
|
+
>(({ className, ...props }, ref) => (
|
|
72
|
+
<div
|
|
73
|
+
ref={ref}
|
|
74
|
+
className={cn("flex items-center p-4 pt-0", className)}
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
));
|
|
78
|
+
CardFooter.displayName = "CardFooter";
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
Card,
|
|
82
|
+
CardContent,
|
|
83
|
+
CardDescription,
|
|
84
|
+
CardFooter,
|
|
85
|
+
CardHeader,
|
|
86
|
+
CardTitle,
|
|
87
|
+
};
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { Check, Copy, GitCommitHorizontal } from "lucide-react";
|
|
2
|
+
import { type ReactNode, useState } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
/** Who made a commit. */
|
|
7
|
+
export interface CommitAuthor {
|
|
8
|
+
name: string;
|
|
9
|
+
/** Drawn in place of the initials, where the host has one. */
|
|
10
|
+
avatarUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** One commit (or revision, version…) in a `CommitHistory`. */
|
|
14
|
+
export interface CommitHistoryEntry {
|
|
15
|
+
/** Stable identity: the React key and what `selectedId` matches. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** The first line of the message, or a fallback such as "Revision #3". */
|
|
18
|
+
title: ReactNode;
|
|
19
|
+
/** The rest of the message, clamped to two lines. */
|
|
20
|
+
description?: ReactNode;
|
|
21
|
+
/** A short hash or digest, drawn in mono with a copy button. */
|
|
22
|
+
ref?: string;
|
|
23
|
+
/** The full hash, for the ref's tooltip and what the copy button copies. */
|
|
24
|
+
refTitle?: string;
|
|
25
|
+
author?: CommitAuthor;
|
|
26
|
+
/** When it was made (a `Date` or an ISO 8601 string). Entries without one
|
|
27
|
+
* are grouped under "Undated". */
|
|
28
|
+
timestamp?: string | Date;
|
|
29
|
+
/** Small tags next to the ref, e.g. a number or "HEAD". */
|
|
30
|
+
badges?: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The entries made on one calendar day, or the undated ones. */
|
|
34
|
+
export interface CommitDayGroup {
|
|
35
|
+
/** `YYYY-MM-DD` in local time, or `"undated"`. */
|
|
36
|
+
key: string;
|
|
37
|
+
/** Midnight of that day; absent for the undated group. */
|
|
38
|
+
day?: Date;
|
|
39
|
+
entries: CommitHistoryEntry[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toDate(value: string | Date | undefined): Date | undefined {
|
|
43
|
+
if (value === undefined) return undefined;
|
|
44
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
45
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Group `entries` by local calendar day, keeping their order: groups appear in
|
|
52
|
+
* the order of their first entry (newest first when the entries are), and
|
|
53
|
+
* entries without a (valid) timestamp come last, under `"undated"`.
|
|
54
|
+
*/
|
|
55
|
+
export function groupByDay(
|
|
56
|
+
entries: readonly CommitHistoryEntry[],
|
|
57
|
+
): CommitDayGroup[] {
|
|
58
|
+
const groups = new Map<string, CommitDayGroup>();
|
|
59
|
+
const undated: CommitHistoryEntry[] = [];
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
const date = toDate(entry.timestamp);
|
|
62
|
+
if (!date) {
|
|
63
|
+
undated.push(entry);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const key = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
67
|
+
let group = groups.get(key);
|
|
68
|
+
if (!group) {
|
|
69
|
+
group = {
|
|
70
|
+
key,
|
|
71
|
+
day: new Date(date.getFullYear(), date.getMonth(), date.getDate()),
|
|
72
|
+
entries: [],
|
|
73
|
+
};
|
|
74
|
+
groups.set(key, group);
|
|
75
|
+
}
|
|
76
|
+
group.entries.push(entry);
|
|
77
|
+
}
|
|
78
|
+
const out = [...groups.values()];
|
|
79
|
+
if (undated.length > 0) out.push({ key: "undated", entries: undated });
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const UNITS: [Intl.RelativeTimeFormatUnit, number][] = [
|
|
84
|
+
["minute", 60],
|
|
85
|
+
["hour", 60 * 60],
|
|
86
|
+
["day", 24 * 60 * 60],
|
|
87
|
+
["week", 7 * 24 * 60 * 60],
|
|
88
|
+
["month", 30 * 24 * 60 * 60],
|
|
89
|
+
["year", 365 * 24 * 60 * 60],
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* How long ago `date` was, relative to `now`: "just now" under a minute, then
|
|
94
|
+
* the largest whole unit ("5 minutes ago", "yesterday", "3 weeks ago").
|
|
95
|
+
* A `date` after `now` reads "just now" too (clock skew between hosts).
|
|
96
|
+
*/
|
|
97
|
+
export function formatRelativeTime(
|
|
98
|
+
date: Date,
|
|
99
|
+
now: Date = new Date(),
|
|
100
|
+
locale?: string,
|
|
101
|
+
): string {
|
|
102
|
+
const seconds = Math.round((now.getTime() - date.getTime()) / 1000);
|
|
103
|
+
if (seconds < 60) return "just now";
|
|
104
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
105
|
+
let unit = UNITS[0];
|
|
106
|
+
for (const candidate of UNITS) {
|
|
107
|
+
if (seconds >= candidate[1]) unit = candidate;
|
|
108
|
+
}
|
|
109
|
+
return rtf.format(-Math.floor(seconds / unit[1]), unit[0]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function defaultDayLabel(day: Date): string {
|
|
113
|
+
return day.toLocaleDateString(undefined, {
|
|
114
|
+
month: "short",
|
|
115
|
+
day: "numeric",
|
|
116
|
+
year: "numeric",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface CommitHistoryProps {
|
|
121
|
+
/** Newest first. */
|
|
122
|
+
entries: readonly CommitHistoryEntry[];
|
|
123
|
+
/** Makes each entry's title a button. */
|
|
124
|
+
onSelect?: (entry: CommitHistoryEntry) => void;
|
|
125
|
+
/** The highlighted entry. */
|
|
126
|
+
selectedId?: string;
|
|
127
|
+
/** Per-entry actions (e.g. compare), shown on hover and focus. */
|
|
128
|
+
renderActions?: (entry: CommitHistoryEntry) => ReactNode;
|
|
129
|
+
/** Group the entries under a heading per day. Defaults to true. */
|
|
130
|
+
groupByDay?: boolean;
|
|
131
|
+
/** Narrow layout for sidebars: the ref and badges move under the title. */
|
|
132
|
+
compact?: boolean;
|
|
133
|
+
/** A day's heading. Defaults to the date, e.g. "Nov 21, 2026". */
|
|
134
|
+
dayLabel?: (day: Date) => ReactNode;
|
|
135
|
+
/** Drawn when there are no entries. */
|
|
136
|
+
emptyState?: ReactNode;
|
|
137
|
+
/** The reference time for relative timestamps. Defaults to now. */
|
|
138
|
+
now?: Date;
|
|
139
|
+
"aria-label"?: string;
|
|
140
|
+
className?: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A commit history in the style of GitHub's commits page: the entries grouped
|
|
145
|
+
* by day along a timeline, each with its title, author, relative time, badges
|
|
146
|
+
* and a copyable ref. Generic over what is being versioned: the host maps its
|
|
147
|
+
* own records (revisions, commits, table versions) to `CommitHistoryEntry`.
|
|
148
|
+
*/
|
|
149
|
+
export function CommitHistory({
|
|
150
|
+
entries,
|
|
151
|
+
onSelect,
|
|
152
|
+
selectedId,
|
|
153
|
+
renderActions,
|
|
154
|
+
groupByDay: grouped = true,
|
|
155
|
+
compact = false,
|
|
156
|
+
dayLabel = defaultDayLabel,
|
|
157
|
+
emptyState,
|
|
158
|
+
now,
|
|
159
|
+
"aria-label": ariaLabel,
|
|
160
|
+
className,
|
|
161
|
+
}: CommitHistoryProps) {
|
|
162
|
+
if (entries.length === 0) {
|
|
163
|
+
return (
|
|
164
|
+
<div className={cn("text-xs text-muted-foreground", className)}>
|
|
165
|
+
{emptyState ?? "No commits yet."}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const groups = grouped
|
|
170
|
+
? groupByDay(entries)
|
|
171
|
+
: [{ key: "all", entries: [...entries] } as CommitDayGroup];
|
|
172
|
+
const row = (entry: CommitHistoryEntry) => (
|
|
173
|
+
<CommitRow
|
|
174
|
+
key={entry.id}
|
|
175
|
+
entry={entry}
|
|
176
|
+
selected={entry.id === selectedId}
|
|
177
|
+
onSelect={onSelect}
|
|
178
|
+
actions={renderActions?.(entry)}
|
|
179
|
+
compact={compact}
|
|
180
|
+
now={now}
|
|
181
|
+
/>
|
|
182
|
+
);
|
|
183
|
+
return (
|
|
184
|
+
<section aria-label={ariaLabel} className={cn("text-sm", className)}>
|
|
185
|
+
{groups.map((group) => (
|
|
186
|
+
<div key={group.key}>
|
|
187
|
+
{grouped && (
|
|
188
|
+
<h3 className="flex items-center gap-1.5 py-1 text-xs text-muted-foreground">
|
|
189
|
+
<GitCommitHorizontal
|
|
190
|
+
aria-hidden
|
|
191
|
+
className="h-3.5 w-3.5 shrink-0"
|
|
192
|
+
/>
|
|
193
|
+
{group.day ? dayLabel(group.day) : "Undated"}
|
|
194
|
+
</h3>
|
|
195
|
+
)}
|
|
196
|
+
<div className={cn(grouped && "ml-[7px] border-l pb-3 pl-3")}>
|
|
197
|
+
<ol className="divide-y overflow-hidden rounded-md border bg-card text-card-foreground">
|
|
198
|
+
{group.entries.map(row)}
|
|
199
|
+
</ol>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
))}
|
|
203
|
+
</section>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function CommitRow({
|
|
208
|
+
entry,
|
|
209
|
+
selected,
|
|
210
|
+
onSelect,
|
|
211
|
+
actions,
|
|
212
|
+
compact,
|
|
213
|
+
now,
|
|
214
|
+
}: {
|
|
215
|
+
entry: CommitHistoryEntry;
|
|
216
|
+
selected: boolean;
|
|
217
|
+
onSelect?: (entry: CommitHistoryEntry) => void;
|
|
218
|
+
actions: ReactNode;
|
|
219
|
+
compact: boolean;
|
|
220
|
+
now?: Date;
|
|
221
|
+
}) {
|
|
222
|
+
const date = toDate(entry.timestamp);
|
|
223
|
+
const titleClass = "block w-full truncate text-left font-medium";
|
|
224
|
+
const tags = (entry.badges || entry.ref) && (
|
|
225
|
+
<span className="flex shrink-0 items-center gap-1">
|
|
226
|
+
{entry.badges}
|
|
227
|
+
{entry.ref && <RefChip value={entry.ref} full={entry.refTitle} />}
|
|
228
|
+
</span>
|
|
229
|
+
);
|
|
230
|
+
return (
|
|
231
|
+
<li
|
|
232
|
+
className={cn(
|
|
233
|
+
"group flex items-start gap-2",
|
|
234
|
+
compact ? "px-2 py-1.5" : "px-3 py-2",
|
|
235
|
+
selected && "bg-accent text-accent-foreground",
|
|
236
|
+
)}
|
|
237
|
+
>
|
|
238
|
+
<div className="min-w-0 flex-1">
|
|
239
|
+
{onSelect ? (
|
|
240
|
+
<button
|
|
241
|
+
type="button"
|
|
242
|
+
className={cn(
|
|
243
|
+
titleClass,
|
|
244
|
+
"rounded-sm hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
245
|
+
)}
|
|
246
|
+
aria-current={selected || undefined}
|
|
247
|
+
onClick={() => onSelect(entry)}
|
|
248
|
+
>
|
|
249
|
+
{entry.title}
|
|
250
|
+
</button>
|
|
251
|
+
) : (
|
|
252
|
+
<span className={titleClass}>{entry.title}</span>
|
|
253
|
+
)}
|
|
254
|
+
{entry.description && (
|
|
255
|
+
<p className="mt-0.5 line-clamp-2 text-xs text-muted-foreground">
|
|
256
|
+
{entry.description}
|
|
257
|
+
</p>
|
|
258
|
+
)}
|
|
259
|
+
<div className="mt-0.5 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs text-muted-foreground">
|
|
260
|
+
{entry.author && (
|
|
261
|
+
<>
|
|
262
|
+
<Avatar author={entry.author} />
|
|
263
|
+
<span className="truncate font-medium text-foreground">
|
|
264
|
+
{entry.author.name}
|
|
265
|
+
</span>
|
|
266
|
+
</>
|
|
267
|
+
)}
|
|
268
|
+
{date && (
|
|
269
|
+
<time dateTime={date.toISOString()} title={date.toLocaleString()}>
|
|
270
|
+
{entry.author && !compact ? "committed " : ""}
|
|
271
|
+
{formatRelativeTime(date, now)}
|
|
272
|
+
</time>
|
|
273
|
+
)}
|
|
274
|
+
{compact && tags}
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
{!compact && tags}
|
|
278
|
+
{actions && (
|
|
279
|
+
<span className="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100">
|
|
280
|
+
{actions}
|
|
281
|
+
</span>
|
|
282
|
+
)}
|
|
283
|
+
</li>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function Avatar({ author }: { author: CommitAuthor }) {
|
|
288
|
+
if (author.avatarUrl) {
|
|
289
|
+
return (
|
|
290
|
+
<img
|
|
291
|
+
src={author.avatarUrl}
|
|
292
|
+
alt=""
|
|
293
|
+
className="h-4 w-4 shrink-0 rounded-full"
|
|
294
|
+
/>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
const initials = author.name
|
|
298
|
+
.split(/\s+/)
|
|
299
|
+
.filter(Boolean)
|
|
300
|
+
.slice(0, 2)
|
|
301
|
+
.map((part) => part[0]?.toUpperCase())
|
|
302
|
+
.join("");
|
|
303
|
+
return (
|
|
304
|
+
<span
|
|
305
|
+
aria-hidden
|
|
306
|
+
className="inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-muted text-[8px] font-semibold text-muted-foreground"
|
|
307
|
+
>
|
|
308
|
+
{initials}
|
|
309
|
+
</span>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** A short ref in mono, copying the full one on a click. */
|
|
314
|
+
function RefChip({ value, full }: { value: string; full?: string }) {
|
|
315
|
+
const [copied, setCopied] = useState(false);
|
|
316
|
+
const text = full ?? value;
|
|
317
|
+
const copy = () => {
|
|
318
|
+
void navigator.clipboard?.writeText(text).then(() => {
|
|
319
|
+
setCopied(true);
|
|
320
|
+
setTimeout(() => setCopied(false), 1500);
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
return (
|
|
324
|
+
<span
|
|
325
|
+
className="inline-flex items-center rounded border bg-background font-mono text-[11px] text-muted-foreground"
|
|
326
|
+
title={text}
|
|
327
|
+
>
|
|
328
|
+
<span className="px-1">{value}</span>
|
|
329
|
+
<button
|
|
330
|
+
type="button"
|
|
331
|
+
aria-label={`Copy ${text}`}
|
|
332
|
+
onClick={copy}
|
|
333
|
+
className="border-l px-0.5 py-0.5 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:h-3 [&_svg]:w-3"
|
|
334
|
+
>
|
|
335
|
+
{copied ? <Check /> : <Copy />}
|
|
336
|
+
</button>
|
|
337
|
+
</span>
|
|
338
|
+
);
|
|
339
|
+
}
|