@codefast/ui 0.5.0-canary.1 → 0.5.0-canary.3
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 +39 -0
- package/dist/components/attachment.d.mts +136 -0
- package/dist/components/attachment.mjs +112 -0
- package/dist/components/avatar.mjs +1 -1
- package/dist/components/bubble.d.mts +67 -0
- package/dist/components/bubble.mjs +58 -0
- package/dist/components/card.mjs +2 -2
- package/dist/components/carousel.mjs +12 -3
- package/dist/components/chart.mjs +2 -1
- package/dist/components/empty.mjs +1 -1
- package/dist/components/form.mjs +2 -1
- package/dist/components/marker.d.mts +49 -0
- package/dist/components/marker.mjs +42 -0
- package/dist/components/message-scroller.d.mts +89 -0
- package/dist/components/message-scroller.mjs +77 -0
- package/dist/components/message.d.mts +86 -0
- package/dist/components/message.mjs +66 -0
- package/dist/components/sidebar.mjs +6 -3
- package/dist/hooks/use-animated-value.mjs +3 -1
- package/dist/hooks/use-message-scroller-commands.d.mts +39 -0
- package/dist/hooks/use-message-scroller-commands.mjs +165 -0
- package/dist/hooks/use-message-scroller-controller.d.mts +19 -0
- package/dist/hooks/use-message-scroller-controller.mjs +382 -0
- package/dist/hooks/use-message-scroller-refs.d.mts +60 -0
- package/dist/hooks/use-message-scroller-refs.mjs +77 -0
- package/dist/hooks/use-pagination.mjs +18 -12
- package/dist/index.d.mts +11 -1
- package/dist/index.mjs +11 -2
- package/dist/lib/message-scroller/geometry.d.mts +136 -0
- package/dist/lib/message-scroller/geometry.mjs +199 -0
- package/dist/lib/message-scroller/stores.d.mts +21 -0
- package/dist/lib/message-scroller/stores.mjs +52 -0
- package/dist/lib/message-scroller/types.d.mts +171 -0
- package/dist/lib/message-scroller/types.mjs +53 -0
- package/dist/lib/message-scroller/utils.d.mts +7 -0
- package/dist/lib/message-scroller/utils.mjs +12 -0
- package/dist/lib/use-render.d.mts +43 -0
- package/dist/lib/use-render.mjs +84 -0
- package/dist/primitives/checkbox-group.mjs +20 -10
- package/dist/primitives/message-scroller.d.mts +88 -0
- package/dist/primitives/message-scroller.mjs +240 -0
- package/dist/variants/attachment.d.mts +42 -0
- package/dist/variants/attachment.mjs +42 -0
- package/dist/variants/bubble.d.mts +45 -0
- package/dist/variants/bubble.mjs +45 -0
- package/dist/variants/marker.d.mts +21 -0
- package/dist/variants/marker.mjs +18 -0
- package/package.json +57 -11
- package/src/components/attachment.tsx +284 -0
- package/src/components/avatar.tsx +1 -1
- package/src/components/bubble.tsx +116 -0
- package/src/components/card.tsx +2 -2
- package/src/components/carousel.tsx +12 -3
- package/src/components/empty.tsx +1 -1
- package/src/components/marker.tsx +94 -0
- package/src/components/message-scroller.tsx +213 -0
- package/src/components/message.tsx +173 -0
- package/src/components/sidebar.tsx +11 -4
- package/src/css/foundation/tokens.css +6 -18
- package/src/css/foundation/utilities.css +451 -0
- package/src/css/preset.css +2 -1
- package/src/hooks/use-message-scroller-commands.ts +312 -0
- package/src/hooks/use-message-scroller-controller.ts +651 -0
- package/src/hooks/use-message-scroller-refs.ts +168 -0
- package/src/index.ts +72 -0
- package/src/lib/message-scroller/geometry.ts +398 -0
- package/src/lib/message-scroller/stores.ts +89 -0
- package/src/lib/message-scroller/types.ts +310 -0
- package/src/lib/message-scroller/utils.ts +15 -0
- package/src/lib/use-render.ts +202 -0
- package/src/primitives/message-scroller.tsx +399 -0
- package/src/variants/attachment.ts +73 -0
- package/src/variants/bubble.ts +81 -0
- package/src/variants/marker.ts +38 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Slot } from "radix-ui";
|
|
2
|
+
import type { ComponentProps, JSX } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "#/lib/utils";
|
|
5
|
+
import type { BubbleReactionsVariants, BubbleVariants } from "#/variants/bubble";
|
|
6
|
+
import { bubbleReactionsVariants, bubbleVariants } from "#/variants/bubble";
|
|
7
|
+
|
|
8
|
+
/* -----------------------------------------------------------------------------
|
|
9
|
+
* Component: BubbleGroup
|
|
10
|
+
* -------------------------------------------------------------------------- */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Vertical stack of consecutive bubbles from one author.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.5.0-canary.3
|
|
16
|
+
*/
|
|
17
|
+
type BubbleGroupProps = ComponentProps<"div">;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @since 0.5.0-canary.3
|
|
21
|
+
*/
|
|
22
|
+
function BubbleGroup({ className, ...props }: BubbleGroupProps): JSX.Element {
|
|
23
|
+
return <div className={cn("flex min-w-0 flex-col gap-2", className)} data-slot="bubble-group" {...props} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* -----------------------------------------------------------------------------
|
|
27
|
+
* Component: Bubble
|
|
28
|
+
* -------------------------------------------------------------------------- */
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Chat bubble wrapper. `variant` colors the content; `align` sets the side.
|
|
32
|
+
*
|
|
33
|
+
* @since 0.5.0-canary.3
|
|
34
|
+
*/
|
|
35
|
+
interface BubbleProps extends ComponentProps<"div">, BubbleVariants {
|
|
36
|
+
align?: "start" | "end";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @since 0.5.0-canary.3
|
|
41
|
+
*/
|
|
42
|
+
function Bubble({ align = "start", className, variant = "default", ...props }: BubbleProps): JSX.Element {
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
className={bubbleVariants({ className, variant })}
|
|
46
|
+
data-align={align}
|
|
47
|
+
data-slot="bubble"
|
|
48
|
+
data-variant={variant}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* -----------------------------------------------------------------------------
|
|
55
|
+
* Component: BubbleContent
|
|
56
|
+
* -------------------------------------------------------------------------- */
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The bubble's colored surface; render as a button/link with `asChild`.
|
|
60
|
+
*
|
|
61
|
+
* @since 0.5.0-canary.3
|
|
62
|
+
*/
|
|
63
|
+
interface BubbleContentProps extends ComponentProps<"div"> {
|
|
64
|
+
asChild?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @since 0.5.0-canary.3
|
|
69
|
+
*/
|
|
70
|
+
function BubbleContent({ asChild = false, className, ...props }: BubbleContentProps): JSX.Element {
|
|
71
|
+
const Component = asChild ? Slot.Root : "div";
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Component
|
|
75
|
+
className={cn(
|
|
76
|
+
"w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-start [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50",
|
|
77
|
+
className,
|
|
78
|
+
)}
|
|
79
|
+
data-slot="bubble-content"
|
|
80
|
+
{...props}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* -----------------------------------------------------------------------------
|
|
86
|
+
* Component: BubbleReactions
|
|
87
|
+
* -------------------------------------------------------------------------- */
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Reaction pill overlapping a bubble corner.
|
|
91
|
+
*
|
|
92
|
+
* @since 0.5.0-canary.3
|
|
93
|
+
*/
|
|
94
|
+
interface BubbleReactionsProps extends ComponentProps<"div">, BubbleReactionsVariants {}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @since 0.5.0-canary.3
|
|
98
|
+
*/
|
|
99
|
+
function BubbleReactions({ align = "end", className, side = "bottom", ...props }: BubbleReactionsProps): JSX.Element {
|
|
100
|
+
return (
|
|
101
|
+
<div
|
|
102
|
+
className={bubbleReactionsVariants({ align, className, side })}
|
|
103
|
+
data-align={align}
|
|
104
|
+
data-side={side}
|
|
105
|
+
data-slot="bubble-reactions"
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* -----------------------------------------------------------------------------
|
|
112
|
+
* Exports
|
|
113
|
+
* -------------------------------------------------------------------------- */
|
|
114
|
+
|
|
115
|
+
export { Bubble, BubbleContent, BubbleGroup, BubbleReactions };
|
|
116
|
+
export type { BubbleContentProps, BubbleGroupProps, BubbleProps, BubbleReactionsProps };
|
package/src/components/card.tsx
CHANGED
|
@@ -20,7 +20,7 @@ function Card({ className, size = "default", ...props }: CardProps): JSX.Element
|
|
|
20
20
|
return (
|
|
21
21
|
<div
|
|
22
22
|
className={cn(
|
|
23
|
-
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground shadow-xs ring-1 ring-foreground/10 [--card-spacing:--spacing(6)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
|
|
23
|
+
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground shadow-xs ring-1 ring-foreground/10 [--card-spacing:--spacing(6)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
|
|
24
24
|
className,
|
|
25
25
|
)}
|
|
26
26
|
data-size={size}
|
|
@@ -124,7 +124,7 @@ type CardFooterProps = ComponentProps<"div">;
|
|
|
124
124
|
function CardFooter({ className, ...props }: CardFooterProps): JSX.Element {
|
|
125
125
|
return (
|
|
126
126
|
<div
|
|
127
|
-
className={cn("flex items-center rounded-b-xl
|
|
127
|
+
className={cn("flex items-center rounded-b-xl border-t bg-muted/50 p-(--card-spacing)", className)}
|
|
128
128
|
data-slot="card-footer"
|
|
129
129
|
{...props}
|
|
130
130
|
/>
|
|
@@ -6,6 +6,7 @@ import type { ComponentProps, JSX, KeyboardEvent } from "react";
|
|
|
6
6
|
import { useCallback, useEffect, useState } from "react";
|
|
7
7
|
|
|
8
8
|
import { Button } from "#/components/button";
|
|
9
|
+
import { useDirection } from "#/components/direction";
|
|
9
10
|
import { cn } from "#/lib/utils";
|
|
10
11
|
|
|
11
12
|
/* -----------------------------------------------------------------------------
|
|
@@ -66,8 +67,12 @@ function Carousel({
|
|
|
66
67
|
setApi,
|
|
67
68
|
...props
|
|
68
69
|
}: ScopedProps<CarouselProps>): JSX.Element {
|
|
70
|
+
const direction = useDirection();
|
|
71
|
+
|
|
69
72
|
const [carouselRef, api] = useEmblaCarousel(
|
|
70
73
|
{
|
|
74
|
+
// Mirror Embla's drag/snap physics under RTL; explicit opts.direction wins.
|
|
75
|
+
direction,
|
|
71
76
|
...opts,
|
|
72
77
|
axis: orientation === "vertical" ? "y" : "x",
|
|
73
78
|
},
|
|
@@ -96,15 +101,19 @@ function Carousel({
|
|
|
96
101
|
|
|
97
102
|
const handleKeyDown = useCallback(
|
|
98
103
|
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
99
|
-
|
|
104
|
+
// Arrow keys follow reading direction: in RTL the left key advances.
|
|
105
|
+
const previousKey = direction === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
106
|
+
const nextKey = direction === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
107
|
+
|
|
108
|
+
if (event.key === previousKey) {
|
|
100
109
|
event.preventDefault();
|
|
101
110
|
scrollPrevious();
|
|
102
|
-
} else if (event.key ===
|
|
111
|
+
} else if (event.key === nextKey) {
|
|
103
112
|
event.preventDefault();
|
|
104
113
|
scrollNext();
|
|
105
114
|
}
|
|
106
115
|
},
|
|
107
|
-
[scrollPrevious, scrollNext],
|
|
116
|
+
[direction, scrollPrevious, scrollNext],
|
|
108
117
|
);
|
|
109
118
|
|
|
110
119
|
useEffect(() => {
|
package/src/components/empty.tsx
CHANGED
|
@@ -20,7 +20,7 @@ function Empty({ className, ...props }: EmptyProps): JSX.Element {
|
|
|
20
20
|
return (
|
|
21
21
|
<div
|
|
22
22
|
className={cn(
|
|
23
|
-
"flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-
|
|
23
|
+
"flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-xl border-dashed p-12 text-center text-balance",
|
|
24
24
|
className,
|
|
25
25
|
)}
|
|
26
26
|
data-slot="empty"
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Slot } from "radix-ui";
|
|
2
|
+
import type { ComponentProps, JSX } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "#/lib/utils";
|
|
5
|
+
import type { MarkerVariants } from "#/variants/marker";
|
|
6
|
+
import { markerVariants } from "#/variants/marker";
|
|
7
|
+
|
|
8
|
+
/* -----------------------------------------------------------------------------
|
|
9
|
+
* Component: Marker
|
|
10
|
+
* -------------------------------------------------------------------------- */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inline divider for a message feed — a date, unread line, or section label.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.5.0-canary.3
|
|
16
|
+
*/
|
|
17
|
+
interface MarkerProps extends ComponentProps<"div">, MarkerVariants {
|
|
18
|
+
asChild?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @since 0.5.0-canary.3
|
|
23
|
+
*/
|
|
24
|
+
function Marker({ asChild = false, className, variant = "default", ...props }: MarkerProps): JSX.Element {
|
|
25
|
+
const Component = asChild ? Slot.Root : "div";
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Component
|
|
29
|
+
className={markerVariants({ className, variant })}
|
|
30
|
+
data-slot="marker"
|
|
31
|
+
data-variant={variant}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* -----------------------------------------------------------------------------
|
|
38
|
+
* Component: MarkerIcon
|
|
39
|
+
* -------------------------------------------------------------------------- */
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Decorative leading icon for a marker.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.5.0-canary.3
|
|
45
|
+
*/
|
|
46
|
+
type MarkerIconProps = ComponentProps<"span">;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @since 0.5.0-canary.3
|
|
50
|
+
*/
|
|
51
|
+
function MarkerIcon({ className, ...props }: MarkerIconProps): JSX.Element {
|
|
52
|
+
return (
|
|
53
|
+
<span
|
|
54
|
+
aria-hidden="true"
|
|
55
|
+
className={cn("size-4 shrink-0 [&_svg:not([class*='size-'])]:size-4", className)}
|
|
56
|
+
data-slot="marker-icon"
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* -----------------------------------------------------------------------------
|
|
63
|
+
* Component: MarkerContent
|
|
64
|
+
* -------------------------------------------------------------------------- */
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Marker label; centers between the rules in the `separator` variant.
|
|
68
|
+
*
|
|
69
|
+
* @since 0.5.0-canary.3
|
|
70
|
+
*/
|
|
71
|
+
type MarkerContentProps = ComponentProps<"span">;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @since 0.5.0-canary.3
|
|
75
|
+
*/
|
|
76
|
+
function MarkerContent({ className, ...props }: MarkerContentProps): JSX.Element {
|
|
77
|
+
return (
|
|
78
|
+
<span
|
|
79
|
+
className={cn(
|
|
80
|
+
"min-w-0 wrap-break-word group-data-[variant=separator]/marker:flex-none group-data-[variant=separator]/marker:text-center *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
|
|
81
|
+
className,
|
|
82
|
+
)}
|
|
83
|
+
data-slot="marker-content"
|
|
84
|
+
{...props}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* -----------------------------------------------------------------------------
|
|
90
|
+
* Exports
|
|
91
|
+
* -------------------------------------------------------------------------- */
|
|
92
|
+
|
|
93
|
+
export { Marker, MarkerContent, MarkerIcon };
|
|
94
|
+
export type { MarkerContentProps, MarkerIconProps, MarkerProps };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { ArrowDownIcon } from "lucide-react";
|
|
2
|
+
import type { ComponentProps, JSX } from "react";
|
|
3
|
+
|
|
4
|
+
import { Button } from "#/components/button";
|
|
5
|
+
import { cn } from "#/lib/utils";
|
|
6
|
+
import {
|
|
7
|
+
MessageScroller as MessageScrollerPrimitive,
|
|
8
|
+
MessageScrollerButton as MessageScrollerButtonPrimitive,
|
|
9
|
+
MessageScrollerContent as MessageScrollerContentPrimitive,
|
|
10
|
+
MessageScrollerItem as MessageScrollerItemPrimitive,
|
|
11
|
+
MessageScrollerProvider as MessageScrollerProviderPrimitive,
|
|
12
|
+
MessageScrollerViewport as MessageScrollerViewportPrimitive,
|
|
13
|
+
useMessageScroller,
|
|
14
|
+
useMessageScrollerScrollable,
|
|
15
|
+
useMessageScrollerVisibility,
|
|
16
|
+
} from "#/primitives/message-scroller";
|
|
17
|
+
|
|
18
|
+
/* -----------------------------------------------------------------------------
|
|
19
|
+
* Component: MessageScrollerProvider
|
|
20
|
+
* -------------------------------------------------------------------------- */
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Owns scroll behavior for a transcript. Renders no DOM; wrap the frame.
|
|
24
|
+
*
|
|
25
|
+
* @since 0.5.0-canary.3
|
|
26
|
+
*/
|
|
27
|
+
type MessageScrollerProviderProps = ComponentProps<typeof MessageScrollerProviderPrimitive>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @since 0.5.0-canary.3
|
|
31
|
+
*/
|
|
32
|
+
function MessageScrollerProvider(props: MessageScrollerProviderProps): JSX.Element {
|
|
33
|
+
return <MessageScrollerProviderPrimitive {...props} />;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* -----------------------------------------------------------------------------
|
|
37
|
+
* Component: MessageScroller
|
|
38
|
+
* -------------------------------------------------------------------------- */
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Frame for a chat transcript scroller; must sit inside a provider.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.5.0-canary.3
|
|
44
|
+
*/
|
|
45
|
+
type MessageScrollerProps = ComponentProps<typeof MessageScrollerPrimitive>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @since 0.5.0-canary.3
|
|
49
|
+
*/
|
|
50
|
+
function MessageScroller({ className, ...props }: MessageScrollerProps): JSX.Element {
|
|
51
|
+
return (
|
|
52
|
+
<MessageScrollerPrimitive
|
|
53
|
+
className={cn("group/message-scroller relative flex size-full min-h-0 flex-col overflow-hidden", className)}
|
|
54
|
+
data-slot="message-scroller"
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* -----------------------------------------------------------------------------
|
|
61
|
+
* Component: MessageScrollerViewport
|
|
62
|
+
* -------------------------------------------------------------------------- */
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Scrollable viewport; fades its bottom edge and hides the bar while autoscrolling.
|
|
66
|
+
*
|
|
67
|
+
* @since 0.5.0-canary.3
|
|
68
|
+
*/
|
|
69
|
+
type MessageScrollerViewportProps = ComponentProps<typeof MessageScrollerViewportPrimitive>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @since 0.5.0-canary.3
|
|
73
|
+
*/
|
|
74
|
+
function MessageScrollerViewport({ className, ...props }: MessageScrollerViewportProps): JSX.Element {
|
|
75
|
+
return (
|
|
76
|
+
<MessageScrollerViewportPrimitive
|
|
77
|
+
className={cn(
|
|
78
|
+
"size-full min-h-0 min-w-0 scroll-fade-b scrollbar-thin scrollbar-gutter-stable overflow-y-auto overscroll-contain contain-content data-autoscrolling:scrollbar-thumb-transparent data-autoscrolling:scrollbar-track-transparent",
|
|
79
|
+
className,
|
|
80
|
+
)}
|
|
81
|
+
data-slot="message-scroller-viewport"
|
|
82
|
+
{...props}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* -----------------------------------------------------------------------------
|
|
88
|
+
* Component: MessageScrollerContent
|
|
89
|
+
* -------------------------------------------------------------------------- */
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Column holding the transcript rows.
|
|
93
|
+
*
|
|
94
|
+
* @since 0.5.0-canary.3
|
|
95
|
+
*/
|
|
96
|
+
type MessageScrollerContentProps = ComponentProps<typeof MessageScrollerContentPrimitive>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @since 0.5.0-canary.3
|
|
100
|
+
*/
|
|
101
|
+
function MessageScrollerContent({ className, ...props }: MessageScrollerContentProps): JSX.Element {
|
|
102
|
+
return (
|
|
103
|
+
<MessageScrollerContentPrimitive
|
|
104
|
+
className={cn("flex h-max min-h-full flex-col gap-6", className)}
|
|
105
|
+
data-slot="message-scroller-content"
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* -----------------------------------------------------------------------------
|
|
112
|
+
* Component: MessageScrollerItem
|
|
113
|
+
* -------------------------------------------------------------------------- */
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* One transcript row; opts into content-visibility for long feeds.
|
|
117
|
+
*
|
|
118
|
+
* @since 0.5.0-canary.3
|
|
119
|
+
*/
|
|
120
|
+
type MessageScrollerItemProps = ComponentProps<typeof MessageScrollerItemPrimitive>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @since 0.5.0-canary.3
|
|
124
|
+
*/
|
|
125
|
+
function MessageScrollerItem({ className, scrollAnchor = false, ...props }: MessageScrollerItemProps): JSX.Element {
|
|
126
|
+
return (
|
|
127
|
+
<MessageScrollerItemPrimitive
|
|
128
|
+
className={cn("min-w-0 shrink-0 [contain-intrinsic-size:auto_10rem] [content-visibility:auto]", className)}
|
|
129
|
+
data-slot="message-scroller-item"
|
|
130
|
+
scrollAnchor={scrollAnchor}
|
|
131
|
+
{...props}
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* -----------------------------------------------------------------------------
|
|
137
|
+
* Component: MessageScrollerButton
|
|
138
|
+
* -------------------------------------------------------------------------- */
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Scroll-to-edge control; hides itself when there is no overflow that way.
|
|
142
|
+
*
|
|
143
|
+
* @since 0.5.0-canary.3
|
|
144
|
+
*/
|
|
145
|
+
type MessageScrollerButtonProps = ComponentProps<typeof MessageScrollerButtonPrimitive> &
|
|
146
|
+
Pick<ComponentProps<typeof Button>, "size" | "variant">;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @since 0.5.0-canary.3
|
|
150
|
+
*/
|
|
151
|
+
function MessageScrollerButton({
|
|
152
|
+
children,
|
|
153
|
+
className,
|
|
154
|
+
direction = "end",
|
|
155
|
+
render,
|
|
156
|
+
size = "icon-sm",
|
|
157
|
+
variant = "secondary",
|
|
158
|
+
...props
|
|
159
|
+
}: MessageScrollerButtonProps): JSX.Element {
|
|
160
|
+
return (
|
|
161
|
+
<MessageScrollerButtonPrimitive
|
|
162
|
+
className={cn(
|
|
163
|
+
"absolute inset-s-1/2 -translate-x-1/2 border-border bg-background text-foreground transition-[translate,scale,opacity] duration-200 hover:bg-muted hover:text-foreground data-[active=false]:pointer-events-none data-[active=false]:scale-95 data-[active=false]:opacity-0 data-[active=false]:duration-400 data-[active=false]:ease-[cubic-bezier(0.7,0,0.84,0)] data-[active=true]:translate-y-0 data-[active=true]:scale-100 data-[active=true]:opacity-100 data-[active=true]:ease-[cubic-bezier(0.23,1,0.32,1)] data-[direction=end]:bottom-4 data-[direction=end]:data-[active=false]:translate-y-full data-[direction=start]:top-4 data-[direction=start]:data-[active=false]:-translate-y-full rtl:translate-x-1/2 data-[direction=start]:[&_svg]:rotate-180",
|
|
164
|
+
className,
|
|
165
|
+
)}
|
|
166
|
+
data-direction={direction}
|
|
167
|
+
data-size={size}
|
|
168
|
+
data-slot="message-scroller-button"
|
|
169
|
+
data-variant={variant}
|
|
170
|
+
direction={direction}
|
|
171
|
+
render={render ?? <Button size={size} variant={variant} />}
|
|
172
|
+
{...props}
|
|
173
|
+
>
|
|
174
|
+
{children ?? (
|
|
175
|
+
<>
|
|
176
|
+
<ArrowDownIcon />
|
|
177
|
+
<span className="sr-only">{direction === "end" ? "Scroll to end" : "Scroll to start"}</span>
|
|
178
|
+
</>
|
|
179
|
+
)}
|
|
180
|
+
</MessageScrollerButtonPrimitive>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* -----------------------------------------------------------------------------
|
|
185
|
+
* Exports
|
|
186
|
+
* -------------------------------------------------------------------------- */
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
MessageScroller,
|
|
190
|
+
MessageScrollerButton,
|
|
191
|
+
MessageScrollerContent,
|
|
192
|
+
MessageScrollerItem,
|
|
193
|
+
MessageScrollerProvider,
|
|
194
|
+
MessageScrollerViewport,
|
|
195
|
+
useMessageScroller,
|
|
196
|
+
useMessageScrollerScrollable,
|
|
197
|
+
useMessageScrollerVisibility,
|
|
198
|
+
};
|
|
199
|
+
export type {
|
|
200
|
+
MessageScrollerButtonProps,
|
|
201
|
+
MessageScrollerContentProps,
|
|
202
|
+
MessageScrollerItemProps,
|
|
203
|
+
MessageScrollerProps,
|
|
204
|
+
MessageScrollerProviderProps,
|
|
205
|
+
MessageScrollerViewportProps,
|
|
206
|
+
};
|
|
207
|
+
export type {
|
|
208
|
+
MessageScrollerDefaultScrollPosition,
|
|
209
|
+
MessageScrollerScrollAlign,
|
|
210
|
+
MessageScrollerScrollable,
|
|
211
|
+
MessageScrollerScrollOptions,
|
|
212
|
+
MessageScrollerVisibilityState,
|
|
213
|
+
} from "#/lib/message-scroller/types";
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { ComponentProps, JSX } from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "#/lib/utils";
|
|
4
|
+
|
|
5
|
+
/* -----------------------------------------------------------------------------
|
|
6
|
+
* Component: MessageGroup
|
|
7
|
+
* -------------------------------------------------------------------------- */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Vertical stack of related messages.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.5.0-canary.3
|
|
13
|
+
*/
|
|
14
|
+
type MessageGroupProps = ComponentProps<"div">;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.5.0-canary.3
|
|
18
|
+
*/
|
|
19
|
+
function MessageGroup({ className, ...props }: MessageGroupProps): JSX.Element {
|
|
20
|
+
return <div className={cn("flex min-w-0 flex-col gap-2", className)} data-slot="message-group" {...props} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* -----------------------------------------------------------------------------
|
|
24
|
+
* Component: Message
|
|
25
|
+
* -------------------------------------------------------------------------- */
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A single message row. `align="end"` mirrors the row for the current author.
|
|
29
|
+
*
|
|
30
|
+
* @since 0.5.0-canary.3
|
|
31
|
+
*/
|
|
32
|
+
interface MessageProps extends ComponentProps<"div"> {
|
|
33
|
+
align?: "start" | "end";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @since 0.5.0-canary.3
|
|
38
|
+
*/
|
|
39
|
+
function Message({ align = "start", className, ...props }: MessageProps): JSX.Element {
|
|
40
|
+
return (
|
|
41
|
+
<div
|
|
42
|
+
className={cn(
|
|
43
|
+
"group/message relative flex w-full min-w-0 gap-2 text-sm data-[align=end]:flex-row-reverse",
|
|
44
|
+
className,
|
|
45
|
+
)}
|
|
46
|
+
data-align={align}
|
|
47
|
+
data-slot="message"
|
|
48
|
+
{...props}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* -----------------------------------------------------------------------------
|
|
54
|
+
* Component: MessageAvatar
|
|
55
|
+
* -------------------------------------------------------------------------- */
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Author avatar; lifts above the footer when a message footer is present.
|
|
59
|
+
*
|
|
60
|
+
* @since 0.5.0-canary.3
|
|
61
|
+
*/
|
|
62
|
+
type MessageAvatarProps = ComponentProps<"div">;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @since 0.5.0-canary.3
|
|
66
|
+
*/
|
|
67
|
+
function MessageAvatar({ className, ...props }: MessageAvatarProps): JSX.Element {
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
className={cn(
|
|
71
|
+
"flex w-fit min-w-8 shrink-0 items-center justify-center self-end overflow-hidden rounded-full bg-muted group-has-data-[slot=message-footer]/message:-translate-y-8",
|
|
72
|
+
className,
|
|
73
|
+
)}
|
|
74
|
+
data-slot="message-avatar"
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* -----------------------------------------------------------------------------
|
|
81
|
+
* Component: MessageContent
|
|
82
|
+
* -------------------------------------------------------------------------- */
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Column holding the message bubbles and metadata.
|
|
86
|
+
*
|
|
87
|
+
* @since 0.5.0-canary.3
|
|
88
|
+
*/
|
|
89
|
+
type MessageContentProps = ComponentProps<"div">;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @since 0.5.0-canary.3
|
|
93
|
+
*/
|
|
94
|
+
function MessageContent({ className, ...props }: MessageContentProps): JSX.Element {
|
|
95
|
+
return (
|
|
96
|
+
<div
|
|
97
|
+
className={cn(
|
|
98
|
+
"flex w-full min-w-0 flex-col gap-2.5 wrap-break-word group-data-[align=end]/message:*:data-slot:self-end",
|
|
99
|
+
className,
|
|
100
|
+
)}
|
|
101
|
+
data-slot="message-content"
|
|
102
|
+
{...props}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* -----------------------------------------------------------------------------
|
|
108
|
+
* Component: MessageHeader
|
|
109
|
+
* -------------------------------------------------------------------------- */
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Metadata above the bubbles (author, timestamp).
|
|
113
|
+
*
|
|
114
|
+
* @since 0.5.0-canary.3
|
|
115
|
+
*/
|
|
116
|
+
type MessageHeaderProps = ComponentProps<"div">;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @since 0.5.0-canary.3
|
|
120
|
+
*/
|
|
121
|
+
function MessageHeader({ className, ...props }: MessageHeaderProps): JSX.Element {
|
|
122
|
+
return (
|
|
123
|
+
<div
|
|
124
|
+
className={cn(
|
|
125
|
+
"flex max-w-full min-w-0 items-center px-3 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0",
|
|
126
|
+
className,
|
|
127
|
+
)}
|
|
128
|
+
data-slot="message-header"
|
|
129
|
+
{...props}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* -----------------------------------------------------------------------------
|
|
135
|
+
* Component: MessageFooter
|
|
136
|
+
* -------------------------------------------------------------------------- */
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Metadata below the bubbles (status, reactions); aligns with the row.
|
|
140
|
+
*
|
|
141
|
+
* @since 0.5.0-canary.3
|
|
142
|
+
*/
|
|
143
|
+
type MessageFooterProps = ComponentProps<"div">;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @since 0.5.0-canary.3
|
|
147
|
+
*/
|
|
148
|
+
function MessageFooter({ className, ...props }: MessageFooterProps): JSX.Element {
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
className={cn(
|
|
152
|
+
"flex max-w-full min-w-0 items-center px-3 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0 group-data-[align=end]/message:justify-end",
|
|
153
|
+
className,
|
|
154
|
+
)}
|
|
155
|
+
data-slot="message-footer"
|
|
156
|
+
{...props}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* -----------------------------------------------------------------------------
|
|
162
|
+
* Exports
|
|
163
|
+
* -------------------------------------------------------------------------- */
|
|
164
|
+
|
|
165
|
+
export { Message, MessageAvatar, MessageContent, MessageFooter, MessageGroup, MessageHeader };
|
|
166
|
+
export type {
|
|
167
|
+
MessageAvatarProps,
|
|
168
|
+
MessageContentProps,
|
|
169
|
+
MessageFooterProps,
|
|
170
|
+
MessageGroupProps,
|
|
171
|
+
MessageHeaderProps,
|
|
172
|
+
MessageProps,
|
|
173
|
+
};
|