@vvedantb/ui 0.0.0-stage → 0.1.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 +21 -0
- package/package.json +124 -4
- package/src/ai-elements/artifact.tsx +99 -0
- package/src/ai-elements/attachments.tsx +366 -0
- package/src/ai-elements/chain-of-thought.tsx +212 -0
- package/src/ai-elements/code-block.tsx +478 -0
- package/src/ai-elements/conversation.tsx +157 -0
- package/src/ai-elements/image.tsx +25 -0
- package/src/ai-elements/inline-citation.tsx +252 -0
- package/src/ai-elements/message.tsx +269 -0
- package/src/ai-elements/model-selector.tsx +211 -0
- package/src/ai-elements/prompt-input.tsx +1018 -0
- package/src/ai-elements/queue.tsx +251 -0
- package/src/ai-elements/reasoning.tsx +178 -0
- package/src/ai-elements/shimmer.tsx +56 -0
- package/src/ai-elements/sources.tsx +77 -0
- package/src/ai-elements/speech-input.tsx +290 -0
- package/src/ai-elements/suggestion.tsx +191 -0
- package/src/css.d.ts +2 -0
- package/src/index.ts +96 -0
- package/src/motion/presets.ts +35 -0
- package/src/motion/presets.vibot.ts +105 -0
- package/src/ui/_menu-classes.ts +30 -0
- package/src/ui/_menu-classes.vibot.ts +33 -0
- package/src/ui/accordion.tsx +81 -0
- package/src/ui/accordion.verve.tsx +56 -0
- package/src/ui/badge.tsx +34 -0
- package/src/ui/breadcrumb.tsx +83 -0
- package/src/ui/button-group.tsx +84 -0
- package/src/ui/button.tsx +57 -0
- package/src/ui/card.tsx +27 -0
- package/src/ui/carousel.tsx +211 -0
- package/src/ui/checkbox.tsx +27 -0
- package/src/ui/clear-input.tsx +170 -0
- package/src/ui/clear-input.vibot.tsx +76 -0
- package/src/ui/clearInputDissolve.ts +214 -0
- package/src/ui/collapsible.tsx +7 -0
- package/src/ui/command.tsx +148 -0
- package/src/ui/context-menu.tsx +173 -0
- package/src/ui/dialog.tsx +149 -0
- package/src/ui/dropdown-menu.tsx +178 -0
- package/src/ui/hover-card.tsx +31 -0
- package/src/ui/input-group.tsx +162 -0
- package/src/ui/input-group.verve.tsx +150 -0
- package/src/ui/input.tsx +21 -0
- package/src/ui/kbd.tsx +18 -0
- package/src/ui/label.tsx +20 -0
- package/src/ui/labeled-switch-row.tsx +53 -0
- package/src/ui/modalTransition.ts +85 -0
- package/src/ui/pagination.tsx +47 -0
- package/src/ui/popover.tsx +33 -0
- package/src/ui/progress.tsx +25 -0
- package/src/ui/radix-select.tsx +202 -0
- package/src/ui/scroll-area.tsx +55 -0
- package/src/ui/scroll-area.verve.tsx +43 -0
- package/src/ui/search-input.tsx +29 -0
- package/src/ui/select.tsx +163 -0
- package/src/ui/separator.tsx +28 -0
- package/src/ui/sheet.tsx +87 -0
- package/src/ui/skeleton.tsx +18 -0
- package/src/ui/sonner.css +16 -0
- package/src/ui/sonner.tsx +47 -0
- package/src/ui/spinner.tsx +27 -0
- package/src/ui/surface-classes.ts +55 -0
- package/src/ui/switch.tsx +26 -0
- package/src/ui/table.tsx +123 -0
- package/src/ui/tabs.tsx +140 -0
- package/src/ui/tabsSliding.ts +56 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/time-picker.tsx +170 -0
- package/src/ui/tooltip.tsx +25 -0
- package/src/ui/visually-hidden.tsx +3 -0
- package/src/utils/cn.ts +16 -0
- package/src/utils/ref.ts +10 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vvedantb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,126 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Shared React 19 UI primitives for vmem, vibot and Verve.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/vvedantb/vv-ui.git",
|
|
13
|
+
"directory": "packages/ui"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./src/index.ts",
|
|
18
|
+
"default": "./src/index.ts"
|
|
19
|
+
},
|
|
20
|
+
"./cn": {
|
|
21
|
+
"types": "./src/utils/cn.ts",
|
|
22
|
+
"default": "./src/utils/cn.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "./src/index.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": [
|
|
31
|
+
"./src/ui/sonner.css"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@radix-ui/react-accordion": "^1.2.12",
|
|
39
|
+
"@radix-ui/react-checkbox": "^1.3.3",
|
|
40
|
+
"@radix-ui/react-collapsible": "^1.1.12",
|
|
41
|
+
"@radix-ui/react-context-menu": "^2.2.15",
|
|
42
|
+
"@radix-ui/react-dialog": "^1.1.15",
|
|
43
|
+
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
44
|
+
"@radix-ui/react-hover-card": "^1.1.15",
|
|
45
|
+
"@radix-ui/react-label": "^2.1.8",
|
|
46
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
47
|
+
"@radix-ui/react-progress": "^1.1.8",
|
|
48
|
+
"@radix-ui/react-scroll-area": "^1.2.10",
|
|
49
|
+
"@radix-ui/react-select": "^2.2.6",
|
|
50
|
+
"@radix-ui/react-separator": "^1.1.8",
|
|
51
|
+
"@radix-ui/react-slot": "^1.2.4",
|
|
52
|
+
"@radix-ui/react-switch": "^1.1.7",
|
|
53
|
+
"@radix-ui/react-tabs": "^1.1.13",
|
|
54
|
+
"@radix-ui/react-tooltip": "^1.2.8",
|
|
55
|
+
"@radix-ui/react-use-controllable-state": "^1.2.2",
|
|
56
|
+
"@radix-ui/react-visually-hidden": "^1.2.3",
|
|
57
|
+
"@streamdown/cjk": "*",
|
|
58
|
+
"@streamdown/code": "*",
|
|
59
|
+
"@streamdown/math": "*",
|
|
60
|
+
"@streamdown/mermaid": "*",
|
|
61
|
+
"@tabler/icons-react": "^3.35.0",
|
|
62
|
+
"@vvedantb/tokens": "*",
|
|
63
|
+
"ai": ">=5.0.0",
|
|
64
|
+
"class-variance-authority": "^0.7.1",
|
|
65
|
+
"clsx": "^2.1.1",
|
|
66
|
+
"cmdk": "^1.1.1",
|
|
67
|
+
"embla-carousel-react": "^8.6.0",
|
|
68
|
+
"motion": ">=12.0.0",
|
|
69
|
+
"nanoid": "^5.1.0",
|
|
70
|
+
"radix-ui": "^1.4.0",
|
|
71
|
+
"react": ">=19.0.0",
|
|
72
|
+
"react-dom": ">=19.0.0",
|
|
73
|
+
"shiki": "^3.0.0",
|
|
74
|
+
"sonner": "^2.0.3",
|
|
75
|
+
"streamdown": "*",
|
|
76
|
+
"tailwind-merge": "^2.6.0",
|
|
77
|
+
"use-stick-to-bottom": "^1.1.0",
|
|
78
|
+
"vaul": "^1.1.0"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@radix-ui/react-accordion": "^1.2.12",
|
|
82
|
+
"@radix-ui/react-checkbox": "^1.3.3",
|
|
83
|
+
"@radix-ui/react-collapsible": "^1.1.12",
|
|
84
|
+
"@radix-ui/react-context-menu": "^2.2.15",
|
|
85
|
+
"@radix-ui/react-dialog": "^1.1.15",
|
|
86
|
+
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
87
|
+
"@radix-ui/react-hover-card": "^1.1.15",
|
|
88
|
+
"@radix-ui/react-label": "^2.1.8",
|
|
89
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
90
|
+
"@radix-ui/react-progress": "^1.1.8",
|
|
91
|
+
"@radix-ui/react-scroll-area": "^1.2.10",
|
|
92
|
+
"@radix-ui/react-select": "^2.2.6",
|
|
93
|
+
"@radix-ui/react-separator": "^1.1.8",
|
|
94
|
+
"@radix-ui/react-slot": "^1.2.4",
|
|
95
|
+
"@radix-ui/react-switch": "^1.1.7",
|
|
96
|
+
"@radix-ui/react-tabs": "^1.1.13",
|
|
97
|
+
"@radix-ui/react-tooltip": "^1.2.8",
|
|
98
|
+
"@radix-ui/react-use-controllable-state": "^1.2.2",
|
|
99
|
+
"@radix-ui/react-visually-hidden": "^1.2.3",
|
|
100
|
+
"@streamdown/cjk": "*",
|
|
101
|
+
"@streamdown/code": "*",
|
|
102
|
+
"@streamdown/math": "*",
|
|
103
|
+
"@streamdown/mermaid": "*",
|
|
104
|
+
"@tabler/icons-react": "^3.35.0",
|
|
105
|
+
"@types/react": "^19.1.0",
|
|
106
|
+
"@types/react-dom": "^19.1.0",
|
|
107
|
+
"@vvedantb/tokens": "workspace:*",
|
|
108
|
+
"ai": "^5.0.0",
|
|
109
|
+
"class-variance-authority": "^0.7.1",
|
|
110
|
+
"clsx": "^2.1.1",
|
|
111
|
+
"cmdk": "^1.1.1",
|
|
112
|
+
"embla-carousel-react": "^8.6.0",
|
|
113
|
+
"motion": "^12.0.0",
|
|
114
|
+
"nanoid": "^5.1.0",
|
|
115
|
+
"radix-ui": "^1.4.0",
|
|
116
|
+
"react": "^19.1.0",
|
|
117
|
+
"react-dom": "^19.1.0",
|
|
118
|
+
"shiki": "^3.0.0",
|
|
119
|
+
"sonner": "^2.0.3",
|
|
120
|
+
"streamdown": "*",
|
|
121
|
+
"tailwind-merge": "^2.6.0",
|
|
122
|
+
"typescript": "^5.9.0",
|
|
123
|
+
"use-stick-to-bottom": "^1.1.0",
|
|
124
|
+
"vaul": "^1.1.0"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { Button } from "../ui/button";
|
|
6
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
|
|
7
|
+
import { cn } from "../utils/cn";
|
|
8
|
+
import { flatElevatedSurfaceClass } from "../ui/surface-classes";
|
|
9
|
+
|
|
10
|
+
export type ArtifactProps = ComponentProps<"div">;
|
|
11
|
+
|
|
12
|
+
export const Artifact = ({ className, ...props }: ArtifactProps) => (
|
|
13
|
+
<div
|
|
14
|
+
className={cn(flatElevatedSurfaceClass, "rounded-lg", className)}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export type ArtifactHeaderProps = ComponentProps<"div">;
|
|
20
|
+
|
|
21
|
+
export const ArtifactHeader = ({
|
|
22
|
+
className,
|
|
23
|
+
...props
|
|
24
|
+
}: ArtifactHeaderProps) => (
|
|
25
|
+
<div
|
|
26
|
+
className={cn(
|
|
27
|
+
"flex items-start justify-between gap-2 px-4 py-3",
|
|
28
|
+
className,
|
|
29
|
+
)}
|
|
30
|
+
{...props}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export type ArtifactTitleProps = ComponentProps<"p">;
|
|
35
|
+
|
|
36
|
+
export const ArtifactTitle = ({ className, ...props }: ArtifactTitleProps) => (
|
|
37
|
+
<p
|
|
38
|
+
className={cn("text-sm font-medium text-foreground", className)}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export type ArtifactDescriptionProps = ComponentProps<"p">;
|
|
44
|
+
|
|
45
|
+
export const ArtifactDescription = ({
|
|
46
|
+
className,
|
|
47
|
+
...props
|
|
48
|
+
}: ArtifactDescriptionProps) => (
|
|
49
|
+
<p className={cn("text-xs text-muted", className)} {...props} />
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export type ArtifactActionsProps = ComponentProps<"div">;
|
|
53
|
+
|
|
54
|
+
export const ArtifactActions = ({
|
|
55
|
+
className,
|
|
56
|
+
...props
|
|
57
|
+
}: ArtifactActionsProps) => (
|
|
58
|
+
<div className={cn("flex items-center gap-1", className)} {...props} />
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export type ArtifactActionProps = ComponentProps<typeof Button> & {
|
|
62
|
+
tooltip: string;
|
|
63
|
+
icon: ReactNode;
|
|
64
|
+
label?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const ArtifactAction = ({
|
|
68
|
+
tooltip,
|
|
69
|
+
icon,
|
|
70
|
+
label,
|
|
71
|
+
className,
|
|
72
|
+
variant = "ghost",
|
|
73
|
+
size = "icon",
|
|
74
|
+
...props
|
|
75
|
+
}: ArtifactActionProps) => (
|
|
76
|
+
<Tooltip>
|
|
77
|
+
<TooltipTrigger asChild>
|
|
78
|
+
<Button
|
|
79
|
+
variant={variant}
|
|
80
|
+
size={size}
|
|
81
|
+
className={cn("min-w-6 h-6", className)}
|
|
82
|
+
aria-label={label ?? tooltip}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
{icon}
|
|
86
|
+
</Button>
|
|
87
|
+
</TooltipTrigger>
|
|
88
|
+
<TooltipContent>{tooltip}</TooltipContent>
|
|
89
|
+
</Tooltip>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export type ArtifactContentProps = ComponentProps<"div">;
|
|
93
|
+
|
|
94
|
+
export const ArtifactContent = ({
|
|
95
|
+
className,
|
|
96
|
+
...props
|
|
97
|
+
}: ArtifactContentProps) => (
|
|
98
|
+
<div className={cn("px-4 pb-4", className)} {...props} />
|
|
99
|
+
);
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { FileUIPart, SourceDocumentUIPart } from "ai";
|
|
3
|
+
import type { ComponentProps, HTMLAttributes, ReactNode } from "react";
|
|
4
|
+
import { Button } from "../ui/button";
|
|
5
|
+
import {
|
|
6
|
+
HoverCard,
|
|
7
|
+
HoverCardContent,
|
|
8
|
+
HoverCardTrigger,
|
|
9
|
+
} from "../ui/hover-card";
|
|
10
|
+
import { cn } from "../utils/cn";
|
|
11
|
+
import {
|
|
12
|
+
flatElevatedSurfaceHoverClass,
|
|
13
|
+
flatPanelSubtleClass,
|
|
14
|
+
} from "../ui/surface-classes";
|
|
15
|
+
import {
|
|
16
|
+
IconFileText,
|
|
17
|
+
IconMusic,
|
|
18
|
+
IconPaperclip,
|
|
19
|
+
IconPhoto,
|
|
20
|
+
IconVideo,
|
|
21
|
+
IconWorld,
|
|
22
|
+
IconX,
|
|
23
|
+
} from "@tabler/icons-react";
|
|
24
|
+
import { createContext, useContext } from "react";
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Types
|
|
27
|
+
// ============================================================================
|
|
28
|
+
export type AttachmentData =
|
|
29
|
+
| (FileUIPart & {
|
|
30
|
+
id: string;
|
|
31
|
+
})
|
|
32
|
+
| (SourceDocumentUIPart & {
|
|
33
|
+
id: string;
|
|
34
|
+
});
|
|
35
|
+
export type AttachmentMediaCategory =
|
|
36
|
+
| "image"
|
|
37
|
+
| "video"
|
|
38
|
+
| "audio"
|
|
39
|
+
| "document"
|
|
40
|
+
| "source"
|
|
41
|
+
| "unknown";
|
|
42
|
+
export type AttachmentVariant = "grid" | "inline" | "list";
|
|
43
|
+
const mediaCategoryIcons: Record<AttachmentMediaCategory, typeof IconPhoto> = {
|
|
44
|
+
audio: IconMusic,
|
|
45
|
+
document: IconFileText,
|
|
46
|
+
image: IconPhoto,
|
|
47
|
+
source: IconWorld,
|
|
48
|
+
unknown: IconPaperclip,
|
|
49
|
+
video: IconVideo,
|
|
50
|
+
};
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Utility Functions
|
|
53
|
+
// ============================================================================
|
|
54
|
+
export const getMediaCategory = (
|
|
55
|
+
data: AttachmentData,
|
|
56
|
+
): AttachmentMediaCategory => {
|
|
57
|
+
if (data.type === "source-document") {
|
|
58
|
+
return "source";
|
|
59
|
+
}
|
|
60
|
+
const mediaType = data.mediaType ?? "";
|
|
61
|
+
if (mediaType.startsWith("image/")) {
|
|
62
|
+
return "image";
|
|
63
|
+
}
|
|
64
|
+
if (mediaType.startsWith("video/")) {
|
|
65
|
+
return "video";
|
|
66
|
+
}
|
|
67
|
+
if (mediaType.startsWith("audio/")) {
|
|
68
|
+
return "audio";
|
|
69
|
+
}
|
|
70
|
+
if (mediaType.startsWith("application/") || mediaType.startsWith("text/")) {
|
|
71
|
+
return "document";
|
|
72
|
+
}
|
|
73
|
+
return "unknown";
|
|
74
|
+
};
|
|
75
|
+
export const getAttachmentLabel = (data: AttachmentData): string => {
|
|
76
|
+
if (data.type === "source-document") {
|
|
77
|
+
return data.title || data.filename || "Source";
|
|
78
|
+
}
|
|
79
|
+
const category = getMediaCategory(data);
|
|
80
|
+
return data.filename || (category === "image" ? "Image" : "Attachment");
|
|
81
|
+
};
|
|
82
|
+
const renderAttachmentImage = (
|
|
83
|
+
url: string,
|
|
84
|
+
filename: string | undefined,
|
|
85
|
+
isGrid: boolean,
|
|
86
|
+
) =>
|
|
87
|
+
isGrid ? (
|
|
88
|
+
<img
|
|
89
|
+
alt={filename || "Image"}
|
|
90
|
+
className="size-full object-cover"
|
|
91
|
+
height={96}
|
|
92
|
+
src={url}
|
|
93
|
+
width={96}
|
|
94
|
+
/>
|
|
95
|
+
) : (
|
|
96
|
+
<img
|
|
97
|
+
alt={filename || "Image"}
|
|
98
|
+
className="size-full rounded object-cover"
|
|
99
|
+
height={20}
|
|
100
|
+
src={url}
|
|
101
|
+
width={20}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
// ============================================================================
|
|
105
|
+
// Contexts
|
|
106
|
+
// ============================================================================
|
|
107
|
+
interface AttachmentsContextValue {
|
|
108
|
+
variant: AttachmentVariant;
|
|
109
|
+
}
|
|
110
|
+
const AttachmentsContext = createContext<AttachmentsContextValue | null>(null);
|
|
111
|
+
interface AttachmentContextValue {
|
|
112
|
+
data: AttachmentData;
|
|
113
|
+
mediaCategory: AttachmentMediaCategory;
|
|
114
|
+
onRemove?: () => void;
|
|
115
|
+
variant: AttachmentVariant;
|
|
116
|
+
}
|
|
117
|
+
const AttachmentContext = createContext<AttachmentContextValue | null>(null);
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// Hooks
|
|
120
|
+
// ============================================================================
|
|
121
|
+
export const useAttachmentsContext = () =>
|
|
122
|
+
useContext(AttachmentsContext) ?? { variant: "grid" as const };
|
|
123
|
+
export const useAttachmentContext = () => {
|
|
124
|
+
const ctx = useContext(AttachmentContext);
|
|
125
|
+
if (!ctx) {
|
|
126
|
+
throw new Error("Attachment components must be used within <Attachment>");
|
|
127
|
+
}
|
|
128
|
+
return ctx;
|
|
129
|
+
};
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// Attachments - Container
|
|
132
|
+
// ============================================================================
|
|
133
|
+
export type AttachmentsProps = HTMLAttributes<HTMLDivElement> & {
|
|
134
|
+
variant?: AttachmentVariant;
|
|
135
|
+
};
|
|
136
|
+
export const Attachments = ({
|
|
137
|
+
variant = "grid",
|
|
138
|
+
className,
|
|
139
|
+
children,
|
|
140
|
+
...props
|
|
141
|
+
}: AttachmentsProps) => {
|
|
142
|
+
const contextValue = { variant };
|
|
143
|
+
return (
|
|
144
|
+
<AttachmentsContext.Provider value={contextValue}>
|
|
145
|
+
<div
|
|
146
|
+
className={cn(
|
|
147
|
+
"flex items-start",
|
|
148
|
+
variant === "list" ? "flex-col gap-2" : "flex-wrap gap-2",
|
|
149
|
+
variant === "grid" && "ml-auto w-fit",
|
|
150
|
+
className,
|
|
151
|
+
)}
|
|
152
|
+
{...props}
|
|
153
|
+
>
|
|
154
|
+
{children}
|
|
155
|
+
</div>
|
|
156
|
+
</AttachmentsContext.Provider>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// Attachment - Item
|
|
161
|
+
// ============================================================================
|
|
162
|
+
export type AttachmentProps = HTMLAttributes<HTMLDivElement> & {
|
|
163
|
+
data: AttachmentData;
|
|
164
|
+
onRemove?: () => void;
|
|
165
|
+
};
|
|
166
|
+
export const Attachment = ({
|
|
167
|
+
data,
|
|
168
|
+
onRemove,
|
|
169
|
+
className,
|
|
170
|
+
children,
|
|
171
|
+
...props
|
|
172
|
+
}: AttachmentProps) => {
|
|
173
|
+
const { variant } = useAttachmentsContext();
|
|
174
|
+
const mediaCategory = getMediaCategory(data);
|
|
175
|
+
const contextValue = { data, mediaCategory, onRemove, variant };
|
|
176
|
+
return (
|
|
177
|
+
<AttachmentContext.Provider value={contextValue}>
|
|
178
|
+
<div
|
|
179
|
+
className={cn(
|
|
180
|
+
"group relative",
|
|
181
|
+
variant === "grid" && "size-24 overflow-hidden rounded-lg",
|
|
182
|
+
variant === "inline" && [
|
|
183
|
+
"flex h-8 cursor-pointer select-none items-center gap-1.5",
|
|
184
|
+
"rounded-md px-1.5",
|
|
185
|
+
"font-medium text-sm transition-[background-color,color,transform] duration-150 ease-out",
|
|
186
|
+
"active:scale-[0.97] hover:bg-surface-secondary hover:text-foreground",
|
|
187
|
+
],
|
|
188
|
+
variant === "list" && [
|
|
189
|
+
"flex w-full items-center gap-3 rounded-lg p-3",
|
|
190
|
+
"transition-[background-color,transform] duration-150 ease-out active:scale-[0.99] hover:bg-surface-secondary",
|
|
191
|
+
],
|
|
192
|
+
className,
|
|
193
|
+
)}
|
|
194
|
+
{...props}
|
|
195
|
+
>
|
|
196
|
+
{children}
|
|
197
|
+
</div>
|
|
198
|
+
</AttachmentContext.Provider>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
// ============================================================================
|
|
202
|
+
// AttachmentPreview - Media preview
|
|
203
|
+
// ============================================================================
|
|
204
|
+
export type AttachmentPreviewProps = HTMLAttributes<HTMLDivElement> & {
|
|
205
|
+
fallbackIcon?: ReactNode;
|
|
206
|
+
};
|
|
207
|
+
export const AttachmentPreview = ({
|
|
208
|
+
fallbackIcon,
|
|
209
|
+
className,
|
|
210
|
+
...props
|
|
211
|
+
}: AttachmentPreviewProps) => {
|
|
212
|
+
const { data, mediaCategory, variant } = useAttachmentContext();
|
|
213
|
+
const iconSize = variant === "inline" ? "size-3" : "size-4";
|
|
214
|
+
const renderIcon = (Icon: typeof IconPhoto) => (
|
|
215
|
+
<Icon className={cn(iconSize, "text-muted")} />
|
|
216
|
+
);
|
|
217
|
+
const renderContent = () => {
|
|
218
|
+
if (mediaCategory === "image" && data.type === "file" && data.url) {
|
|
219
|
+
return renderAttachmentImage(data.url, data.filename, variant === "grid");
|
|
220
|
+
}
|
|
221
|
+
if (mediaCategory === "video" && data.type === "file" && data.url) {
|
|
222
|
+
return <video className="size-full object-cover" muted src={data.url} />;
|
|
223
|
+
}
|
|
224
|
+
const Icon = mediaCategoryIcons[mediaCategory];
|
|
225
|
+
return fallbackIcon ?? renderIcon(Icon);
|
|
226
|
+
};
|
|
227
|
+
return (
|
|
228
|
+
<div
|
|
229
|
+
className={cn(
|
|
230
|
+
"flex shrink-0 items-center justify-center overflow-hidden",
|
|
231
|
+
variant === "grid" && cn("size-full", flatPanelSubtleClass),
|
|
232
|
+
variant === "inline" && cn("size-5 rounded", flatPanelSubtleClass),
|
|
233
|
+
variant === "list" && cn("size-12 rounded", flatPanelSubtleClass),
|
|
234
|
+
className,
|
|
235
|
+
)}
|
|
236
|
+
{...props}
|
|
237
|
+
>
|
|
238
|
+
{renderContent()}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
// ============================================================================
|
|
243
|
+
// AttachmentInfo - Name and type display
|
|
244
|
+
// ============================================================================
|
|
245
|
+
export type AttachmentInfoProps = HTMLAttributes<HTMLDivElement> & {
|
|
246
|
+
showMediaType?: boolean;
|
|
247
|
+
};
|
|
248
|
+
export const AttachmentInfo = ({
|
|
249
|
+
showMediaType = false,
|
|
250
|
+
className,
|
|
251
|
+
...props
|
|
252
|
+
}: AttachmentInfoProps) => {
|
|
253
|
+
const { data, variant } = useAttachmentContext();
|
|
254
|
+
const label = getAttachmentLabel(data);
|
|
255
|
+
if (variant === "grid") {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
return (
|
|
259
|
+
<div className={cn("min-w-0 flex-1", className)} {...props}>
|
|
260
|
+
<span className="block truncate">{label}</span>
|
|
261
|
+
{showMediaType && data.mediaType && (
|
|
262
|
+
<span className="block truncate text-muted text-xs">
|
|
263
|
+
{data.mediaType}
|
|
264
|
+
</span>
|
|
265
|
+
)}
|
|
266
|
+
</div>
|
|
267
|
+
);
|
|
268
|
+
};
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// AttachmentRemove - Remove button
|
|
271
|
+
// ============================================================================
|
|
272
|
+
export type AttachmentRemoveProps = ComponentProps<typeof Button> & {
|
|
273
|
+
label?: string;
|
|
274
|
+
};
|
|
275
|
+
export const AttachmentRemove = ({
|
|
276
|
+
label = "Remove",
|
|
277
|
+
className,
|
|
278
|
+
children,
|
|
279
|
+
...props
|
|
280
|
+
}: AttachmentRemoveProps) => {
|
|
281
|
+
const { onRemove, variant } = useAttachmentContext();
|
|
282
|
+
const handleClick = (e: React.MouseEvent) => {
|
|
283
|
+
e.stopPropagation();
|
|
284
|
+
onRemove?.();
|
|
285
|
+
};
|
|
286
|
+
if (!onRemove) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
return (
|
|
290
|
+
<Button
|
|
291
|
+
aria-label={label}
|
|
292
|
+
className={cn(
|
|
293
|
+
variant === "grid" && [
|
|
294
|
+
"absolute top-2 right-2 size-6 rounded-full p-0",
|
|
295
|
+
cn(flatPanelSubtleClass, flatElevatedSurfaceHoverClass),
|
|
296
|
+
"opacity-0 transition-opacity group-hover:opacity-100",
|
|
297
|
+
"[&>svg]:size-3",
|
|
298
|
+
],
|
|
299
|
+
variant === "inline" && [
|
|
300
|
+
"size-5 rounded p-0",
|
|
301
|
+
"opacity-0 transition-opacity group-hover:opacity-100",
|
|
302
|
+
"[&>svg]:size-2.5",
|
|
303
|
+
],
|
|
304
|
+
variant === "list" && ["size-8 shrink-0 rounded p-0", "[&>svg]:size-4"],
|
|
305
|
+
className,
|
|
306
|
+
)}
|
|
307
|
+
onClick={handleClick}
|
|
308
|
+
type="button"
|
|
309
|
+
variant="ghost"
|
|
310
|
+
{...props}
|
|
311
|
+
>
|
|
312
|
+
{children ?? <IconX />}
|
|
313
|
+
<span className="sr-only">{label}</span>
|
|
314
|
+
</Button>
|
|
315
|
+
);
|
|
316
|
+
};
|
|
317
|
+
// ============================================================================
|
|
318
|
+
// AttachmentHoverCard - Hover preview
|
|
319
|
+
// ============================================================================
|
|
320
|
+
export type AttachmentHoverCardProps = ComponentProps<typeof HoverCard>;
|
|
321
|
+
export const AttachmentHoverCard = ({
|
|
322
|
+
openDelay = 0,
|
|
323
|
+
closeDelay = 0,
|
|
324
|
+
...props
|
|
325
|
+
}: AttachmentHoverCardProps) => (
|
|
326
|
+
<HoverCard closeDelay={closeDelay} openDelay={openDelay} {...props} />
|
|
327
|
+
);
|
|
328
|
+
export type AttachmentHoverCardTriggerProps = ComponentProps<
|
|
329
|
+
typeof HoverCardTrigger
|
|
330
|
+
>;
|
|
331
|
+
export const AttachmentHoverCardTrigger = (
|
|
332
|
+
props: AttachmentHoverCardTriggerProps,
|
|
333
|
+
) => <HoverCardTrigger {...props} />;
|
|
334
|
+
export type AttachmentHoverCardContentProps = ComponentProps<
|
|
335
|
+
typeof HoverCardContent
|
|
336
|
+
>;
|
|
337
|
+
export const AttachmentHoverCardContent = ({
|
|
338
|
+
align = "start",
|
|
339
|
+
className,
|
|
340
|
+
...props
|
|
341
|
+
}: AttachmentHoverCardContentProps) => (
|
|
342
|
+
<HoverCardContent
|
|
343
|
+
align={align}
|
|
344
|
+
className={cn("w-auto p-2", className)}
|
|
345
|
+
{...props}
|
|
346
|
+
/>
|
|
347
|
+
);
|
|
348
|
+
// ============================================================================
|
|
349
|
+
// AttachmentEmpty - Empty state
|
|
350
|
+
// ============================================================================
|
|
351
|
+
export type AttachmentEmptyProps = HTMLAttributes<HTMLDivElement>;
|
|
352
|
+
export const AttachmentEmpty = ({
|
|
353
|
+
className,
|
|
354
|
+
children,
|
|
355
|
+
...props
|
|
356
|
+
}: AttachmentEmptyProps) => (
|
|
357
|
+
<div
|
|
358
|
+
className={cn(
|
|
359
|
+
"flex items-center justify-center p-4 text-muted text-sm",
|
|
360
|
+
className,
|
|
361
|
+
)}
|
|
362
|
+
{...props}
|
|
363
|
+
>
|
|
364
|
+
{children ?? "No attachments"}
|
|
365
|
+
</div>
|
|
366
|
+
);
|