forked from langflow-ai/langflow-embedded-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { MessageSquare, X } from "lucide-react" | ||
export default function ChatTrigger({style, open, setOpen, triggerRef}:{style?:React.CSSProperties, open:boolean, setOpen:Function, triggerRef:React.RefObject<HTMLDivElement>|null}){ | ||
export default function ChatTrigger({ style, open, setOpen, triggerRef }: { style?: React.CSSProperties, open: boolean, setOpen: Function, triggerRef: React.RefObject<HTMLButtonElement> | null }) { | ||
|
||
return ( | ||
<div ref={triggerRef}> | ||
<button style={style} onClick={()=>setOpen(!open)} className="bg-blue-500 hover:bg-blue-700 w-12 h-12 text-white font-bold rounded-full flex justify-center items-center"> | ||
{open?<X className="h-1/2 w-1/2"/>:<MessageSquare className="h-1/2 w-1/2"/>} | ||
</button> | ||
</div> | ||
<button ref={triggerRef} style={style} | ||
onClick={() => { setOpen(!open); console.log(triggerRef?.current?.getBoundingClientRect()) }} | ||
className="bg-blue-500 hover:bg-blue-700 w-12 h-12 text-white font-bold rounded-full flex justify-center items-center"> | ||
{open ? <X className="h-1/2 w-1/2" /> : <MessageSquare className="h-1/2 w-1/2" />} | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
export function getChatPosition(position: string,triggerPosition:DOMRect){ | ||
if (!triggerPosition) { | ||
return ""; // Return empty string if trigger position is not available | ||
} | ||
|
||
const { top, left, width, height } = triggerPosition; | ||
|
||
const distance = 10; // Adjust this value to set the desired distance from the trigger | ||
export function getChatPosition( | ||
position: string, | ||
triggerPosition: DOMRect, | ||
Cwidth:number, | ||
Cheight:number | ||
): { top: string; left: string; } { | ||
if (!triggerPosition) { | ||
return { top: "0px", left: "0px" }; // Return empty string if trigger position is not available | ||
} | ||
|
||
switch (position) { | ||
case "top-left": | ||
return `top-${top - height - distance}px left-${left}px`; | ||
case "top-center": | ||
return `top-${top - height - distance}px left-${left + width / 2}px -translate-x-1/2`; | ||
case "top-right": | ||
return `top-${top - height - distance}px right-${window.innerWidth - (left + width)}px`; | ||
case "center-left": | ||
return `top-${top + height / 2}px left-${left - width - distance}px -translate-y-1/2`; | ||
case "center-right": | ||
return `top-${top + height / 2}px right-${window.innerWidth - (left + width) - distance}px -translate-y-1/2`; | ||
case "bottom-right": | ||
return `bottom-${window.innerHeight - top + distance}px right-${window.innerWidth - (left + width)}px`; | ||
case "bottom-center": | ||
return `bottom-${window.innerHeight - top + distance}px left-${left + width / 2}px -translate-x-1/2`; | ||
case "bottom-left": | ||
return `bottom-${window.innerHeight - top + distance}px left-${left}px`; | ||
default: | ||
return ""; | ||
} | ||
} | ||
const { top, left, width, height } = triggerPosition; | ||
|
||
const distance = 5; // Adjust this value to set the desired distance from the trigger | ||
|
||
switch (position) { | ||
case "top-left": | ||
return { top: - distance - Cheight + "px", left: -Cwidth + "px" }; | ||
case "top-center": | ||
return { top: - distance - Cheight + "px", left: width/2-Cwidth / 2 + "px" }; | ||
case "top-right": | ||
return { top: - distance - Cheight + "px", left: width+ "px" }; | ||
case "center-left": | ||
return { top: width/2-Cheight/2 + "px", left: -Cwidth - distance + "px" }; | ||
case "center-right": | ||
return { | ||
top: width/2-Cheight/2 + "px", | ||
left: width + distance + "px", | ||
}; | ||
case "bottom-right": | ||
return { top: distance + height+ "px", left: width + "px" }; | ||
case "bottom-center": | ||
return { | ||
top: distance + height+ "px", | ||
left: width/2-Cwidth / 2 + "px", | ||
}; | ||
case "bottom-left": | ||
return { top: distance + height+ "px", left: -Cwidth + "px"}; | ||
default: | ||
return { top: - distance - Cheight + "px", left: -Cwidth + "px" }; } | ||
} |