index.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { type FC, useMemo } from 'react'
  2. import { RiArrowLeftLine } from '@remixicon/react'
  3. import Link from 'next/link'
  4. import { useTranslation } from 'react-i18next'
  5. import { Stepper, type StepperProps } from '../stepper'
  6. import classNames from '@/utils/classnames'
  7. export type TopBarProps = Pick<StepperProps, 'activeIndex'> & {
  8. className?: string
  9. datasetId?: string
  10. }
  11. const STEP_T_MAP: Record<number, string> = {
  12. 1: 'datasetCreation.steps.one',
  13. 2: 'datasetCreation.steps.two',
  14. 3: 'datasetCreation.steps.three',
  15. }
  16. export const TopBar: FC<TopBarProps> = (props) => {
  17. const { className, datasetId, ...rest } = props
  18. const { t } = useTranslation()
  19. const fallbackRoute = useMemo(() => {
  20. return datasetId ? `/datasets/${datasetId}/documents` : '/datasets'
  21. }, [datasetId])
  22. return <div className={classNames('flex shrink-0 h-[52px] items-center justify-between relative border-b border-b-divider-subtle', className)}>
  23. <Link href={fallbackRoute} replace className="inline-flex h-12 items-center justify-start gap-1 py-2 pl-2 pr-6">
  24. <div className='p-2'>
  25. <RiArrowLeftLine className='size-4 text-text-primary' />
  26. </div>
  27. <p className="system-sm-semibold-uppercase text-text-primary">
  28. {t('datasetCreation.steps.header.fallbackRoute')}
  29. </p>
  30. </Link>
  31. <div className={
  32. 'absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2'
  33. }>
  34. <Stepper
  35. steps={Array.from({ length: 3 }, (_, i) => ({
  36. name: t(STEP_T_MAP[i + 1]),
  37. }))}
  38. {...rest}
  39. />
  40. </div>
  41. </div>
  42. }