figure-modal-options.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { FC } from 'react'
  2. import Icon from '@/shared/components/icon'
  3. import {
  4. useFigureModalContext,
  5. useFigureModalExistingFigureContext,
  6. } from './figure-modal-context'
  7. import { useTranslation } from 'react-i18next'
  8. import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
  9. import OLFormGroup from '@/features/ui/components/ol/ol-form-group'
  10. import OLFormCheckbox from '@/features/ui/components/ol/ol-form-checkbox'
  11. import OLFormText from '@/features/ui/components/ol/ol-form-text'
  12. import OLToggleButtonGroup from '@/features/ui/components/ol/ol-toggle-button-group'
  13. import OLToggleButton from '@/features/ui/components/ol/ol-toggle-button'
  14. import MaterialIcon from '@/shared/components/material-icon'
  15. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  16. import { bsVersion } from '@/features/utils/bootstrap-5'
  17. export const FigureModalFigureOptions: FC = () => {
  18. const { t } = useTranslation()
  19. const { includeCaption, includeLabel, dispatch, width } =
  20. useFigureModalContext()
  21. const { hasComplexGraphicsArgument } = useFigureModalExistingFigureContext()
  22. return (
  23. <>
  24. <OLFormGroup>
  25. <OLFormCheckbox
  26. id="figure-modal-caption"
  27. data-cy="include-caption-option"
  28. defaultChecked={includeCaption}
  29. onChange={event => dispatch({ includeCaption: event.target.checked })}
  30. className={bsVersion({ bs3: 'figure-modal-checkbox-input' })}
  31. label={t('include_caption')}
  32. />
  33. </OLFormGroup>
  34. <OLFormGroup>
  35. <OLFormCheckbox
  36. id="figure-modal-label"
  37. data-cy="include-label-option"
  38. defaultChecked={includeLabel}
  39. onChange={event => dispatch({ includeLabel: event.target.checked })}
  40. className={bsVersion({ bs3: 'figure-modal-checkbox-input' })}
  41. label={
  42. <span className="figure-modal-label-content">
  43. {t('include_label')}
  44. <OLFormText className={bsVersion({ bs3: 'mt-1 text-muted' })}>
  45. {t(
  46. 'used_when_referring_to_the_figure_elsewhere_in_the_document'
  47. )}
  48. </OLFormText>
  49. </span>
  50. }
  51. />
  52. </OLFormGroup>
  53. <OLFormGroup className="mb-0">
  54. <div className="figure-modal-switcher-input">
  55. <div>
  56. {t('image_width')}{' '}
  57. {hasComplexGraphicsArgument ? (
  58. <OLTooltip
  59. id="figure-modal-image-width-warning-tooltip"
  60. description={t('a_custom_size_has_been_used_in_the_latex_code')}
  61. overlayProps={{ delay: 0, placement: 'top' }}
  62. >
  63. <span>
  64. <BootstrapVersionSwitcher
  65. bs3={<Icon type="exclamation-triangle" fw />}
  66. bs5={
  67. <MaterialIcon
  68. type="warning"
  69. className="align-text-bottom"
  70. />
  71. }
  72. />
  73. </span>
  74. </OLTooltip>
  75. ) : (
  76. <OLTooltip
  77. id="figure-modal-image-width-tooltip"
  78. description={t(
  79. 'the_width_you_choose_here_is_based_on_the_width_of_the_text_in_your_document'
  80. )}
  81. overlayProps={{ delay: 0, placement: 'bottom' }}
  82. >
  83. <span>
  84. <BootstrapVersionSwitcher
  85. bs3={<Icon type="question-circle" fw />}
  86. bs5={
  87. <MaterialIcon type="help" className="align-text-bottom" />
  88. }
  89. />
  90. </span>
  91. </OLTooltip>
  92. )}
  93. </div>
  94. <OLToggleButtonGroup
  95. type="radio"
  96. name="figure-width"
  97. onChange={value => dispatch({ width: parseFloat(value) })}
  98. defaultValue={width === 1 ? '1.0' : width?.toString()}
  99. aria-label={t('image_width')}
  100. >
  101. <OLToggleButton
  102. variant="secondary"
  103. id="width-25p"
  104. disabled={hasComplexGraphicsArgument}
  105. value="0.25"
  106. >
  107. {t('1_4_width')}
  108. </OLToggleButton>
  109. <OLToggleButton
  110. variant="secondary"
  111. id="width-50p"
  112. disabled={hasComplexGraphicsArgument}
  113. value="0.5"
  114. >
  115. {t('1_2_width')}
  116. </OLToggleButton>
  117. <OLToggleButton
  118. variant="secondary"
  119. id="width-75p"
  120. disabled={hasComplexGraphicsArgument}
  121. value="0.75"
  122. >
  123. {t('3_4_width')}
  124. </OLToggleButton>
  125. <OLToggleButton
  126. variant="secondary"
  127. id="width-100p"
  128. disabled={hasComplexGraphicsArgument}
  129. value="1.0"
  130. >
  131. {t('full_width')}
  132. </OLToggleButton>
  133. </OLToggleButtonGroup>
  134. </div>
  135. </OLFormGroup>
  136. </>
  137. )
  138. }