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.

6.8 KB
Raw Blame
'use client'

import { Drawer as BaseDrawer } from '@base-ui/react/drawer'
import { cn } from '../cn'
import { focusRingClassName } from '../internal/focus'
import { resolveClassName } from '../internal/resolve-class-name'

const Drawer = BaseDrawer.Root
const DrawerProvider = BaseDrawer.Provider
const DrawerIndent = BaseDrawer.Indent
const DrawerIndentBackground = BaseDrawer.IndentBackground
const DrawerSwipeArea = BaseDrawer.SwipeArea
const DrawerPortal = BaseDrawer.Portal
const DrawerTitle = BaseDrawer.Title
const DrawerDescription = BaseDrawer.Description
const DrawerClose = BaseDrawer.Close
const DrawerVirtualKeyboardProvider = BaseDrawer.VirtualKeyboardProvider
const createDrawerHandle = BaseDrawer.createHandle

type DrawerActions = BaseDrawer.Root.Actions
type DrawerSnapPoint = BaseDrawer.Root.SnapPoint
type DrawerChangeEventReason = BaseDrawer.Root.ChangeEventReason
type DrawerChangeEventDetails = BaseDrawer.Root.ChangeEventDetails
type DrawerSnapPointChangeEventReason = BaseDrawer.Root.SnapPointChangeEventReason
type DrawerSnapPointChangeEventDetails = BaseDrawer.Root.SnapPointChangeEventDetails

type DrawerProps<Payload = unknown> = BaseDrawer.Root.Props<Payload>
type DrawerHandle<Payload = unknown> = BaseDrawer.Handle<Payload>
type DrawerProviderProps = BaseDrawer.Provider.Props
type DrawerIndentProps = BaseDrawer.Indent.Props
type DrawerIndentBackgroundProps = BaseDrawer.IndentBackground.Props
type DrawerTriggerProps<Payload = unknown> = BaseDrawer.Trigger.Props<Payload>

function DrawerTrigger<Payload = unknown>({ className, ...props }: DrawerTriggerProps<Payload>) {
  return (
    <BaseDrawer.Trigger
      className={(state) => cn(focusRingClassName, resolveClassName(className, state))}
      {...props}
    />
  )
}
type DrawerSwipeAreaProps = BaseDrawer.SwipeArea.Props
type DrawerPortalProps = BaseDrawer.Portal.Props
type DrawerTitleProps = BaseDrawer.Title.Props
type DrawerDescriptionProps = BaseDrawer.Description.Props
type DrawerCloseProps = BaseDrawer.Close.Props
type DrawerVirtualKeyboardProviderProps = BaseDrawer.VirtualKeyboardProvider.Props

type DrawerBackdropProps = BaseDrawer.Backdrop.Props

function DrawerBackdrop({ className, ...props }: DrawerBackdropProps) {
  return (
    <BaseDrawer.Backdrop
      className={(state) =>
        cn(
          'absolute inset-0 bg-background-overlay opacity-[calc(1-var(--drawer-swipe-progress,0))]',
          'transition-opacity duration-200 data-ending-style:opacity-0 data-starting-style:opacity-0 data-swiping:duration-0 motion-reduce:transition-none',
          resolveClassName(className, state),
        )
      }
      {...props}
    />
  )
}

type DrawerViewportProps = BaseDrawer.Viewport.Props

function DrawerViewport({ className, ...props }: DrawerViewportProps) {
  return (
    <BaseDrawer.Viewport
      className={(state) =>
        cn(
          'fixed inset-0 touch-none overflow-hidden overscroll-contain outline-hidden',
          resolveClassName(className, state),
        )
      }
      {...props}
    />
  )
}

type DrawerPopupProps = BaseDrawer.Popup.Props

