Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.7 KB
Raw Blame
'use client'
import type { DrawerPopupProps } from '@langgenius/dify-ui/drawer'
import { cn } from '@langgenius/dify-ui/cn'
import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerPopup,
  DrawerPortal,
  DrawerTitle,
  DrawerViewport,
} from '@langgenius/dify-ui/drawer'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { useTranslation } from 'react-i18next'

type IFloatRightContainerProps = Pick<DrawerPopupProps, 'finalFocus'> & {
  presentation: 'drawer' | 'inline'
  isOpen: boolean
  onClose: () => void
  children?: React.ReactNode
  showClose?: boolean
  panelClassName?: string
  title?: string
  mask?: boolean
}

const FloatRightContainer = ({
  presentation,
  children,
  isOpen,
  onClose,
  showClose = false,
  panelClassName,
  title,
  mask = true,
  finalFocus,
}: IFloatRightContainerProps) => {
  const { t } = useTranslation(['common'])

  return (
    <>
      {presentation === 'drawer' && (
        <Drawer
          open={isOpen}
          modal
          swipeDirection="right"
          onOpenChange={(open) => {
            if (!open) onClose()
          }}
        >
          <DrawerPortal>
            <DrawerBackdrop className={cn(!mask && 'bg-transparent')} />
            <DrawerViewport>
              <DrawerPopup
                finalFocus={finalFocus}
                className={cn(
                  'data-[swipe-direction=right]:w-full data-[swipe-direction=right]:max-w-sm',
                  panelClassName,
                )}
              >
                <DrawerContent className="p-6">
                  {(title || showClose) && (
                    <div className="mb-4 flex shrink-0 items-center justify-between">
                      {title && (
                        <DrawerTitle className="text-lg/6 font-medium text-text-primary">
                          {title}
                        </DrawerTitle>
                      )}
                      {showClose && (
                        <DrawerClose
                          render={
                            <IconButton
                              aria-label={t(($) => $['operation.close'], { ns: 'common' })}
                              size="md"
                            >
                              <span aria-hidden="true" className="i-ri-close-line size-4" />
                            </IconButton>
                          }
                        />
                      )}
                    </div>
                  )}
                  {children}
                </DrawerContent>
              </DrawerPopup>
            </DrawerViewport>
          </DrawerPortal>
        </Drawer>
      )}
      {presentation === 'inline' && isOpen && <>{children}</>}
    </>
  )
}

export default FloatRightContainer