ss-support-widget 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ss-support-widget",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Chatbot widget for customer support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@ import SmartToyRoundedIcon from "@mui/icons-material/SmartToyRounded";
18
18
  import PersonRoundedIcon from "@mui/icons-material/PersonRounded";
19
19
  import ReactMarkdown from "react-markdown";
20
20
  import { Msg } from "./App";
21
+ import { useViewportHeightVar } from "./hooks";
21
22
 
22
23
 
23
24
  export function ChatWidget({
@@ -42,6 +43,7 @@ export function ChatWidget({
42
43
  const endRef = useRef<HTMLDivElement | null>(null);
43
44
  const theme = useTheme();
44
45
  const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
46
+ useViewportHeightVar();
45
47
 
46
48
  useEffect(() => {
47
49
  endRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
@@ -76,9 +78,12 @@ export function ChatWidget({
76
78
  elevation={isMobile ? 0 : 10}
77
79
  sx={{
78
80
  width: isMobile ? "100vw" : 380,
79
- height: isMobile ? "100vh" : 560,
81
+ height: isMobile ? "calc(var(--vh, 1vh) * 100)" : 560,
82
+ "@supports (height: 100dvh)": {
83
+ height: isMobile ? "100dvh" : 560,
84
+ },
80
85
  maxWidth: "100vw",
81
- maxHeight: "100vh",
86
+ maxHeight: "100dvh",
82
87
  borderRadius: isMobile ? 0 : 4,
83
88
  position: isMobile ? "fixed" : "relative",
84
89
  inset: isMobile ? 0 : "auto",
@@ -149,7 +154,7 @@ export function ChatWidget({
149
154
  <Box
150
155
  sx={{
151
156
  flex: 1,
152
- minHeight: 250,
157
+ minHeight: 0,
153
158
  position: "relative",
154
159
  // height: 300,
155
160
  overflow: "auto",
@@ -392,4 +397,4 @@ export function ChatWidget({
392
397
  </Box>
393
398
  );
394
399
  }
395
- export default ChatWidget;
400
+ export default ChatWidget;
package/src/hooks.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { useEffect } from "react";
2
+
1
3
  export function ensureViewportMeta() {
2
4
  if (typeof document === "undefined") return;
3
5
 
@@ -10,3 +12,21 @@ export function ensureViewportMeta() {
10
12
  document.head.appendChild(meta);
11
13
  }
12
14
 
15
+ export function useViewportHeightVar() {
16
+ useEffect(() => {
17
+ const setVh = () => {
18
+ const vh = window.innerHeight * 0.01;
19
+ document.documentElement.style.setProperty("--vh", `${vh}px`);
20
+ };
21
+
22
+ setVh();
23
+
24
+ window.addEventListener("resize", setVh);
25
+ window.addEventListener("orientationchange", setVh);
26
+
27
+ return () => {
28
+ window.removeEventListener("resize", setVh);
29
+ window.removeEventListener("orientationchange", setVh);
30
+ };
31
+ }, []);
32
+ }