Skip to content

Commit 07b77b8

Browse files
Olfa MaslahOlfa Maslah
authored andcommitted
logic for the slider and chat-header
1 parent d0bd45a commit 07b77b8

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

.secrets.baseline

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,23 +1403,35 @@
14031403
"filename": "src/frontend/src/constants/constants.ts",
14041404
"hashed_secret": "19a2fbd0dd38b4097f419c962342ef5e109eab07",
14051405
"is_verified": false,
1406+
<<<<<<< HEAD
14061407
"line_number": 759,
1408+
=======
1409+
"line_number": 758,
1410+
>>>>>>> e285aff7dc (logic for the slider and chat-header)
14071411
"is_secret": false
14081412
},
14091413
{
14101414
"type": "Secret Keyword",
14111415
"filename": "src/frontend/src/constants/constants.ts",
14121416
"hashed_secret": "3806954324550e26ef5de85d007f1746825a073c",
14131417
"is_verified": false,
1418+
<<<<<<< HEAD
14141419
"line_number": 760,
1420+
=======
1421+
"line_number": 759,
1422+
>>>>>>> e285aff7dc (logic for the slider and chat-header)
14151423
"is_secret": false
14161424
},
14171425
{
14181426
"type": "Secret Keyword",
14191427
"filename": "src/frontend/src/constants/constants.ts",
14201428
"hashed_secret": "c04f8fbf55c9096907a982750b1c6b0e4c1dd658",
14211429
"is_verified": false,
1430+
<<<<<<< HEAD
14221431
"line_number": 933,
1432+
=======
1433+
"line_number": 932,
1434+
>>>>>>> e285aff7dc (logic for the slider and chat-header)
14231435
"is_secret": false
14241436
}
14251437
],

src/frontend/src/components/core/flowToolbarComponent/components/playground-button.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import ForwardedIconComponent from "@/components/common/genericIconComponent";
22
import ShadTooltip from "@/components/common/shadTooltipComponent";
3+
34
// import { CustomIOModal } from "@/customization/components/custom-new-modal";
5+
46
import { PLAYGROUND_BUTTON_NAME } from "@/constants/constants";
57
import { ENABLE_PUBLISH } from "@/customization/feature-flags";
68
import { usePlaygroundStore } from "@/stores/playgroundStore";
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { useCallback, useEffect, useRef, useState } from "react";
2+
import { cn } from "@/utils/utils";
3+
4+
const DEFAULT_WIDTH = 400;
5+
const DEFAULT_DURATION = 0.3;
6+
7+
interface SlidingContainerProps {
8+
isOpen: boolean;
9+
children: React.ReactNode;
10+
className?: string;
11+
width?: number;
12+
onWidthChange?: (width: number) => void;
13+
resizable?: boolean;
14+
duration?: number;
15+
isFullscreen?: boolean;
16+
}
17+
18+
export function SlidingContainer({
19+
isOpen,
20+
children,
21+
className,
22+
width = DEFAULT_WIDTH,
23+
onWidthChange,
24+
resizable = false,
25+
duration = DEFAULT_DURATION,
26+
isFullscreen = false,
27+
}: SlidingContainerProps) {
28+
const [isResizing, setIsResizing] = useState(false);
29+
const containerRef = useRef<HTMLDivElement>(null);
30+
31+
const handleMouseDown = useCallback(
32+
(e: React.MouseEvent) => {
33+
if (!resizable || !isOpen) return;
34+
e.preventDefault();
35+
setIsResizing(true);
36+
},
37+
[resizable, isOpen],
38+
);
39+
40+
useEffect(() => {
41+
if (!isResizing) return;
42+
43+
const handleMouseMove = (e: MouseEvent) => {
44+
if (!onWidthChange) return;
45+
const newWidth = window.innerWidth - e.clientX;
46+
onWidthChange(newWidth);
47+
};
48+
49+
const handleMouseUp = () => {
50+
setIsResizing(false);
51+
};
52+
53+
document.addEventListener("mousemove", handleMouseMove);
54+
document.addEventListener("mouseup", handleMouseUp);
55+
56+
return () => {
57+
document.removeEventListener("mousemove", handleMouseMove);
58+
document.removeEventListener("mouseup", handleMouseUp);
59+
};
60+
}, [isResizing, onWidthChange]);
61+
62+
const fullscreenWidth = "100%";
63+
const actualWidth = isFullscreen
64+
? fullscreenWidth
65+
: isOpen
66+
? `${width}px`
67+
: "0px";
68+
69+
return (
70+
<div
71+
ref={containerRef}
72+
className={cn(
73+
// Sync with outer overlay: animate width only, match easing and duration.
74+
"relative h-full overflow-hidden transition-[width] ease",
75+
isResizing && "select-none",
76+
className,
77+
)}
78+
style={{
79+
width: actualWidth,
80+
transitionDuration: isResizing ? "0ms" : `${duration}ms`,
81+
}}
82+
>
83+
{resizable && isOpen && !isFullscreen && (
84+
<div
85+
onMouseDown={handleMouseDown}
86+
className={cn(
87+
"absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize bg-transparent hover:bg-primary/20 transition-colors",
88+
isResizing && "bg-primary/30",
89+
)}
90+
style={{ touchAction: "none" }}
91+
aria-label="Resize panel"
92+
/>
93+
)}
94+
<div className="h-full w-full">{children}</div>
95+
</div>
96+
);
97+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { create } from "zustand";
2+
3+
const MIN_WIDTH = 300;
4+
const MAX_WIDTH_RATIO = 0.5;
5+
const DEFAULT_WIDTH = 400;
6+
7+
export interface SlidingContainerStoreType {
8+
isOpen: boolean;
9+
setIsOpen: (isOpen: boolean) => void;
10+
toggle: () => void;
11+
width: number;
12+
setWidth: (width: number) => void;
13+
isFullscreen: boolean;
14+
setIsFullscreen: (isFullscreen: boolean) => void;
15+
toggleFullscreen: () => void;
16+
}
17+
18+
export const useSlidingContainerStore = create<SlidingContainerStoreType>(
19+
(set) => ({
20+
isOpen: false,
21+
setIsOpen: (isOpen: boolean) => set({ isOpen }),
22+
toggle: () => set((state) => ({ isOpen: !state.isOpen })),
23+
width: DEFAULT_WIDTH,
24+
setWidth: (width: number) => {
25+
const maxWidth = window.innerWidth * MAX_WIDTH_RATIO;
26+
set({ width: Math.max(MIN_WIDTH, Math.min(maxWidth, width)) });
27+
},
28+
isFullscreen: false,
29+
setIsFullscreen: (isFullscreen: boolean) => set({ isFullscreen }),
30+
toggleFullscreen: () =>
31+
set((state) => ({ isFullscreen: !state.isFullscreen })),
32+
}),
33+
);

0 commit comments

Comments
 (0)