function DrawerPopup({ className, ...props }: DrawerPopupProps) {
  return (
    <BaseDrawer.Popup
      className={(state) =>
        cn(
          'fixed flex min-h-0 touch-none flex-col overflow-hidden bg-components-panel-bg text-text-primary shadow-xl ring-[0.5px] ring-components-panel-border outline-hidden',
          'transition-[transform,opacity,box-shadow] duration-200 data-swiping:duration-0 data-swiping:select-none motion-reduce:transition-none',
          'data-[swipe-direction=right]:inset-y-0 data-[swipe-direction=right]:right-0 data-[swipe-direction=right]:h-dvh data-[swipe-direction=right]:w-120 data-[swipe-direction=right]:max-w-[calc(100vw-2rem)] data-[swipe-direction=right]:transform-[translateX(var(--drawer-swipe-movement-x,0px))] data-[swipe-direction=right]:rounded-l-2xl',
          'data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(100%+2px))] data-starting-style:data-[swipe-direction=right]:transform-[translateX(calc(100%+2px))]',
          'data-[swipe-direction=left]:inset-y-0 data-[swipe-direction=left]:left-0 data-[swipe-direction=left]:h-dvh data-[swipe-direction=left]:w-120 data-[swipe-direction=left]:max-w-[calc(100vw-2rem)] data-[swipe-direction=left]:transform-[translateX(var(--drawer-swipe-movement-x,0px))] data-[swipe-direction=left]:rounded-r-2xl',
          'data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(-100%-2px))] data-starting-style:data-[swipe-direction=left]:transform-[translateX(calc(-100%-2px))]',
          'data-[swipe-direction=down]:inset-x-0 data-[swipe-direction=down]:bottom-0 data-[swipe-direction=down]:max-h-[calc(100dvh-2rem)] data-[swipe-direction=down]:w-full data-[swipe-direction=down]:transform-[translateY(calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px)))] data-[swipe-direction=down]:rounded-t-2xl',
          'data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(100%+2px))] data-starting-style:data-[swipe-direction=down]:transform-[translateY(calc(100%+2px))]',
          'data-[swipe-direction=up]:inset-x-0 data-[swipe-direction=up]:top-0 data-[swipe-direction=up]:max-h-[calc(100dvh-2rem)] data-[swipe-direction=up]:w-full data-[swipe-direction=up]:transform-[translateY(var(--drawer-swipe-movement-y,0px))] data-[swipe-direction=up]:rounded-b-2xl',
          'data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(-100%-2px))] data-starting-style:data-[swipe-direction=up]:transform-[translateY(calc(-100%-2px))]',
          resolveClassName(className, state),
        )
      }
      {...props}
    />
  )
}

type DrawerContentProps = BaseDrawer.Content.Props

function DrawerContent({ className, ...props }: DrawerContentProps) {
  return (
    <BaseDrawer.Content
      className={(state) =>
        cn(
          'flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain',
          resolveClassName(className, state),
        )
      }
      {...props}
    />
  )
}

export {
  createDrawerHandle,
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerIndent,
  DrawerIndentBackground,
  DrawerPopup,
  DrawerPortal,
  DrawerProvider,
  DrawerSwipeArea,
  DrawerTitle,
  DrawerTrigger,
  DrawerViewport,
  DrawerVirtualKeyboardProvider,
}

export type {
  DrawerActions,
  DrawerBackdropProps,
  DrawerChangeEventDetails,
  DrawerChangeEventReason,
  DrawerCloseProps,
  DrawerContentProps,
  DrawerDescriptionProps,
  DrawerHandle,
  DrawerIndentBackgroundProps,
  DrawerIndentProps,
  DrawerPopupProps,
  DrawerPortalProps,
  DrawerProps,
  DrawerProviderProps,
  DrawerSnapPoint,
  DrawerSnapPointChangeEventDetails,
  DrawerSnapPointChangeEventReason,
  DrawerSwipeAreaProps,
  DrawerTitleProps,
  DrawerTriggerProps,
  DrawerViewportProps,
  DrawerVirtualKeyboardProviderProps,
}