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.

4.1 KB
Raw Blame
import type { FC } from 'react'
import { cn } from '@langgenius/dify-ui/cn'
import { Popover, PopoverContent, PopoverTrigger } from '@langgenius/dify-ui/popover'
import { RiArrowDownSLine } from '@remixicon/react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'

type MethodSelectorProps = {
  value?: string
  onChange: (v: string) => void
}
const MethodSelector: FC<MethodSelectorProps> = ({ value, onChange }) => {
  const { t } = useTranslation(['tools'])
  const [open, setOpen] = useState(false)
  const handleSelect = (value: string) => {
    onChange(value)
    setOpen(false)
  }

  return (
    <Popover open={open} onOpenChange={setOpen}>
      <div className="relative">
        <PopoverTrigger
          nativeButton={false}
          render={
            <div
              className={cn(
                'flex h-9 min-h-14 cursor-pointer items-center gap-1 bg-transparent px-3 py-2 hover:bg-background-section-burn',
                'data-popup-open:bg-background-section-burn! data-popup-open:hover:bg-background-section-burn',
              )}
            >
              <div className={cn('grow truncate text-[13px] leading-4.5 text-text-secondary')}>
                {value === 'llm'
                  ? t(($) => $['createTool.toolInput.methodParameter'], { ns: 'tools' })
                  : t(($) => $['createTool.toolInput.methodSetting'], { ns: 'tools' })}
              </div>
              <div className="ml-1 shrink-0 text-text-secondary opacity-60">
                <RiArrowDownSLine className="size-4" />
              </div>
            </div>
          }
        />
        <PopoverContent align="start" sideOffset={4}>
          <div className="relative w-[320px]">
            <div className="p-1">
              <button
                type="button"
                className="block w-full cursor-pointer rounded-lg border-none bg-transparent py-2.5 pr-2 pl-3 text-left hover:bg-components-panel-on-panel-item-bg-hover"
                onClick={() => handleSelect('llm')}
              >
                <div className="flex items-center gap-1">
                  <div className="size-4 shrink-0">
                    {value === 'llm' && (
                      <span
                        aria-hidden
                        className="i-custom-vender-line-general-check size-4 shrink-0 text-text-accent"
                      />
                    )}
                  </div>
                  <div className="text-[13px] leading-4.5 font-medium text-text-secondary">
                    {t(($) => $['createTool.toolInput.methodParameter'], { ns: 'tools' })}
                  </div>
                </div>
                <div className="pl-5 text-[13px] leading-4.5 text-text-tertiary">
                  {t(($) => $['createTool.toolInput.methodParameterTip'], { ns: 'tools' })}
                </div>
              </button>
              <button
                type="button"
                className="block w-full cursor-pointer rounded-lg border-none bg-transparent py-2.5 pr-2 pl-3 text-left hover:bg-components-panel-on-panel-item-bg-hover"
                onClick={() => handleSelect('form')}
              >
                <div className="flex items-center gap-1">
                  <div className="size-4 shrink-0">
                    {value === 'form' && (
                      <span
                        aria-hidden
                        className="i-custom-vender-line-general-check size-4 shrink-0 text-text-accent"
                      />
                    )}
                  </div>
                  <div className="text-[13px] leading-4.5 font-medium text-text-secondary">
                    {t(($) => $['createTool.toolInput.methodSetting'], { ns: 'tools' })}
                  </div>
                </div>
                <div className="pl-5 text-[13px] leading-4.5 text-text-tertiary">
                  {t(($) => $['createTool.toolInput.methodSettingTip'], { ns: 'tools' })}
                </div>
              </button>
            </div>
          </div>
        </PopoverContent>
      </div>
    </Popover>
  )
}

export default MethodSelector