@banbox/chat 1.0.3 → 1.0.5

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.
@@ -1,64 +1,52 @@
1
- "use client";
2
- import clsx from "clsx";
3
- import React from "react";
4
-
5
- type Props = {
6
- top?: React.ReactNode;
7
- children: React.ReactNode;
8
- className?: string;
9
- /** set true if you want short threads anchored at the bottom */
10
- bottomAlignWhenShort?: boolean;
11
- /** when this value changes, we auto-scroll to the bottom */
12
- scrollKey?: string | number;
13
- };
14
-
15
- const ChatScroll: React.FC<Props> = ({
16
- top,
17
- children,
18
- className,
19
- bottomAlignWhenShort = false,
20
- scrollKey,
21
- }) => {
22
- const ref = React.useRef<HTMLDivElement>(null);
23
-
24
- const scrollToBottom = React.useCallback(() => {
25
- const el = ref.current;
26
- if (!el) {
27
- return;
28
- }
29
- el.scrollTop = el.scrollHeight;
30
- }, []);
31
-
32
- // On mount & when scrollKey changes
33
- React.useEffect(() => {
34
- // immediate
35
- scrollToBottom();
36
- // nudge after paint/layout (covers images)
37
- const id = window.setTimeout(scrollToBottom, 0);
38
- return () => window.clearTimeout(id);
39
- }, [scrollKey, scrollToBottom]);
40
-
41
- return (
42
- <div
43
- ref={ref}
44
- data-chat-scroll
45
- className={clsx(
46
- "h-full min-h-0 overflow-y-auto bg-white p-4 custom-scroll-hidden",
47
- className,
48
- )}
49
- >
50
- {/* This wrapper ensures content is at least as tall as the scroll area */}
51
- <div
52
- className={clsx(
53
- "min-h-full flex flex-col",
54
- bottomAlignWhenShort ? "justify-end" : "justify-start",
55
- )}
56
- >
57
- {top}
58
- {children}
59
- </div>
60
- </div>
61
- );
62
- };
63
-
64
- export default ChatScroll;
1
+ "use client";
2
+ import React from "react";
3
+
4
+ type Props = {
5
+ top?: React.ReactNode;
6
+ children: React.ReactNode;
7
+ className?: string;
8
+ style?: React.CSSProperties;
9
+ bottomAlignWhenShort?: boolean;
10
+ scrollKey?: string | number;
11
+ };
12
+
13
+ const ChatScroll: React.FC<Props> = ({
14
+ top,
15
+ children,
16
+ className,
17
+ style,
18
+ bottomAlignWhenShort = false,
19
+ scrollKey,
20
+ }) => {
21
+ const ref = React.useRef<HTMLDivElement>(null);
22
+
23
+ const scrollToBottom = React.useCallback(() => {
24
+ const el = ref.current;
25
+ if (!el) return;
26
+ el.scrollTop = el.scrollHeight;
27
+ }, []);
28
+
29
+ React.useEffect(() => {
30
+ scrollToBottom();
31
+ const id = window.setTimeout(scrollToBottom, 0);
32
+ return () => window.clearTimeout(id);
33
+ }, [scrollKey, scrollToBottom]);
34
+
35
+ return (
36
+ <div
37
+ ref={ref}
38
+ data-chat-scroll
39
+ className={`h-full min-h-0 overflow-y-auto bg-white p-4 custom-scroll-hidden${className ? ` ${className}` : ""}`}
40
+ style={style}
41
+ >
42
+ <div
43
+ className={`min-h-full flex flex-col${bottomAlignWhenShort ? " justify-end" : " justify-start"}`}
44
+ >
45
+ {top}
46
+ {children}
47
+ </div>
48
+ </div>
49
+ );
50
+ };
51
+
52
+ export default ChatScroll;
@@ -6,44 +6,34 @@ import _Lottie from "lottie-react";
6
6
  const Lottie = ((_Lottie as any).default ?? _Lottie) as typeof _Lottie;
7
7
 
8
8
  import React from "react";
9
- import { cn } from "../../utils/cn";
10
9
  import dots from "../../lottie/typingdotanimation2.json";
11
10
 
12
- /* =======================
13
- Types
14
- ======================= */
15
-
16
11
  type Props = {
17
- /** Pixel box for the animation area */
18
- size?: number; // default 18 (inside badge)
19
- loop?: boolean; // default true
20
- autoplay?: boolean; // default true
12
+ size?: number;
13
+ loop?: boolean;
14
+ autoplay?: boolean;
21
15
  className?: string;
16
+ style?: React.CSSProperties;
22
17
  ariaLabel?: string;
23
-
24
- /** Avatar size in px */
25
- avatarSize?: number; // default 40
18
+ avatarSize?: number;
26
19
  };
27
20
 
28
- /* =======================
29
- Component
30
- ======================= */
31
-
32
21
  const TypingIndicator: React.FC<Props> = ({
33
- size = 18,
34
22
  loop = true,
35
23
  autoplay = true,
36
24
  className,
37
25
  ariaLabel = "Typing…",
38
26
  avatarSize = 40,
27
+ style,
39
28
  }) => {
40
29
  const isOnline = true;
41
30
 
42
31
  return (
43
32
  <div
44
- className={cn("relative flex items-end gap-[6px]", className)}
45
33
  role="status"
46
34
  aria-label={ariaLabel}
35
+ className={`relative flex items-end gap-[6px]${className ? ` ${className}` : ""}`}
36
+ style={style}
47
37
  >
48
38
  {/* Avatar */}
49
39
  <div
@@ -55,13 +45,12 @@ const TypingIndicator: React.FC<Props> = ({
55
45
  alt="avatar image"
56
46
  className="h-full w-full rounded-full object-cover"
57
47
  />
58
-
59
48
  {isOnline && (
60
- <span className="absolute bottom-[0px] right-[0px] h-[11.25px] w-[11.25px] rounded-full bg-[#328545] ring-1 ring-white" />
49
+ <span className="absolute bottom-0 right-0 h-[11.25px] w-[11.25px] rounded-full bg-[#328545] ring-1 ring-white" />
61
50
  )}
62
51
  </div>
63
52
 
64
- {/* typing lottie at bottom-right */}
53
+ {/* Lottie typing dots */}
65
54
  <span className="absolute bottom-[-13px] left-[30px]">
66
55
  <Lottie
67
56
  animationData={dots}