@connectif/ui-components 1.0.10 → 1.0.11

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.
@@ -16,6 +16,10 @@ export type ChatProps = React.PropsWithChildren<{
16
16
  * Scrollbar color
17
17
  */
18
18
  scrollbarColor?: string;
19
+ /**
20
+ * Number that change to trigger scroll to class in scrollToLastClassName
21
+ */
22
+ triggerScroll?: number;
19
23
  }>;
20
- declare const Chat: ({ children, header, backgroundColor, scrollToLastClassName, scrollbarColor }: ChatProps) => import("react/jsx-runtime").JSX.Element;
24
+ declare const Chat: ({ children, header, backgroundColor, scrollToLastClassName, scrollbarColor, triggerScroll }: ChatProps) => import("react/jsx-runtime").JSX.Element;
21
25
  export default Chat;
package/dist/index.js CHANGED
@@ -13460,14 +13460,17 @@ var ChatMessage_default = ChatMessage;
13460
13460
  import Stack5 from "@mui/material/Stack";
13461
13461
  import * as React35 from "react";
13462
13462
  import { jsx as jsx80, jsxs as jsxs35 } from "react/jsx-runtime";
13463
+ var PADDING_BOTTOM = 8;
13463
13464
  var Chat = ({
13464
13465
  children,
13465
13466
  header,
13466
13467
  backgroundColor: backgroundColor2,
13467
13468
  scrollToLastClassName,
13468
- scrollbarColor
13469
+ scrollbarColor,
13470
+ triggerScroll
13469
13471
  }) => {
13470
13472
  const ref = React35.useRef(null);
13473
+ const innerRef = React35.useRef(null);
13471
13474
  const [isInitialize, setIsInitialize] = React35.useState(false);
13472
13475
  const [hasVerticalScroll, setHasVerticalScroll] = React35.useState(false);
13473
13476
  React35.useEffect(() => {
@@ -13490,20 +13493,31 @@ var Chat = ({
13490
13493
  if (!container) {
13491
13494
  return;
13492
13495
  }
13493
- if (scrollToLastClassName) {
13494
- const elements = container.querySelectorAll(
13495
- `.${scrollToLastClassName}`
13496
+ if (innerRef.current && innerRef.current.style.paddingBottom !== "0px" && innerRef.current.style.paddingBottom !== `${PADDING_BOTTOM}px` && innerRef.current.style.paddingBottom !== "") {
13497
+ const paddingBottom = parseInt(
13498
+ innerRef.current.style.paddingBottom || "0",
13499
+ 10
13496
13500
  );
13497
- const last = elements[elements.length - 1];
13498
- if (last) {
13499
- last.scrollIntoView({ behavior: "smooth", block: "start" });
13500
- } else {
13501
- container.scrollTo(0, container.scrollHeight);
13502
- }
13503
- } else {
13504
- container.scrollTo(0, container.scrollHeight);
13501
+ const childrenHeight = innerRef.current.scrollHeight - paddingBottom;
13502
+ const childrenHeightVisible = childrenHeight - container.scrollTop;
13503
+ innerRef.current.style.paddingBottom = childrenHeightVisible > container.clientHeight ? "0px" : `${container.clientHeight - childrenHeightVisible}px`;
13504
+ }
13505
+ }, [children]);
13506
+ React35.useEffect(() => {
13507
+ const container = ref.current;
13508
+ if (!container || !scrollToLastClassName || !triggerScroll) {
13509
+ return;
13510
+ }
13511
+ const elements = container.querySelectorAll(
13512
+ `.${scrollToLastClassName}`
13513
+ );
13514
+ const last = elements[elements.length - 1];
13515
+ if (last && innerRef.current) {
13516
+ const paddingBottom = container.clientHeight - last.offsetHeight;
13517
+ innerRef.current.style.paddingBottom = `${paddingBottom}px`;
13518
+ last.scrollIntoView({ behavior: "smooth", block: "start" });
13505
13519
  }
13506
- }, [children, scrollToLastClassName]);
13520
+ }, [scrollToLastClassName, triggerScroll]);
13507
13521
  return /* @__PURE__ */ jsxs35(
13508
13522
  Stack5,
13509
13523
  {
@@ -13515,7 +13529,7 @@ var Chat = ({
13515
13529
  height: "calc(100% - 8px)",
13516
13530
  visibility: !isInitialize ? "hidden" : "visible",
13517
13531
  width: `calc(100% - ${hasVerticalScroll ? "4px" : "8px"})`,
13518
- paddingBottom: "8px",
13532
+ paddingBottom: `${PADDING_BOTTOM}px`,
13519
13533
  ...backgroundColor2 && { backgroundColor: backgroundColor2 },
13520
13534
  paddingRight: hasVerticalScroll ? "4px" : "8px",
13521
13535
  "::-webkit-scrollbar": {
@@ -13538,10 +13552,10 @@ var Chat = ({
13538
13552
  /* @__PURE__ */ jsx80(
13539
13553
  Stack5,
13540
13554
  {
13541
- justifyContent: "end",
13555
+ ref: innerRef,
13556
+ justifyContent: "start",
13542
13557
  ...!header && {
13543
- minHeight: "100%",
13544
- justifyContent: "end"
13558
+ minHeight: "100%"
13545
13559
  },
13546
13560
  sx: {
13547
13561
  "> *": { marginTop: "12px" },