figure-modal-source-picker.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { FC } from 'react'
  2. import {
  3. FigureModalSource,
  4. useFigureModalContext,
  5. } from './figure-modal-context'
  6. import Icon from '../../../../shared/components/icon'
  7. import { useTranslation } from 'react-i18next'
  8. import getMeta from '@/utils/meta'
  9. import MaterialIcon from '@/shared/components/material-icon'
  10. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  11. import { bsVersion } from '@/features/utils/bootstrap-5'
  12. export const FigureModalSourcePicker: FC = () => {
  13. const { t } = useTranslation()
  14. const {
  15. hasLinkedProjectFileFeature,
  16. hasLinkedProjectOutputFileFeature,
  17. hasLinkUrlFeature,
  18. } = getMeta('ol-ExposedSettings')
  19. return (
  20. <div className="figure-modal-source-button-grid">
  21. <FigureModalSourceButton
  22. type={FigureModalSource.FILE_UPLOAD}
  23. title={t('replace_from_computer')}
  24. icon={bsVersion({ bs3: 'upload', bs5: 'upload' })}
  25. />
  26. <FigureModalSourceButton
  27. type={FigureModalSource.FILE_TREE}
  28. title={t('replace_from_project_files')}
  29. icon={bsVersion({ bs3: 'archive', bs5: 'inbox' })}
  30. />
  31. {(hasLinkedProjectFileFeature || hasLinkedProjectOutputFileFeature) && (
  32. <FigureModalSourceButton
  33. type={FigureModalSource.OTHER_PROJECT}
  34. title={t('replace_from_another_project')}
  35. icon={bsVersion({ bs3: 'folder-open', bs5: 'folder_open' })}
  36. />
  37. )}
  38. {hasLinkUrlFeature && (
  39. <FigureModalSourceButton
  40. type={FigureModalSource.FROM_URL}
  41. title={t('replace_from_url')}
  42. icon={bsVersion({ bs3: 'globe', bs5: 'public' })}
  43. />
  44. )}
  45. </div>
  46. )
  47. }
  48. const FigureModalSourceButton: FC<{
  49. type: FigureModalSource
  50. title: string
  51. icon: string
  52. }> = ({ type, title, icon }) => {
  53. const { dispatch } = useFigureModalContext()
  54. return (
  55. <button
  56. type="button"
  57. className="figure-modal-source-button"
  58. onClick={() => {
  59. dispatch({ source: type, sourcePickerShown: false, getPath: undefined })
  60. }}
  61. >
  62. <BootstrapVersionSwitcher
  63. bs3={
  64. <Icon type={icon} className="figure-modal-source-button-icon" fw />
  65. }
  66. bs5={
  67. <MaterialIcon
  68. type={icon}
  69. className="figure-modal-source-button-icon"
  70. />
  71. }
  72. />
  73. <span className="figure-modal-source-button-title">{title}</span>
  74. <BootstrapVersionSwitcher
  75. bs3={<Icon type="chevron-right" fw />}
  76. bs5={<MaterialIcon type="chevron_right" />}
  77. />
  78. </button>
  79. )
  80. }