Skip to content

Commit ab31417

Browse files
authoredJan 10, 2025··
chore(core): export EditPortal from sanity (#8229)
1 parent 26b64c7 commit ab31417

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed
 

Diff for: ‎packages/sanity/src/core/form/components/EditPortal.tsx

+23-20
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@ import {VirtualizerScrollInstanceProvider} from '../inputs/arrays/ArrayOfObjects
88

99
const PRESENCE_MARGINS: [number, number, number, number] = [0, 0, 1, 0]
1010

11-
interface Props {
12-
type: 'popover' | 'dialog'
13-
width: ResponsiveWidthProps['width']
11+
interface SharedProps {
12+
children?: ReactNode
1413
header: string
14+
width: ResponsiveWidthProps['width']
15+
}
16+
interface DialogProps extends SharedProps {
17+
type: 'dialog'
1518
id?: string
16-
onClose: () => void
17-
children?: ReactNode
19+
autofocus?: boolean
20+
onClose?: () => void
21+
}
22+
23+
interface PopoverProps extends SharedProps {
24+
type: 'popover'
1825
// eslint-disable-next-line camelcase
1926
legacy_referenceElement: HTMLElement | null
20-
autofocus?: boolean
27+
onClose: () => void
2128
}
2229

2330
function onDragEnter(event: DragEvent<HTMLDivElement>) {
@@ -28,17 +35,13 @@ function onDrop(event: DragEvent<HTMLDivElement>) {
2835
return event.stopPropagation()
2936
}
3037

31-
export function EditPortal(props: Props): React.JSX.Element {
32-
const {
33-
children,
34-
header,
35-
id,
36-
legacy_referenceElement: referenceElement,
37-
onClose,
38-
type,
39-
width,
40-
autofocus,
41-
} = props
38+
/**
39+
* @internal
40+
* Creates a dialog or a popover for editing content.
41+
* Handles presence and virtual scrolling.
42+
*/
43+
export function EditPortal(props: PopoverProps | DialogProps): React.JSX.Element {
44+
const {children, header, onClose, type, width} = props
4245
const [documentScrollElement, setDocumentScrollElement] = useState<HTMLDivElement | null>(null)
4346
const containerElement = useRef<HTMLDivElement | null>(null)
4447

@@ -55,11 +58,11 @@ export function EditPortal(props: Props): React.JSX.Element {
5558
containerElement={containerElement}
5659
>
5760
<Dialog
58-
__unstable_autoFocus={autofocus}
61+
__unstable_autoFocus={props.autofocus}
5962
contentRef={setDocumentScrollElement}
6063
data-testid="edit-portal-dialog"
6164
header={header}
62-
id={id || ''}
65+
id={props.id || ''}
6366
onClickOutside={onClose}
6467
onClose={onClose}
6568
onDragEnter={onDragEnter}
@@ -76,7 +79,7 @@ export function EditPortal(props: Props): React.JSX.Element {
7679
<PopoverDialog
7780
header={header}
7881
onClose={onClose}
79-
referenceElement={referenceElement}
82+
referenceElement={props.legacy_referenceElement}
8083
width={width}
8184
containerRef={setDocumentScrollElement}
8285
>

Diff for: ‎packages/sanity/src/core/form/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './EditPortal'
12
export * from './formField'
23
export * from './FormInput'

0 commit comments

Comments
 (0)
Please sign in to comment.