figure-modal-options.tsx 4.2 KB

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