@theruntime/components 0.0.0 → 0.0.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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +113 -4
  3. package/src/accordion.tsx +62 -0
  4. package/src/alert-dialog.tsx +177 -0
  5. package/src/alert.tsx +60 -0
  6. package/src/aspect-ratio.tsx +7 -0
  7. package/src/attachment.tsx +192 -0
  8. package/src/avatar.tsx +94 -0
  9. package/src/badge.tsx +46 -0
  10. package/src/breadcrumb.tsx +102 -0
  11. package/src/bubble.tsx +125 -0
  12. package/src/button-group.tsx +82 -0
  13. package/src/button.tsx +62 -0
  14. package/src/calendar.tsx +178 -0
  15. package/src/card.tsx +75 -0
  16. package/src/carousel.tsx +228 -0
  17. package/src/chart/container.tsx +72 -0
  18. package/src/chart/context.tsx +39 -0
  19. package/src/chart/index.ts +4 -0
  20. package/src/chart/legend.tsx +63 -0
  21. package/src/chart/payload.ts +31 -0
  22. package/src/chart/tooltip.tsx +149 -0
  23. package/src/checkbox.tsx +27 -0
  24. package/src/cn.ts +36 -0
  25. package/src/collapsible.tsx +19 -0
  26. package/src/combobox/chips.tsx +71 -0
  27. package/src/combobox/content.tsx +123 -0
  28. package/src/combobox/index.ts +13 -0
  29. package/src/combobox/input.tsx +39 -0
  30. package/src/combobox/trigger.tsx +44 -0
  31. package/src/command.tsx +153 -0
  32. package/src/context-menu.tsx +222 -0
  33. package/src/dialog.tsx +142 -0
  34. package/src/direction.tsx +18 -0
  35. package/src/drawer.tsx +122 -0
  36. package/src/dropdown-menu.tsx +226 -0
  37. package/src/empty.tsx +94 -0
  38. package/src/field.tsx +232 -0
  39. package/src/form.tsx +153 -0
  40. package/src/hover-card.tsx +36 -0
  41. package/src/index.ts +90 -0
  42. package/src/input-group.tsx +156 -0
  43. package/src/input-otp.tsx +68 -0
  44. package/src/input.tsx +21 -0
  45. package/src/item.tsx +172 -0
  46. package/src/kbd.tsx +28 -0
  47. package/src/label.tsx +19 -0
  48. package/src/marker.tsx +66 -0
  49. package/src/menubar.tsx +250 -0
  50. package/src/message-scroller.tsx +128 -0
  51. package/src/message.tsx +85 -0
  52. package/src/native-select.tsx +56 -0
  53. package/src/navigation-menu.tsx +161 -0
  54. package/src/pagination.tsx +106 -0
  55. package/src/popover.tsx +72 -0
  56. package/src/progress.tsx +26 -0
  57. package/src/questionnaire/actions.tsx +118 -0
  58. package/src/questionnaire/choices.tsx +113 -0
  59. package/src/questionnaire/index.ts +21 -0
  60. package/src/questionnaire/root.tsx +75 -0
  61. package/src/radio-group.tsx +43 -0
  62. package/src/resizable.tsx +45 -0
  63. package/src/scroll-area.tsx +54 -0
  64. package/src/select.tsx +173 -0
  65. package/src/separator.tsx +26 -0
  66. package/src/sheet.tsx +132 -0
  67. package/src/shell/app-tab.tsx +67 -0
  68. package/src/shell/entry-row.tsx +137 -0
  69. package/src/shell/field.tsx +83 -0
  70. package/src/shell/group-head.tsx +19 -0
  71. package/src/shell/scope-chip.tsx +32 -0
  72. package/src/shell/suggest-panel.tsx +92 -0
  73. package/src/sidebar/context.tsx +128 -0
  74. package/src/sidebar/index.ts +23 -0
  75. package/src/sidebar/menu.tsx +239 -0
  76. package/src/sidebar/sections.tsx +118 -0
  77. package/src/sidebar/sidebar.tsx +183 -0
  78. package/src/skeleton.tsx +13 -0
  79. package/src/slider.tsx +56 -0
  80. package/src/sonner.tsx +41 -0
  81. package/src/spinner.tsx +16 -0
  82. package/src/styles.css +149 -0
  83. package/src/switch.tsx +33 -0
  84. package/src/table.tsx +90 -0
  85. package/src/tabs.tsx +79 -0
  86. package/src/textarea.tsx +18 -0
  87. package/src/toggle-group.tsx +81 -0
  88. package/src/toggle.tsx +44 -0
  89. package/src/tooltip.tsx +51 -0
  90. package/src/use-mobile.ts +21 -0
  91. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright 2026 Digital Pine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ 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,9 +1,118 @@
