import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import { Range } from '@ohif/ui'; import './SegmentationSettings.css'; const SegmentationSettings = ({ configuration, onBack, onChange, disabledFields = [] }) => { const [state, setState] = useState({ renderFill: configuration.renderFill, renderOutline: configuration.renderOutline, shouldRenderInactiveLabelmaps: configuration.shouldRenderInactiveLabelmaps, fillAlpha: configuration.fillAlpha, outlineAlpha: configuration.outlineAlpha, outlineWidth: configuration.outlineWidth, fillAlphaInactive: configuration.fillAlphaInactive, outlineAlphaInactive: configuration.outlineAlphaInactive }); useEffect(() => { onChange(state); }, [state]); const check = field => { setState(state => ({ ...state, [field]: !state[field] })); }; const save = (field, value) => { setState(state => ({ ...state, [field]: value })); }; const toFloat = value => parseFloat(value / 100).toFixed(2); return (

Segmentations Settings

check('renderFill')} /> {state.renderFill && ( save('fillAlpha', toFloat(event.target.value))} showPercentage /> )}
check('renderOutline')} /> {state.renderOutline && ( <> {!disabledFields.includes('outlineAlpha') && ( save('outlineAlpha', toFloat(event.target.value))} /> )} {!disabledFields.includes('outlineWidth') && ( save('outlineWidth', parseInt(event.target.value))} /> )} )}
{(state.renderFill || state.renderOutline) && !disabledFields.includes('shouldRenderInactiveLabelmaps') && (
check('shouldRenderInactiveLabelmaps')} /> {state.shouldRenderInactiveLabelmaps && ( <> {state.renderFill && !disabledFields.includes('fillAlphaInactive') && ( save('fillAlphaInactive', toFloat(event.target.value))} /> )} {state.renderOutline && !disabledFields.includes('outlineAlphaInactive') && ( save('outlineAlphaInactive', toFloat(event.target.value))} /> )} )}
)}
); }; const CustomCheck = ({ label, checked, onChange }) => { return (
); }; const CustomRange = props => { const { label, onChange } = props; return (
{ event.persist(); onChange(event); }} />
); }; SegmentationSettings.propTypes = { configuration: PropTypes.shape({ renderFill: PropTypes.bool.isRequired, renderOutline: PropTypes.bool.isRequired, shouldRenderInactiveLabelmaps: PropTypes.bool.isRequired, fillAlpha: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, /* TODO: why fillAlpha is string? */ outlineAlpha: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, /* TODO: why fillAlpha is string? */ outlineWidth: PropTypes.number.isRequired, fillAlphaInactive: PropTypes.number.isRequired, outlineAlphaInactive: PropTypes.number.isRequired, }).isRequired, onBack: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, }; export default SegmentationSettings;