import { Box, Text, Group, ActionIcon, ScrollArea, Divider, } from "@mantine/core"; import { ArrowLeftIcon, CheckIcon } from "@phosphor-icons/react"; import { useState, ReactNode } from "react"; import { SlidePanelContext, type PanelConfig } from "./slide-panel-context"; import Button from "@/components/button"; interface SlidePanelProps { children: ReactNode; onSubmit: (event: React.FormEvent) => void; onCancel?: () => void; submitText?: string; cancelText?: string; cancelColor?: string; maxHeight?: string; formProps?: Record; loading?: boolean; } const SlidePanel = ({ children, onSubmit, onCancel, submitText = "Submit", cancelText = "Cancel", cancelColor = "red", maxHeight = "70vh", formProps = {}, loading = false, }: SlidePanelProps) => { const [isOpen, setIsOpen] = useState(false); const [panelConfig, setPanelConfig] = useState(null); const [tempValue, setTempValue] = useState(null); const openPanel = (config: PanelConfig) => { setPanelConfig(config); setTempValue(config.value); setIsOpen(true); }; const closePanel = () => { setIsOpen(false); }; const handleConfirm = () => { if (panelConfig) { panelConfig.onChange(tempValue); } setIsOpen(false); }; const handleFormSubmit = (event: React.FormEvent) => { event.preventDefault(); onSubmit(event); }; return (
{children} {onCancel && ( )}
{panelConfig && ( <> {panelConfig.title} )}
); }; export { SlidePanel };