@codefast/ui 0.5.0-canary.2 → 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 +32 -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/empty.mjs +1 -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-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/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/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 +52 -6
- 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,399 @@
|
|
|
1
|
+
// Vendored from shadcn-ui/ui packages/react/src/message-scroller/components.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useSyncExternalStore,
|
|
11
|
+
} from "react";
|
|
12
|
+
import type { KeyboardEvent, MouseEvent, TouchEvent, UIEvent, WheelEvent } from "react";
|
|
13
|
+
|
|
14
|
+
import { useMessageScrollerController } from "#/hooks/use-message-scroller-controller";
|
|
15
|
+
import { USER_SCROLL_KEYS } from "#/lib/message-scroller/types";
|
|
16
|
+
import type {
|
|
17
|
+
MessageScrollerButtonProps,
|
|
18
|
+
MessageScrollerContentProps,
|
|
19
|
+
MessageScrollerContextValue,
|
|
20
|
+
MessageScrollerItemProps,
|
|
21
|
+
MessageScrollerProps,
|
|
22
|
+
MessageScrollerProviderProps,
|
|
23
|
+
MessageScrollerRegisterMessage,
|
|
24
|
+
MessageScrollerViewportProps,
|
|
25
|
+
} from "#/lib/message-scroller/types";
|
|
26
|
+
import { useLatest } from "#/lib/message-scroller/utils";
|
|
27
|
+
import { composeRefs, mergeProps, useRender } from "#/lib/use-render";
|
|
28
|
+
|
|
29
|
+
const MessageScrollerContext = createContext<MessageScrollerContextValue | null>(null);
|
|
30
|
+
const MessageScrollerItemContext = createContext<MessageScrollerRegisterMessage | null>(null);
|
|
31
|
+
|
|
32
|
+
function useMessageScrollerContext() {
|
|
33
|
+
const context = useContext(MessageScrollerContext);
|
|
34
|
+
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("useMessageScroller must be used within a MessageScroller.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return context;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function useMessageScrollerItemContext() {
|
|
43
|
+
const context = useContext(MessageScrollerItemContext);
|
|
44
|
+
|
|
45
|
+
if (!context) {
|
|
46
|
+
throw new Error("MessageScrollerItem must be used within a MessageScroller.");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return context;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @since 0.5.0-canary.3
|
|
54
|
+
*/
|
|
55
|
+
function useMessageScroller() {
|
|
56
|
+
const { scrollToEnd, scrollToMessage, scrollToStart } = useMessageScrollerContext();
|
|
57
|
+
|
|
58
|
+
return useMemo(
|
|
59
|
+
() => ({
|
|
60
|
+
scrollToEnd,
|
|
61
|
+
scrollToMessage,
|
|
62
|
+
scrollToStart,
|
|
63
|
+
}),
|
|
64
|
+
[scrollToEnd, scrollToMessage, scrollToStart],
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @since 0.5.0-canary.3
|
|
70
|
+
*/
|
|
71
|
+
function useMessageScrollerScrollable() {
|
|
72
|
+
const { stateStore } = useMessageScrollerContext();
|
|
73
|
+
|
|
74
|
+
return useSyncExternalStore(stateStore.subscribe, stateStore.getSnapshot, stateStore.getSnapshot);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @since 0.5.0-canary.3
|
|
79
|
+
*/
|
|
80
|
+
function useMessageScrollerVisibility() {
|
|
81
|
+
const { observeVisibility, unobserveVisibility, visibilityStore } = useMessageScrollerContext();
|
|
82
|
+
const subscribe = useCallback(
|
|
83
|
+
(listener: () => void) => visibilityStore.subscribe(listener, observeVisibility, unobserveVisibility),
|
|
84
|
+
[observeVisibility, unobserveVisibility, visibilityStore],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return useSyncExternalStore(subscribe, visibilityStore.getSnapshot, visibilityStore.getSnapshot);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @since 0.5.0-canary.3
|
|
92
|
+
*/
|
|
93
|
+
function MessageScrollerProvider({
|
|
94
|
+
autoScroll = false,
|
|
95
|
+
children,
|
|
96
|
+
defaultScrollPosition = "end",
|
|
97
|
+
scrollEdgeThreshold,
|
|
98
|
+
scrollPreviousItemPeek,
|
|
99
|
+
scrollMargin,
|
|
100
|
+
}: MessageScrollerProviderProps) {
|
|
101
|
+
const { context, registerMessage } = useMessageScrollerController({
|
|
102
|
+
autoScroll,
|
|
103
|
+
defaultScrollPosition,
|
|
104
|
+
scrollEdgeThreshold,
|
|
105
|
+
scrollPreviousItemPeek,
|
|
106
|
+
scrollMargin,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<MessageScrollerContext.Provider value={context}>
|
|
111
|
+
<MessageScrollerItemContext.Provider value={registerMessage}>{children}</MessageScrollerItemContext.Provider>
|
|
112
|
+
</MessageScrollerContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @since 0.5.0-canary.3
|
|
118
|
+
*/
|
|
119
|
+
function MessageScroller({ children, ...props }: MessageScrollerProps) {
|
|
120
|
+
const { setRootElement } = useMessageScrollerContext();
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<div ref={setRootElement} {...props}>
|
|
124
|
+
{children}
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @since 0.5.0-canary.3
|
|
131
|
+
*/
|
|
132
|
+
function MessageScrollerViewport({
|
|
133
|
+
"aria-label": ariaLabel,
|
|
134
|
+
children,
|
|
135
|
+
onKeyDown,
|
|
136
|
+
onScroll,
|
|
137
|
+
onTouchMove,
|
|
138
|
+
onWheel,
|
|
139
|
+
preserveScrollOnPrepend = true,
|
|
140
|
+
ref,
|
|
141
|
+
role,
|
|
142
|
+
tabIndex,
|
|
143
|
+
...props
|
|
144
|
+
}: MessageScrollerViewportProps) {
|
|
145
|
+
const {
|
|
146
|
+
handleResize,
|
|
147
|
+
preserveScrollOnPrependRef,
|
|
148
|
+
setViewportElement,
|
|
149
|
+
syncAfterScroll,
|
|
150
|
+
userScrollIntent,
|
|
151
|
+
viewportRef,
|
|
152
|
+
} = useMessageScrollerContext();
|
|
153
|
+
|
|
154
|
+
preserveScrollOnPrependRef.current = preserveScrollOnPrepend;
|
|
155
|
+
|
|
156
|
+
const setViewportRef = useCallback(
|
|
157
|
+
(element: HTMLDivElement | null) => {
|
|
158
|
+
setViewportElement(element);
|
|
159
|
+
composeRefs(ref)?.(element);
|
|
160
|
+
},
|
|
161
|
+
[ref, setViewportElement],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
function handleScroll(event: UIEvent<HTMLDivElement>) {
|
|
165
|
+
syncAfterScroll();
|
|
166
|
+
onScroll?.(event);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function handleWheel(event: WheelEvent<HTMLDivElement>) {
|
|
170
|
+
userScrollIntent();
|
|
171
|
+
onWheel?.(event);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function handleTouchMove(event: TouchEvent<HTMLDivElement>) {
|
|
175
|
+
userScrollIntent();
|
|
176
|
+
onTouchMove?.(event);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function handleKeyDown(event: KeyboardEvent<HTMLDivElement>) {
|
|
180
|
+
if (USER_SCROLL_KEYS.has(event.key)) {
|
|
181
|
+
userScrollIntent();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
onKeyDown?.(event);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
const viewport = viewportRef.current;
|
|
189
|
+
|
|
190
|
+
if (!viewport || typeof ResizeObserver === "undefined") {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const observer = new ResizeObserver(handleResize);
|
|
195
|
+
|
|
196
|
+
observer.observe(viewport);
|
|
197
|
+
|
|
198
|
+
return () => observer.disconnect();
|
|
199
|
+
}, [handleResize, viewportRef]);
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
// The viewport defaults to role="region"; the scroll/key handlers back that landmark.
|
|
203
|
+
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- role default is dynamic
|
|
204
|
+
<div
|
|
205
|
+
ref={setViewportRef}
|
|
206
|
+
role={role ?? "region"}
|
|
207
|
+
aria-label={ariaLabel ?? "Messages"}
|
|
208
|
+
tabIndex={tabIndex ?? 0}
|
|
209
|
+
onKeyDown={handleKeyDown}
|
|
210
|
+
onScroll={handleScroll}
|
|
211
|
+
onTouchMove={handleTouchMove}
|
|
212
|
+
onWheel={handleWheel}
|
|
213
|
+
{...props}
|
|
214
|
+
>
|
|
215
|
+
{children}
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @since 0.5.0-canary.3
|
|
222
|
+
*/
|
|
223
|
+
function MessageScrollerContent({
|
|
224
|
+
"aria-relevant": ariaRelevant,
|
|
225
|
+
children,
|
|
226
|
+
ref,
|
|
227
|
+
role,
|
|
228
|
+
spacerClassName,
|
|
229
|
+
...props
|
|
230
|
+
}: MessageScrollerContentProps) {
|
|
231
|
+
const { handleContentChange, handleResize, setContentElement, setSpacerElement } = useMessageScrollerContext();
|
|
232
|
+
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
233
|
+
|
|
234
|
+
const setContentRef = useCallback(
|
|
235
|
+
(element: HTMLDivElement | null) => {
|
|
236
|
+
contentRef.current = element;
|
|
237
|
+
setContentElement(element);
|
|
238
|
+
composeRefs(ref)?.(element);
|
|
239
|
+
},
|
|
240
|
+
[ref, setContentElement],
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
useLayoutEffect(() => {
|
|
244
|
+
const content = contentRef.current;
|
|
245
|
+
|
|
246
|
+
if (!content) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
handleContentChange();
|
|
251
|
+
|
|
252
|
+
if (typeof MutationObserver === "undefined") {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const observer = new MutationObserver(() => {
|
|
257
|
+
handleContentChange();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
observer.observe(content, { childList: true });
|
|
261
|
+
|
|
262
|
+
return () => observer.disconnect();
|
|
263
|
+
}, [handleContentChange]);
|
|
264
|
+
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const content = contentRef.current;
|
|
267
|
+
|
|
268
|
+
if (!content || typeof ResizeObserver === "undefined") {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const observer = new ResizeObserver(handleResize);
|
|
273
|
+
|
|
274
|
+
observer.observe(content);
|
|
275
|
+
|
|
276
|
+
return () => observer.disconnect();
|
|
277
|
+
}, [handleResize]);
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<div ref={setContentRef} role={role ?? "log"} aria-relevant={ariaRelevant ?? "additions"} {...props}>
|
|
281
|
+
{children}
|
|
282
|
+
<div
|
|
283
|
+
ref={setSpacerElement}
|
|
284
|
+
aria-hidden="true"
|
|
285
|
+
data-message-scroller-spacer=""
|
|
286
|
+
hidden
|
|
287
|
+
className={spacerClassName}
|
|
288
|
+
/>
|
|
289
|
+
</div>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @since 0.5.0-canary.3
|
|
295
|
+
*/
|
|
296
|
+
function MessageScrollerItem({ messageId, ref, scrollAnchor = false, ...props }: MessageScrollerItemProps) {
|
|
297
|
+
const registerMessage = useMessageScrollerItemContext();
|
|
298
|
+
const elementRef = useRef<HTMLDivElement | null>(null);
|
|
299
|
+
|
|
300
|
+
const setItemRef = useCallback(
|
|
301
|
+
(element: HTMLDivElement | null) => {
|
|
302
|
+
const previousElement = elementRef.current;
|
|
303
|
+
|
|
304
|
+
elementRef.current = element;
|
|
305
|
+
|
|
306
|
+
if (messageId) {
|
|
307
|
+
registerMessage(messageId, element, previousElement);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
composeRefs(ref)?.(element);
|
|
311
|
+
},
|
|
312
|
+
[messageId, ref, registerMessage],
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<div ref={setItemRef} data-message-id={messageId} data-scroll-anchor={scrollAnchor ? "true" : "false"} {...props} />
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* @since 0.5.0-canary.3
|
|
322
|
+
*/
|
|
323
|
+
function MessageScrollerButton({
|
|
324
|
+
behavior = "smooth",
|
|
325
|
+
children,
|
|
326
|
+
direction = "end",
|
|
327
|
+
onClick,
|
|
328
|
+
render,
|
|
329
|
+
tabIndex,
|
|
330
|
+
type = "button",
|
|
331
|
+
...props
|
|
332
|
+
}: MessageScrollerButtonProps) {
|
|
333
|
+
const { scrollToEnd, scrollToStart, stateStore } = useMessageScrollerContext();
|
|
334
|
+
const onClickRef = useLatest(onClick);
|
|
335
|
+
const subscribe = useCallback((listener: () => void) => stateStore.subscribe(listener), [stateStore]);
|
|
336
|
+
const getSnapshot = useCallback(() => {
|
|
337
|
+
const state = stateStore.getSnapshot();
|
|
338
|
+
|
|
339
|
+
return direction === "start" ? state.start : state.end;
|
|
340
|
+
}, [direction, stateStore]);
|
|
341
|
+
const isActive = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
342
|
+
|
|
343
|
+
const handleClick = useCallback(
|
|
344
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
345
|
+
if (!isActive) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
onClickRef.current?.(event);
|
|
350
|
+
|
|
351
|
+
if (!event.defaultPrevented) {
|
|
352
|
+
event.currentTarget.blur();
|
|
353
|
+
|
|
354
|
+
if (direction === "start") {
|
|
355
|
+
scrollToStart({ behavior });
|
|
356
|
+
} else {
|
|
357
|
+
scrollToEnd({ behavior });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
[behavior, direction, isActive, onClickRef, scrollToEnd, scrollToStart],
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
return useRender({
|
|
365
|
+
defaultTagName: "button",
|
|
366
|
+
props: mergeProps<"button">(
|
|
367
|
+
{
|
|
368
|
+
type,
|
|
369
|
+
inert: !isActive,
|
|
370
|
+
tabIndex: isActive ? tabIndex : -1,
|
|
371
|
+
children: children ?? <span>Scroll to {direction}</span>,
|
|
372
|
+
onClick: handleClick,
|
|
373
|
+
},
|
|
374
|
+
props,
|
|
375
|
+
),
|
|
376
|
+
render,
|
|
377
|
+
state: {
|
|
378
|
+
active: isActive,
|
|
379
|
+
direction,
|
|
380
|
+
},
|
|
381
|
+
stateAttributesMapping: {
|
|
382
|
+
active: (value) => ({
|
|
383
|
+
"data-active": value ? "true" : "false",
|
|
384
|
+
}),
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export {
|
|
390
|
+
MessageScroller,
|
|
391
|
+
MessageScrollerButton,
|
|
392
|
+
MessageScrollerContent,
|
|
393
|
+
MessageScrollerItem,
|
|
394
|
+
MessageScrollerProvider,
|
|
395
|
+
MessageScrollerViewport,
|
|
396
|
+
useMessageScroller,
|
|
397
|
+
useMessageScrollerScrollable,
|
|
398
|
+
useMessageScrollerVisibility,
|
|
399
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { VariantProps } from "#/lib/utils";
|
|
2
|
+
import { tv } from "#/lib/utils";
|
|
3
|
+
|
|
4
|
+
/* -----------------------------------------------------------------------------
|
|
5
|
+
* Variant: Attachment
|
|
6
|
+
* -------------------------------------------------------------------------- */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* File/media attachment card. Size drives padding for the media and content
|
|
10
|
+
* slots; orientation switches between a horizontal row and a vertical tile.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.5.0-canary.3
|
|
13
|
+
*/
|
|
14
|
+
const attachmentVariants = tv({
|
|
15
|
+
base: "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",
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
orientation: "horizontal",
|
|
18
|
+
size: "default",
|
|
19
|
+
},
|
|
20
|
+
variants: {
|
|
21
|
+
size: {
|
|
22
|
+
default:
|
|
23
|
+
"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",
|
|
24
|
+
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",
|
|
25
|
+
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",
|
|
26
|
+
},
|
|
27
|
+
orientation: {
|
|
28
|
+
horizontal: "min-w-40 items-center",
|
|
29
|
+
vertical: "w-24 flex-col has-data-[slot=attachment-content]:w-30",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @since 0.5.0-canary.3
|
|
36
|
+
*/
|
|
37
|
+
type AttachmentVariants = VariantProps<typeof attachmentVariants>;
|
|
38
|
+
|
|
39
|
+
/* -----------------------------------------------------------------------------
|
|
40
|
+
* Variant: AttachmentMedia
|
|
41
|
+
* -------------------------------------------------------------------------- */
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Media thumbnail — an icon tile or a cover image that reacts to attachment
|
|
45
|
+
* size, orientation, and upload state via the parent `group/attachment`.
|
|
46
|
+
*
|
|
47
|
+
* @since 0.5.0-canary.3
|
|
48
|
+
*/
|
|
49
|
+
const attachmentMediaVariants = tv({
|
|
50
|
+
base: "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",
|
|
51
|
+
defaultVariants: {
|
|
52
|
+
variant: "icon",
|
|
53
|
+
},
|
|
54
|
+
variants: {
|
|
55
|
+
variant: {
|
|
56
|
+
icon: "",
|
|
57
|
+
image:
|
|
58
|
+
"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",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @since 0.5.0-canary.3
|
|
65
|
+
*/
|
|
66
|
+
type AttachmentMediaVariants = VariantProps<typeof attachmentMediaVariants>;
|
|
67
|
+
|
|
68
|
+
/* -----------------------------------------------------------------------------
|
|
69
|
+
* Exports
|
|
70
|
+
* -------------------------------------------------------------------------- */
|
|
71
|
+
|
|
72
|
+
export { attachmentMediaVariants, attachmentVariants };
|
|
73
|
+
export type { AttachmentMediaVariants, AttachmentVariants };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { VariantProps } from "#/lib/utils";
|
|
2
|
+
import { tv } from "#/lib/utils";
|
|
3
|
+
|
|
4
|
+
/* -----------------------------------------------------------------------------
|
|
5
|
+
* Variant: Bubble
|
|
6
|
+
* -------------------------------------------------------------------------- */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Chat bubble surface. Variants paint the nested `bubble-content`, so the color
|
|
10
|
+
* follows the message author regardless of alignment.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.5.0-canary.3
|
|
13
|
+
*/
|
|
14
|
+
const bubbleVariants = tv({
|
|
15
|
+
base: "group/bubble relative flex w-fit max-w-[80%] min-w-0 flex-col gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full",
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
variant: "default",
|
|
18
|
+
},
|
|
19
|
+
variants: {
|
|
20
|
+
variant: {
|
|
21
|
+
default:
|
|
22
|
+
"*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80",
|
|
23
|
+
secondary:
|
|
24
|
+
"*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]",
|
|
25
|
+
muted:
|
|
26
|
+
"*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]",
|
|
27
|
+
tinted:
|
|
28
|
+
"*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]",
|
|
29
|
+
outline:
|
|
30
|
+
"*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30",
|
|
31
|
+
ghost:
|
|
32
|
+
"border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50",
|
|
33
|
+
destructive:
|
|
34
|
+
"*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @since 0.5.0-canary.3
|
|
41
|
+
*/
|
|
42
|
+
type BubbleVariants = VariantProps<typeof bubbleVariants>;
|
|
43
|
+
|
|
44
|
+
/* -----------------------------------------------------------------------------
|
|
45
|
+
* Variant: BubbleReactions
|
|
46
|
+
* -------------------------------------------------------------------------- */
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Reaction pill anchored to a bubble corner.
|
|
50
|
+
*
|
|
51
|
+
* @since 0.5.0-canary.3
|
|
52
|
+
*/
|
|
53
|
+
const bubbleReactionsVariants = tv({
|
|
54
|
+
base: "absolute z-10 flex w-fit shrink-0 items-center justify-center gap-1 rounded-full bg-muted px-1.5 py-0.5 text-sm ring-3 ring-card has-[button]:p-0",
|
|
55
|
+
defaultVariants: {
|
|
56
|
+
align: "end",
|
|
57
|
+
side: "bottom",
|
|
58
|
+
},
|
|
59
|
+
variants: {
|
|
60
|
+
side: {
|
|
61
|
+
top: "top-0 -translate-y-3/4",
|
|
62
|
+
bottom: "bottom-0 translate-y-3/4",
|
|
63
|
+
},
|
|
64
|
+
align: {
|
|
65
|
+
start: "start-3",
|
|
66
|
+
end: "end-3",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @since 0.5.0-canary.3
|
|
73
|
+
*/
|
|
74
|
+
type BubbleReactionsVariants = VariantProps<typeof bubbleReactionsVariants>;
|
|
75
|
+
|
|
76
|
+
/* -----------------------------------------------------------------------------
|
|
77
|
+
* Exports
|
|
78
|
+
* -------------------------------------------------------------------------- */
|
|
79
|
+
|
|
80
|
+
export { bubbleReactionsVariants, bubbleVariants };
|
|
81
|
+
export type { BubbleReactionsVariants, BubbleVariants };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { VariantProps } from "#/lib/utils";
|
|
2
|
+
import { tv } from "#/lib/utils";
|
|
3
|
+
|
|
4
|
+
/* -----------------------------------------------------------------------------
|
|
5
|
+
* Variant: Marker
|
|
6
|
+
* -------------------------------------------------------------------------- */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Inline chat divider — plain label, centered separator rule, or bottom border.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.5.0-canary.3
|
|
12
|
+
*/
|
|
13
|
+
const markerVariants = tv({
|
|
14
|
+
base: "group/marker relative flex min-h-4 w-full items-center gap-2 text-start text-sm text-muted-foreground [&_svg:not([class*='size-'])]:size-4 [a]:underline [a]:underline-offset-3 [a]:hover:text-foreground",
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: "default",
|
|
17
|
+
},
|
|
18
|
+
variants: {
|
|
19
|
+
variant: {
|
|
20
|
+
default: "",
|
|
21
|
+
separator:
|
|
22
|
+
"before:me-1 before:h-px before:min-w-0 before:flex-1 before:bg-border after:ms-1 after:h-px after:min-w-0 after:flex-1 after:bg-border",
|
|
23
|
+
border: "border-b border-border pb-2",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @since 0.5.0-canary.3
|
|
30
|
+
*/
|
|
31
|
+
type MarkerVariants = VariantProps<typeof markerVariants>;
|
|
32
|
+
|
|
33
|
+
/* -----------------------------------------------------------------------------
|
|
34
|
+
* Exports
|
|
35
|
+
* -------------------------------------------------------------------------- */
|
|
36
|
+
|
|
37
|
+
export { markerVariants };
|
|
38
|
+
export type { MarkerVariants };
|