1
1
  {
2
2
  "name": "@theruntime/components",
3
- "version": "0.0.0",
4
- "description": "Placeholder. The first release replaces it.",
3
+ "version": "0.0.1",
5
4
  "license": "MIT",
6
- "publishConfig": {
7
- "access": "public"
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/DigitalPine/runtime.git",
8
+ "directory": "packages/components"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "!**/*.test.ts",
13
+ "!**/*.test.tsx"
14
+ ],
15
+ "type": "module",
16
+ "exports": {
17
+ ".": "./src/index.ts",
18
+ "./package.json": "./package.json",
19
+ "./styles.css": "./src/styles.css",
20
+ "./accordion": "./src/accordion.tsx",
21
+ "./alert-dialog": "./src/alert-dialog.tsx",
22
+ "./alert": "./src/alert.tsx",
23
+ "./aspect-ratio": "./src/aspect-ratio.tsx",
24
+ "./attachment": "./src/attachment.tsx",
25
+ "./avatar": "./src/avatar.tsx",
26
+ "./badge": "./src/badge.tsx",
27
+ "./breadcrumb": "./src/breadcrumb.tsx",
28
+ "./bubble": "./src/bubble.tsx",
29
+ "./button-group": "./src/button-group.tsx",
30
+ "./button": "./src/button.tsx",
31
+ "./calendar": "./src/calendar.tsx",
32
+ "./card": "./src/card.tsx",
33
+ "./carousel": "./src/carousel.tsx",
34
+ "./checkbox": "./src/checkbox.tsx",
35
+ "./cn": "./src/cn.ts",
36
+ "./collapsible": "./src/collapsible.tsx",
37
+ "./command": "./src/command.tsx",
38
+ "./context-menu": "./src/context-menu.tsx",
39
+ "./dialog": "./src/dialog.tsx",
40
+ "./direction": "./src/direction.tsx",
41
+ "./drawer": "./src/drawer.tsx",
42
+ "./dropdown-menu": "./src/dropdown-menu.tsx",
43
+ "./empty": "./src/empty.tsx",
44
+ "./field": "./src/field.tsx",
45
+ "./form": "./src/form.tsx",
46
+ "./hover-card": "./src/hover-card.tsx",
47
+ "./input-group": "./src/input-group.tsx",
48
+ "./input-otp": "./src/input-otp.tsx",
49
+ "./input": "./src/input.tsx",
50
+ "./item": "./src/item.tsx",
51
+ "./kbd": "./src/kbd.tsx",
52
+ "./label": "./src/label.tsx",
53
+ "./marker": "./src/marker.tsx",
54
+ "./menubar": "./src/menubar.tsx",
55
+ "./message-scroller": "./src/message-scroller.tsx",
56
+ "./message": "./src/message.tsx",
57
+ "./native-select": "./src/native-select.tsx",
58
+ "./navigation-menu": "./src/navigation-menu.tsx",
59
+ "./pagination": "./src/pagination.tsx",
60
+ "./popover": "./src/popover.tsx",
61
+ "./progress": "./src/progress.tsx",
62
+ "./radio-group": "./src/radio-group.tsx",
63
+ "./resizable": "./src/resizable.tsx",
64
+ "./scroll-area": "./src/scroll-area.tsx",
65
+ "./select": "./src/select.tsx",
66
+ "./separator": "./src/separator.tsx",
67
+ "./sheet": "./src/sheet.tsx",
68
+ "./skeleton": "./src/skeleton.tsx",
69
+ "./slider": "./src/slider.tsx",
70
+ "./sonner": "./src/sonner.tsx",
71
+ "./spinner": "./src/spinner.tsx",
72
+ "./switch": "./src/switch.tsx",
73
+ "./table": "./src/table.tsx",
74
+ "./tabs": "./src/tabs.tsx",
75
+ "./textarea": "./src/textarea.tsx",
76
+ "./toggle-group": "./src/toggle-group.tsx",
77
+ "./toggle": "./src/toggle.tsx",
78
+ "./tooltip": "./src/tooltip.tsx",
79
+ "./use-mobile": "./src/use-mobile.ts",
80
+ "./chart": "./src/chart/index.ts",
81
+ "./combobox": "./src/combobox/index.ts",
82
+ "./questionnaire": "./src/questionnaire/index.ts",
83
+ "./sidebar": "./src/sidebar/index.ts",
84
+ "./shell/app-tab": "./src/shell/app-tab.tsx",
85
+ "./shell/entry-row": "./src/shell/entry-row.tsx",
86
+ "./shell/field": "./src/shell/field.tsx",
87
+ "./shell/group-head": "./src/shell/group-head.tsx",
88
+ "./shell/scope-chip": "./src/shell/scope-chip.tsx",
89
+ "./shell/suggest-panel": "./src/shell/suggest-panel.tsx"
90
+ },
91
+ "dependencies": {
92
+ "@base-ui/react": "^1.7.0",
93
+ "@phosphor-icons/react": "^2.1.10",
94
+ "@shadcn/react": "^0.3.0",
95
+ "class-variance-authority": "^0.7.1",
96
+ "clsx": "^2.1.1",
97
+ "cmdk": "^1.1.1",
98
+ "embla-carousel-react": "^8.6.0",
99
+ "input-otp": "^1.4.2",
100
+ "next-themes": "^0.4.6",
101
+ "radix-ui": "^1.6.0",
102
+ "react-day-picker": "^10.0.1",
103
+ "react-hook-form": "^7.80.0",
104
+ "react-resizable-panels": "^4.12.0",
105
+ "recharts": "^3.8.1",
106
+ "sonner": "^2.0.7",
107
+ "tailwind-merge": "^3.6.0",
108
+ "vaul": "^1.1.2"
109
+ },
110
+ "devDependencies": {
111
+ "react": "^19.2.6",
112
+ "react-dom": "^19.2.6"
113
+ },
114
+ "peerDependencies": {
115
+ "react": "^19.0.0",
116
+ "react-dom": "^19.0.0"
8
117
  }
9
118
  }
