figure-modal-options.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { FC } from 'react'
  2. import Icon from '../../../../shared/components/icon'
  3. import Tooltip from '../../../../shared/components/tooltip'
  4. import {
  5. useFigureModalContext,
  6. useFigureModalExistingFigureContext,
  7. } from './figure-modal-context'
  8. import { Switcher, SwitcherItem } from '../../../../shared/components/switcher'
  9. import { useTranslation } from 'react-i18next'
  10. export const FigureModalFigureOptions: FC = () => {
  11. const { t } = useTranslation()
  12. const { includeCaption, includeLabel, dispatch, width } =
  13. useFigureModalContext()
  14. const { hasComplexGraphicsArgument } = useFigureModalExistingFigureContext()
  15. return (
  16. <>
  17. <div className="figure-modal-checkbox-input">
  18. <input
  19. type="checkbox"
  20. id="figure-modal-caption"
  21. data-cy="include-caption-option"
  22. defaultChecked={includeCaption}
  23. onChange={event => dispatch({ includeCaption: event.target.checked })}
  24. />
  25. <label className="figure-modal-label" htmlFor="figure-modal-caption">
  26. {t('include_caption')}
  27. </label>
  28. </div>
  29. <div className="figure-modal-checkbox-input">
  30. <input
  31. type="checkbox"
  32. id="figure-modal-label"
  33. data-cy="include-label-option"
  34. defaultChecked={includeLabel}
  35. onChange={event => dispatch({ includeLabel: event.target.checked })}
  36. />
  37. <label htmlFor="figure-modal-label" className="mb-0 figure-modal-label">
  38. {t('include_label')}
  39. <br />
  40. <span className="text-muted text-small figure-modal-label-description">
  41. {t('used_when_referring_to_the_figure_elsewhere_in_the_document')}
  42. </span>
  43. </label>
  44. </div>
  45. <div className="figure-modal-switcher-input">
  46. <div>
  47. {t('image_width')}{' '}
  48. {hasComplexGraphicsArgument ? (
  49. <Tooltip
  50. id="figure-modal-image-width-warning-tooltip"
  51. description={t('a_custom_size_has_been_used_in_the_latex_code')}
  52. overlayProps={{ delay: 0, placement: 'top' }}
  53. >
  54. <Icon type="exclamation-triangle" fw />
  55. </Tooltip>
  56. ) : (
  57. <Tooltip
  58. id="figure-modal-image-width-tooltip"
  59. description={t(
  60. 'the_width_you_choose_here_is_based_on_the_width_of_the_text_in_your_document'
  61. )}
  62. overlayProps={{ delay: 0, placement: 'bottom' }}
  63. >
  64. <Icon type="question-circle" fw />
  65. </Tooltip>
  66. )}
  67. </div>
  68. <div>
  69. <Switcher
  70. name="figure-width"
  71. onChange={value => dispatch({ width: parseFloat(value) })}
  72. defaultValue={width === 1 ? '1.0' : width?.toString()}
  73. disabled={hasComplexGraphicsArgument}
  74. >
  75. <SwitcherItem value="0.25" label={t('1_4_width')} />
  76. <SwitcherItem value="0.5" label={t('1_2_width')} />
  77. <SwitcherItem value="0.75" label={t('3_4_width')} />
  78. <SwitcherItem value="1.0" label={t('full_width')} />
  79. </Switcher>
  80. </div>
  81. </div>
  82. </>
  83. )
  84. }