From f3b41c96bbbcb2fdbb57abeaa953623aa92ee386 Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Thu, 9 Jan 2025 17:32:21 +0100 Subject: [PATCH] chore(core): export EditPortal from sanity to allow users build custom Dialogs or Popovers --- .../src/core/form/components/EditPortal.tsx | 43 +++++++++++-------- .../sanity/src/core/form/components/index.ts | 1 + 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/sanity/src/core/form/components/EditPortal.tsx b/packages/sanity/src/core/form/components/EditPortal.tsx index 621afa306f02..6ccb83ae7c17 100644 --- a/packages/sanity/src/core/form/components/EditPortal.tsx +++ b/packages/sanity/src/core/form/components/EditPortal.tsx @@ -8,16 +8,25 @@ import {VirtualizerScrollInstanceProvider} from '../inputs/arrays/ArrayOfObjects const PRESENCE_MARGINS: [number, number, number, number] = [0, 0, 1, 0] -interface Props { - type: 'popover' | 'dialog' +interface SharedProps { + children?: ReactNode + header: string width: ResponsiveWidthProps['width'] +} +interface DialogProps extends SharedProps { + type: 'dialog' header: string id?: string - onClose: () => void - children?: ReactNode + autofocus?: boolean + onClose?: () => void +} + +interface PopoverProps extends SharedProps { + type: 'popover' + header: string // eslint-disable-next-line camelcase legacy_referenceElement: HTMLElement | null - autofocus?: boolean + onClose: () => void } function onDragEnter(event: DragEvent) { @@ -28,17 +37,13 @@ function onDrop(event: DragEvent) { return event.stopPropagation() } -export function EditPortal(props: Props): React.JSX.Element { - const { - children, - header, - id, - legacy_referenceElement: referenceElement, - onClose, - type, - width, - autofocus, - } = props +/** + * @internal + * Creates a dialog or a popover for editing content. + * Handles presence and virtual scrolling. + */ +export function EditPortal(props: PopoverProps | DialogProps): React.JSX.Element { + const {children, header, onClose, type, width} = props const [documentScrollElement, setDocumentScrollElement] = useState(null) const containerElement = useRef(null) @@ -55,11 +60,11 @@ export function EditPortal(props: Props): React.JSX.Element { containerElement={containerElement} > diff --git a/packages/sanity/src/core/form/components/index.ts b/packages/sanity/src/core/form/components/index.ts index 1232b537f5fe..505b839b942a 100644 --- a/packages/sanity/src/core/form/components/index.ts +++ b/packages/sanity/src/core/form/components/index.ts @@ -1,2 +1,3 @@ +export * from './EditPortal' export * from './formField' export * from './FormInput'