@@ -0,0 +1,62 @@
1
+ import * as React from "react";
2
+ import { CaretDownIcon } from "@phosphor-icons/react";
3
+ import { Accordion as AccordionPrimitive } from "radix-ui";
4
+
5
+ import { cn } from "./cn";
6
+
7
+ function Accordion({ ...props }: React.ComponentProps<typeof AccordionPrimitive.Root>) {
8
+ return <AccordionPrimitive.Root data-slot="accordion" {...props} />;
9
+ }
10
+
11
+ function AccordionItem({
12
+ className,
13
+ ...props
14
+ }: React.ComponentProps<typeof AccordionPrimitive.Item>) {
15
+ return (
16
+ <AccordionPrimitive.Item
17
+ data-slot="accordion-item"
18
+ className={cn("border-b last:border-b-0", className)}
19
+ {...props}
20
+ />
21
+ );
22
+ }
23
+
24
+ function AccordionTrigger({
25
+ className,
26
+ children,
27
+ ...props
28
+ }: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
29
+ return (
30
+ <AccordionPrimitive.Header className="flex">
31
+ <AccordionPrimitive.Trigger
32
+ data-slot="accordion-trigger"
33
+ className={cn(
34
+ "flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
35
+ className,
36
+ )}
37
+ {...props}
38
+ >
39
+ {children}
40
+ <CaretDownIcon className="pointer-events-none size-4 shrink-0 translate-y-0.5 text-muted-foreground transition-transform duration-200" />
41
+ </AccordionPrimitive.Trigger>
42
+ </AccordionPrimitive.Header>
43
+ );
44
+ }
45
+
46
+ function AccordionContent({
47
+ className,
48
+ children,
49
+ ...props
50
+ }: React.ComponentProps<typeof AccordionPrimitive.Content>) {
51
+ return (
52
+ <AccordionPrimitive.Content
53
+ data-slot="accordion-content"
54
+ className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
55
+ {...props}
56
+ >
57
+ <div className={cn("pt-0 pb-4", className)}>{children}</div>
58
+ </AccordionPrimitive.Content>
59
+ );
60
+ }
61
+
62
+ export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
@@ -0,0 +1,177 @@
1
+ import * as React from "react";
2
+ import { AlertDialog as AlertDialogPrimitive } from "radix-ui";
3
+
4
+ import { cn } from "./cn";
5
+ import { Button } from "./button";
6
+
7
+ function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
8
+ return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
9
+ }
10
+
11
+ function AlertDialogTrigger({
12
+ ...props
13
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
14
+ return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />;
15
+ }
16
+
17
+ function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
18
+ return <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />;
19
+ }
20
+
21
+ function AlertDialogOverlay({
22
+ className,
23
+ ...props
24
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
25
+ return (
26
+ <AlertDialogPrimitive.Overlay
27
+ data-slot="alert-dialog-overlay"
28
+ className={cn(
29
+ "fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
30
+ className,
31
+ )}
32
+ {...props}
33
+ />
34
+ );
35
+ }
36
+
37
+ function AlertDialogContent({
38
+ className,
39
+ size = "default",
40
+ ...props
41
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Content> & {
42
+ size?: "default" | "sm";
43
+ }) {
44
+ return (
45
+ <AlertDialogPortal>
46
+ <AlertDialogOverlay />
47
+ <AlertDialogPrimitive.Content
48
+ data-slot="alert-dialog-content"
49
+ data-size={size}
50
+ className={cn(
51
+ "group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg",
52
+ className,
53
+ )}
54
+ {...props}
55
+ />
56
+ </AlertDialogPortal>
57
+ );
58
+ }
59
+
60
+ function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
61
+ return (
62
+ <div
63
+ data-slot="alert-dialog-header"
64
+ className={cn(
65
+ "grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
66
+ className,
67
+ )}
68
+ {...props}
69
+ />
70
+ );
71
+ }
72
+
73
+ function AlertDialogFooter({ className, ...props }: React.ComponentProps<"div">) {
74
+ return (
75
+ <div
76
+ data-slot="alert-dialog-footer"
77
+ className={cn(
78
+ "flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
79
+ className,
80
+ )}
81
+ {...props}
82
+ />
83
+ );
84
+ }
85
+
86
+ function AlertDialogTitle({
87
+ className,
88
+ ...props
89
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
90
+ return (
91
+ <AlertDialogPrimitive.Title
92
+ data-slot="alert-dialog-title"
93
+ className={cn(
94
+ "text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
95
+ className,
96
+ )}
97
+ {...props}
98
+ />
99
+ );
100
+ }
101
+
102
+ function AlertDialogDescription({
103
+ className,
104
+ ...props
105
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
106
+ return (
107
+ <AlertDialogPrimitive.Description
108
+ data-slot="alert-dialog-description"
109
+ className={cn("text-sm text-muted-foreground", className)}
110
+ {...props}
111
+ />
112
+ );
113
+ }
114
+
115
+ function AlertDialogMedia({ className, ...props }: React.ComponentProps<"div">) {
116
+ return (
117
+ <div
118
+ data-slot="alert-dialog-media"
119
+ className={cn(
120
+ "mb-2 inline-flex size-16 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
121
+ className,
122
+ )}
123
+ {...props}
124
+ />
125
+ );
126
+ }
127
+
128
+ function AlertDialogAction({
129
+ className,
130
+ variant = "default",
131
+ size = "default",
132
+ ...props
133
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Action> &
134
+ Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
135
+ return (
136
+ <Button variant={variant} size={size} asChild>
137
+ <AlertDialogPrimitive.Action
138
+ data-slot="alert-dialog-action"
139
+ className={cn(className)}
140
+ {...props}
141
+ />
142
+ </Button>
143
+ );
144
+ }
145
+
146
+ function AlertDialogCancel({
147
+ className,
148
+ variant = "outline",
149
+ size = "default",
150
+ ...props
151
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
152
+ Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
153
+ return (
154
+ <Button variant={variant} size={size} asChild>
155
+ <AlertDialogPrimitive.Cancel
156
+ data-slot="alert-dialog-cancel"
157
+ className={cn(className)}
158
+ {...props}
159
+ />
160
+ </Button>
161
+ );
162
+ }
163
+
164
+ export {
165
+ AlertDialog,
166
+ AlertDialogAction,
167
+ AlertDialogCancel,
168
+ AlertDialogContent,
169
+ AlertDialogDescription,
170
+ AlertDialogFooter,
171
+ AlertDialogHeader,
172
+ AlertDialogMedia,
173
+ AlertDialogOverlay,
174
+ AlertDialogPortal,
175
+ AlertDialogTitle,
176
+ AlertDialogTrigger,
177
+ };
package/src/alert.tsx ADDED
@@ -0,0 +1,60 @@
1
+ import * as React from "react";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+
4
+ import { cn } from "./cn";
5
+
6
+ const alertVariants = cva(
7
+ "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default: "bg-card text-card-foreground",
12
+ destructive:
13
+ "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current",
14
+ },
15
+ },
16
+ defaultVariants: {
17
+ variant: "default",
18
+ },
19
+ },
20
+ );
21
+
22
+ function Alert({
23
+ className,
24
+ variant,
25
+ ...props
26
+ }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
27
+ return (
28
+ <div
29
+ data-slot="alert"
30
+ role="alert"
31
+ className={cn(alertVariants({ variant }), className)}
32
+ {...props}
33
+ />
34
+ );
35
+ }
36
+
37
+ function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
38
+ return (
39
+ <div
40
+ data-slot="alert-title"
41
+ className={cn("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight", className)}
42
+ {...props}
43
+ />
44
+ );
45
+ }
46
+
47
+ function AlertDescription({ className, ...props }: React.ComponentProps<"div">) {
48
+ return (
49
+ <div
50
+ data-slot="alert-description"
51
+ className={cn(
52
+ "col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed",
53
+ className,
54
+ )}
55
+ {...props}
56
+ />
57
+ );
58
+ }
59
+
60
+ export { Alert, AlertTitle, AlertDescription };
@@ -0,0 +1,7 @@
1
+ import { AspectRatio as AspectRatioPrimitive } from "radix-ui";
2
+
3
+ function AspectRatio({ ...props }: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {
4
+ return <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props} />;
5
+ }
6
+
7
+ export { AspectRatio };
@@ -0,0 +1,192 @@
1
+ import * as React from "react";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import { Slot } from "radix-ui";
4
+
5
+ import { cn } from "./cn";
6
+ import { Button } from "./button";
7
+
8
+ const attachmentVariants = cva(
9
+ "group/attachment relative flex w-fit max-w-full min-w-0 shrink-0 flex-wrap rounded-xl border bg-card text-card-foreground transition-colors focus-within:ring-1 focus-within:ring-ring/50 has-[>a,>button]:hover:bg-muted/50 data-[state=error]:border-destructive/30 data-[state=idle]:border-dashed",
10
+ {
11
+ variants: {
12
+ size: {
13
+ default:
14
+ "gap-2 text-sm has-data-[slot=attachment-content]:px-2.5 has-data-[slot=attachment-content]:py-2 has-data-[slot=attachment-media]:p-2",
15
+ sm: "gap-2.5 text-xs has-data-[slot=attachment-content]:px-2 has-data-[slot=attachment-content]:py-1.5 has-data-[slot=attachment-media]:p-1.5",
16
+ xs: "gap-1.5 rounded-lg text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1",
17
+ },
18
+ orientation: {
19
+ horizontal: "min-w-40 items-center",
20
+ vertical: "w-24 flex-col has-data-[slot=attachment-content]:w-30",
21
+ },
22
+ },
23
+ },
24
+ );
25
+
26
+ function Attachment({
27
+ className,
28
+ state = "done",
29
+ size = "default",
30
+ orientation = "horizontal",
31
+ ...props
32
+ }: React.ComponentProps<"div"> &
33
+ VariantProps<typeof attachmentVariants> & {
34
+ state?: "idle" | "uploading" | "processing" | "error" | "done";
35
+ }) {
36
+ return (
37
+ <div
38
+ data-slot="attachment"
39
+ data-state={state}
40
+ data-size={size}
41
+ data-orientation={orientation}
42
+ className={cn(attachmentVariants({ size, orientation }), className)}
43
+ {...props}
44
+ />
45
+ );
46
+ }
47
+
48
+ const attachmentMediaVariants = cva(
49
+ "relative flex aspect-square w-10 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-muted text-foreground group-data-[orientation=vertical]/attachment:w-full group-data-[size=sm]/attachment:w-8 group-data-[size=xs]/attachment:w-7 group-data-[size=xs]/attachment:rounded-md group-data-[state=error]/attachment:bg-destructive/10 group-data-[state=error]/attachment:text-destructive group-data-[orientation=vertical]/attachment:*:data-[slot=spinner]:size-6! [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 group-data-[orientation=vertical]/attachment:[&_svg:not([class*='size-'])]:size-6 group-data-[size=xs]/attachment:[&_svg:not([class*='size-'])]:size-3.5",
50
+ {
51
+ variants: {
52
+ variant: {
53
+ icon: "",
54
+ image:
55
+ "opacity-60 group-data-[state=done]/attachment:opacity-100 group-data-[state=idle]/attachment:opacity-100 *:[img]:aspect-square *:[img]:w-full *:[img]:object-cover",
56
+ },
57
+ },
58
+ defaultVariants: {
59
+ variant: "icon",
60
+ },
61
+ },
62
+ );
63
+
64
+ function AttachmentMedia({
65
+ className,
66
+ variant = "icon",
67
+ ...props
68
+ }: React.ComponentProps<"div"> & VariantProps<typeof attachmentMediaVariants>) {
69
+ return (
70
+ <div
71
+ data-slot="attachment-media"
72
+ data-variant={variant}
73
+ className={cn(attachmentMediaVariants({ variant }), className)}
74
+ {...props}
75
+ />
76
+ );
77
+ }
78
+
79
+ function AttachmentContent({ className, ...props }: React.ComponentProps<"div">) {
80
+ return (
81
+ <div
82
+ data-slot="attachment-content"
83
+ className={cn(
84
+ "max-w-full min-w-0 flex-1 leading-tight group-data-[orientation=vertical]/attachment:px-1",
85
+ className,
86
+ )}
87
+ {...props}
88
+ />
89
+ );
90
+ }
91
+
92
+ function AttachmentTitle({ className, ...props }: React.ComponentProps<"span">) {
93
+ return (
94
+ <span
95
+ data-slot="attachment-title"
96
+ className={cn(
97
+ "block max-w-full min-w-0 truncate font-medium group-data-[state=processing]/attachment:shimmer group-data-[state=uploading]/attachment:shimmer",
98
+ className,
99
+ )}
100
+ {...props}
101
+ />
102
+ );
103
+ }
104
+
105
+ function AttachmentDescription({ className, ...props }: React.ComponentProps<"span">) {
106
+ return (
107
+ <span
108
+ data-slot="attachment-description"
109
+ className={cn(
110
+ "mt-0.5 block min-w-0 truncate text-xs text-muted-foreground group-data-[state=error]/attachment:text-destructive/80",
111
+ "max-w-full",
112
+ className,
113
+ )}
114
+ {...props}
115
+ />
116
+ );
117
+ }
118
+
119
+ function AttachmentActions({ className, ...props }: React.ComponentProps<"div">) {
120
+ return (
121
+ <div
122
+ data-slot="attachment-actions"
123
+ className={cn(
124
+ "relative z-20 flex shrink-0 items-center group-data-[orientation=vertical]/attachment:absolute group-data-[orientation=vertical]/attachment:top-3 group-data-[orientation=vertical]/attachment:right-3 group-data-[orientation=vertical]/attachment:gap-1",
125
+ className,
126
+ )}
127
+ {...props}
128
+ />
129
+ );
130
+ }
131
+
132
+ function AttachmentAction({
133
+ className,
134
+ variant,
135
+ size = "icon-xs",
136
+ ...props
137
+ }: React.ComponentProps<typeof Button>) {
138
+ return (
139
+ <Button
140
+ data-slot="attachment-action"
141
+ variant={variant ?? "ghost"}
142
+ size={size}
143
+ className={cn(className)}
144
+ {...props}
145
+ />
146
+ );
147
+ }
148
+
149
+ function AttachmentTrigger({
150
+ className,
151
+ asChild = false,
152
+ type,
153
+ ...props
154
+ }: React.ComponentProps<"button"> & {
155
+ asChild?: boolean;
156
+ }) {
157
+ const Comp = asChild ? Slot.Root : "button";
158
+
159
+ return (
160
+ <Comp
161
+ data-slot="attachment-trigger"
162
+ type={asChild ? undefined : (type ?? "button")}
163
+ className={cn("absolute inset-0 z-10 outline-none", className)}
164
+ {...props}
165
+ />
166
+ );
167
+ }
168
+
169
+ function AttachmentGroup({ className, ...props }: React.ComponentProps<"div">) {
170
+ return (
171
+ <div
172
+ data-slot="attachment-group"
173
+ className={cn(
174
+ "flex min-w-0 scroll-fade-x snap-x snap-mandatory scroll-px-1 scrollbar-none gap-3 overflow-x-auto overscroll-x-contain py-1 *:data-[slot=attachment]:flex-none *:data-[slot=attachment]:snap-start",
175
+ className,
176
+ )}
177
+ {...props}
178
+ />
179
+ );
180
+ }
181
+
182
+ export {
183
+ Attachment,
184
+ AttachmentGroup,
185
+ AttachmentMedia,
186
+ AttachmentContent,
187
+ AttachmentTitle,
188
+ AttachmentDescription,
189
+ AttachmentActions,
190
+ AttachmentAction,
191
+ AttachmentTrigger,
192
+ };