Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add an modal to show an image from an integration page.

Ivan Vasilov0d45d6f1cbb0
diff --git a/apps/www/components/ImageModal.tsx b/apps/www/components/ImageModal.tsx
new file mode 100644
index 00000000000..0b7c79e2db3
--- /dev/null
+++ b/apps/www/components/ImageModal.tsx
@@ -0,0 +1,80 @@
+import React, { useEffect } from 'react'
+
+import * as Dialog from '@radix-ui/react-dialog'
+
+import styleHandler from 'ui/src/lib/theme/styleHandler'
+
+export type ImageModalProps = RadixProps & Props
+
+interface RadixProps
+ extends Dialog.DialogProps,
+ Pick<
+ Dialog.DialogContentProps,
+ | 'onOpenAutoFocus'
+ | 'onCloseAutoFocus'
+ | 'onEscapeKeyDown'
+ | 'onPointerDownOutside'
+ | 'onInteractOutside'
+ > {}
+
+interface Props {
+ children?: React.ReactNode
+ onCancel?: any
+ visible: boolean
+ size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'
+ className?: string
+}
+
+/**
+ * Similar to ui/Modal component but with an unstyled dialog content component.
+ * Mainly used to show images in a overlay.
+ */
+const ImageModal = ({
+ children,
+ onCancel = () => {},
+ visible = false,
+ size = 'large',
+ className = '',
+}: ImageModalProps) => {
+ const [open, setOpen] = React.useState(visible ? visible : false)
+
+ const __styles = styleHandler('modal')
+
+ useEffect(() => {
+ setOpen(visible)
+ }, [visible])
+
+ function handleOpenChange(open: boolean) {
+ if (visible !== undefined && !open) {
+ // controlled component behaviour
+ onCancel()
+ } else {
+ // un-controlled component behaviour
+ setOpen(open)
+ }
+ }
+
+ const contentClasses =
+ 'relative data-open:animate-overlay-show data-closed:animate-overlay-hide'
+
+ return (
+ <Dialog.Root open={open} onOpenChange={handleOpenChange}>
+ <Dialog.Portal>
+ <Dialog.Overlay className={__styles.overlay} />
+ <Dialog.Overlay className={__styles.scroll_overlay}>
+ <Dialog.Content className={[contentClasses, __styles.size[size], className].join(' ')}>
+ {children}
+ </Dialog.Content>
+ </Dialog.Overlay>
+ </Dialog.Portal>
+ </Dialog.Root>
+ )
+}
+
+function Content({ children }: { children: React.ReactNode }) {
+ const __styles = styleHandler('modal')
+ return <div className={__styles.content}>{children}</div>
+}
+
+ImageModal.Content = Content
+export default ImageModal
diff --git a/apps/www/pages/partners/integrations/[slug].tsx b/apps/www/pages/partners/integrations/[slug].tsx
index 2ac95452ff2..e3b6d101840 100644
--- a/apps/www/pages/partners/integrations/[slug].tsx
+++ b/apps/www/pages/partners/integrations/[slug].tsx
@@ -5,14 +5,18 @@ import Image from 'next/image'
import Link from 'next/link'
import { Swiper, SwiperSlide } from 'swiper/react'
import 'swiper/swiper.min.css'
-import { IconChevronLeft, IconExternalLink } from 'ui'
+import { IconChevronLeft, IconExternalLink, Modal } from 'ui'
import DefaultLayout from '~/components/Layouts/Default'
import SectionContainer from '~/components/Layouts/SectionContainer'
import supabase from '~/lib/supabase'
import { Partner } from '~/types/partners'
import Error404 from '../../404'
+import { useState } from 'react'
+import ImageModal from '~/components/ImageModal'
function Partner({ partner }: { partner: Partner }) {
+ const [focusedImage, setFocusedImage] = useState<string | null>(null)
+
if (!partner) return <Error404 />
return (
<>
@@ -31,6 +35,24 @@ function Partner({ partner }: { partner: Partner }) {
}}
/>
+ {focusedImage ? (
+ <ImageModal
+ visible
+ onCancel={() => setFocusedImage(null)}
+ size="xxlarge"
+ className="w-full outline-none"
+ // hideFooter
+ >
+ <Image
+ layout="responsive"
+ objectFit="contain"
+ width={1152}
+ height={766}
+ src={focusedImage!}
+ alt={partner.title}
+ />
+ </ImageModal>
+ ) : null}
<DefaultLayout>
<SectionContainer>
<div className="col-span-12 mx-auto mb-2 max-w-5xl space-y-12 lg:col-span-2">
@@ -80,7 +102,7 @@ function Partner({ partner }: { partner: Partner }) {
1024: {
slidesPerView: 4,
},
- 1208: {
+ 1280: {
slidesPerView: 5,
},
}}
@@ -96,6 +118,7 @@ function Partner({ partner }: { partner: Partner }) {
height={960}
src={image}
alt={partner.title}
+ onClick={() => setFocusedImage(image)}
/>
</div>
</SwiperSlide>