mirror of
https://github.com/formbricks/formbricks.git
synced 2026-03-09 02:00:12 -05:00
* made modal component responsive * added tab switch * added mobile preview mode for surveys * did some refactors * did some refactors * added type defs * ran pnpm format * removed an unused comment * fixed variable name typo * fixed UI bugs and added mobile mockup to link surveys * restored changes from fix long description PR * fixed scroll to top issue and toggle hide bug * fixed minor animation bug * fixed placement issue * re-embed restart button, make phone preview more responsive --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { getPlacementStyle } from "@/lib/preview";
|
|
import { cn } from "@formbricks/lib/cn";
|
|
import { PlacementType } from "@formbricks/types/js";
|
|
import { ReactNode, useEffect, useMemo, useState, useRef } from "react";
|
|
|
|
export default function Modal({
|
|
children,
|
|
isOpen,
|
|
placement,
|
|
previewMode,
|
|
highlightBorderColor,
|
|
}: {
|
|
children: ReactNode;
|
|
isOpen: boolean;
|
|
placement: PlacementType;
|
|
previewMode: string;
|
|
highlightBorderColor: string | null | undefined;
|
|
}) {
|
|
const [show, setShow] = useState(false);
|
|
const modalRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
const highlightBorderColorStyle = useMemo(() => {
|
|
if (!highlightBorderColor) return {};
|
|
|
|
return {
|
|
border: `2px solid ${highlightBorderColor}`,
|
|
overflow: "hidden",
|
|
};
|
|
}, [highlightBorderColor]);
|
|
|
|
useEffect(() => {
|
|
setShow(isOpen);
|
|
}, [isOpen]);
|
|
|
|
// scroll to top whenever question in modal changes
|
|
useEffect(() => {
|
|
if (modalRef.current) {
|
|
modalRef.current.scrollTop = 0;
|
|
}
|
|
}, [children]);
|
|
|
|
const slidingAnimationClass =
|
|
previewMode === "desktop"
|
|
? show
|
|
? "translate-x-0 opacity-100"
|
|
: "translate-x-32 opacity-0"
|
|
: previewMode === "mobile"
|
|
? show
|
|
? "bottom-0"
|
|
: "-bottom-full"
|
|
: "";
|
|
|
|
return (
|
|
<div aria-live="assertive" className="relative h-full w-full overflow-hidden">
|
|
<div
|
|
ref={modalRef}
|
|
style={highlightBorderColorStyle}
|
|
className={cn(
|
|
"pointer-events-auto absolute max-h-[90%] w-full h-fit max-w-sm overflow-y-auto rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5 transition-all duration-500 ease-in-out",
|
|
previewMode === "desktop" ? getPlacementStyle(placement) : "max-w-full ",
|
|
slidingAnimationClass
|
|
)}>
|
|
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|