@tamagui/dialog 1.0.1-beta.78 → 1.0.1-beta.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Dialog.tsx CHANGED
@@ -247,7 +247,7 @@ const DialogContentFrame = styled(ThemeableStack, {
247
247
 
248
248
  type DialogContentFrameProps = GetProps<typeof DialogContentFrame>
249
249
 
250
- type DialogContentProps = DialogContentFrameProps & {
250
+ interface DialogContentProps extends DialogContentFrameProps, DialogContentTypeProps {
251
251
  /**
252
252
  * Used to force mounting when more control is needed. Useful when
253
253
  * controlling animation with React animation libraries.
@@ -592,53 +592,63 @@ const DescriptionWarning: React.FC<DescriptionWarningProps> = ({ contentRef, des
592
592
  * Dialog
593
593
  * -----------------------------------------------------------------------------------------------*/
594
594
 
595
- const Dialog = withStaticProperties(
596
- function Dialog(props: ScopedProps<DialogProps>) {
597
- const {
598
- __scopeDialog,
599
- children,
600
- open: openProp,
601
- defaultOpen = false,
602
- onOpenChange,
603
- modal = true,
604
- allowPinchZoom = false,
605
- } = props
606
- const triggerRef = React.useRef<HTMLButtonElement>(null)
607
- const contentRef = React.useRef<TamaguiElement>(null)
608
- const [open, setOpen] = useControllableState({
609
- prop: openProp,
610
- defaultProp: defaultOpen,
611
- onChange: onOpenChange,
612
- })
595
+ const DialogInner = React.forwardRef<{ open: (val: boolean) => void }, DialogProps>(function Dialog(
596
+ props: ScopedProps<DialogProps>,
597
+ ref
598
+ ) {
599
+ const {
600
+ __scopeDialog,
601
+ children,
602
+ open: openProp,
603
+ defaultOpen = false,
604
+ onOpenChange,
605
+ modal = true,
606
+ allowPinchZoom = false,
607
+ } = props
608
+ const triggerRef = React.useRef<HTMLButtonElement>(null)
609
+ const contentRef = React.useRef<TamaguiElement>(null)
610
+ const [open, setOpen] = useControllableState({
611
+ prop: openProp,
612
+ defaultProp: defaultOpen,
613
+ onChange: onOpenChange,
614
+ })
615
+
616
+ React.useImperativeHandle(
617
+ ref,
618
+ () => ({
619
+ open: setOpen,
620
+ }),
621
+ []
622
+ )
613
623
 
614
- return (
615
- <DialogProvider
616
- scope={__scopeDialog}
617
- triggerRef={triggerRef}
618
- contentRef={contentRef}
619
- contentId={useId() || ''}
620
- titleId={useId() || ''}
621
- descriptionId={useId() || ''}
622
- open={open}
623
- onOpenChange={setOpen}
624
- onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}
625
- modal={modal}
626
- allowPinchZoom={allowPinchZoom}
627
- >
628
- {children}
629
- </DialogProvider>
630
- )
631
- },
632
- {
633
- Trigger: DialogTrigger,
634
- Portal: DialogPortal,
635
- Overlay: DialogOverlay,
636
- Content: DialogContent,
637
- Title: DialogTitle,
638
- Description: DialogDescription,
639
- Close: DialogClose,
640
- }
641
- )
624
+ return (
625
+ <DialogProvider
626
+ scope={__scopeDialog}
627
+ triggerRef={triggerRef}
628
+ contentRef={contentRef}
629
+ contentId={useId() || ''}
630
+ titleId={useId() || ''}
631
+ descriptionId={useId() || ''}
632
+ open={open}
633
+ onOpenChange={setOpen}
634
+ onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}
635
+ modal={modal}
636
+ allowPinchZoom={allowPinchZoom}
637
+ >
638
+ {children}
639
+ </DialogProvider>
640
+ )
641
+ })
642
+
643
+ const Dialog = withStaticProperties(DialogInner, {
644
+ Trigger: DialogTrigger,
645
+ Portal: DialogPortal,
646
+ Overlay: DialogOverlay,
647
+ Content: DialogContent,
648
+ Title: DialogTitle,
649
+ Description: DialogDescription,
650
+ Close: DialogClose,
651
+ })
642
652
 
643
653
  export {
644
654
  createDialogScope,