import { Box, Text, UnstyledButton, Flex, Stack } from "@mantine/core"; import { CaretRightIcon } from "@phosphor-icons/react"; import { ComponentType, useContext } from "react"; import { SlidePanelContext } from "./slide-panel-context"; interface SlidePanelFieldProps { key: string; value?: any; onChange?: (value: any) => void; Component: ComponentType; title: string; label?: string; placeholder?: string; formatValue?: (value: any) => string; componentProps?: Record; withAsterisk?: boolean; error?: string; } const SlidePanelField = ({ value, onChange, Component, title, label, placeholder = "Select value", withAsterisk = false, formatValue, componentProps, error, }: SlidePanelFieldProps) => { const context = useContext(SlidePanelContext); if (!context) { throw new Error('SlidePanelField must be used within a SlidePanel'); } const handleClick = () => { if (!onChange) return; context.openPanel({ title, Component, value, onChange, componentProps, }); }; const displayValue = () => { if (formatValue && value != null) { return formatValue(value); } if (value != null) { if (value instanceof Date) { return value.toLocaleDateString(); } return String(value); } return placeholder; }; return ( {label}{withAsterisk && *} {displayValue()} {error && {error}} ); }; export { SlidePanelField };