variable-trigger.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use client'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { RiAddLine } from '@remixicon/react'
  5. import Button from '@/app/components/base/button'
  6. import VariableModal from '@/app/components/workflow/panel/env-panel/variable-modal'
  7. import {
  8. PortalToFollowElem,
  9. PortalToFollowElemContent,
  10. PortalToFollowElemTrigger,
  11. } from '@/app/components/base/portal-to-follow-elem'
  12. import type { EnvironmentVariable } from '@/app/components/workflow/types'
  13. type Props = {
  14. open: boolean
  15. setOpen: (value: React.SetStateAction<boolean>) => void
  16. env?: EnvironmentVariable
  17. onClose: () => void
  18. onSave: (env: EnvironmentVariable) => void
  19. }
  20. const VariableTrigger = ({
  21. open,
  22. setOpen,
  23. env,
  24. onClose,
  25. onSave,
  26. }: Props) => {
  27. const { t } = useTranslation()
  28. return (
  29. <PortalToFollowElem
  30. open={open}
  31. onOpenChange={() => {
  32. setOpen(v => !v)
  33. open && onClose()
  34. }}
  35. placement='left-start'
  36. offset={{
  37. mainAxis: 8,
  38. alignmentAxis: -104,
  39. }}
  40. >
  41. <PortalToFollowElemTrigger onClick={() => {
  42. setOpen(v => !v)
  43. open && onClose()
  44. }}>
  45. <Button variant='primary'>
  46. <RiAddLine className='mr-1 w-4 h-4' />
  47. <span className='system-sm-medium'>{t('workflow.env.envPanelButton')}</span>
  48. </Button>
  49. </PortalToFollowElemTrigger>
  50. <PortalToFollowElemContent className='z-[11]'>
  51. <VariableModal
  52. env={env}
  53. onSave={onSave}
  54. onClose={() => {
  55. onClose()
  56. setOpen(false)
  57. }}
  58. />
  59. </PortalToFollowElemContent>
  60. </PortalToFollowElem>
  61. )
  62. }
  63. export default VariableTrigger