-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add type string to switch case * add celsius/fahrenheit inputs, metadata, conversion method in RingdownForm class * Brute force approach handling temperature conversion in Ringdown. Alternate approaches in comment. * comment out celsius field metadata * TemperatureField.js file created * Temperature control created * FormMultiField component/stylesheet wrapper created * add key to mapped children in FormMultiField.js * remove unnecessary comments
- Loading branch information
1 parent
01a1e91
commit 9eabe17
Showing
5 changed files
with
107 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import './FormMultiField.scss'; | ||
|
||
const FormMultiField = ({ label, children }) => { | ||
return ( | ||
<> | ||
{label} | ||
<div className="multi-field"> | ||
{children.map((child) => { | ||
return ( | ||
<div key={child.props.metadata.name} className="multi-field__input"> | ||
{child} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default FormMultiField; |
4 changes: 2 additions & 2 deletions
4
client/src/EMS/BloodPressureField.scss → client/src/Components/FormMultiField.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState } from 'react'; | ||
import { useForm } from '../Components/Form'; | ||
import FormInput from '../Components/FormInput'; | ||
|
||
import { ValidationState } from '../Models/PatientFieldData'; | ||
import classNames from 'classnames'; | ||
|
||
import FormMultiField from '../Components/FormMultiField'; | ||
|
||
const TemperatureInput = ({ metadata, unit, onChange, value }) => { | ||
const { data } = useForm(); | ||
const { name, range = {} } = metadata || {}; | ||
const { min, max } = range; | ||
|
||
return ( | ||
<FormInput | ||
type="number" | ||
property={name} | ||
value={data[name] || value} | ||
validationState={data.getValidationState(name)} | ||
unit={unit || metadata?.unit} | ||
min={min} | ||
max={max} | ||
onChange={onChange} | ||
/> | ||
); | ||
}; | ||
|
||
const TemperatureField = ({ temperatureMetadata }) => { | ||
const { data, onChange } = useForm(); | ||
const [celsius, setCelsius] = useState(''); | ||
const celsiusMetadata = { name: 'celsius', unit: '°C', range: { min: 26.5, max: 65.5 } }; | ||
|
||
const hasError = data.getValidationState(temperatureMetadata.name) === ValidationState.RANGE_ERROR; | ||
|
||
const handleOnChange = (name, value) => { | ||
if (name === 'celsius') { | ||
onChange('temperature', (parseFloat(value) * 1.8 + 32).toFixed(2)); | ||
setCelsius(value); | ||
} else { | ||
onChange(name, value); | ||
setCelsius(((parseFloat(value) - 32) / 1.8).toFixed(2)); | ||
} | ||
}; | ||
return ( | ||
<> | ||
<FormMultiField | ||
label={ | ||
<label htmlFor={temperatureMetadata.name} className={classNames('usa-label', { 'usa-label--error': hasError })}> | ||
Temperature | ||
</label> | ||
} | ||
> | ||
<TemperatureInput metadata={temperatureMetadata} onChange={handleOnChange} /> | ||
<TemperatureInput metadata={celsiusMetadata} value={celsius} onChange={handleOnChange} /> | ||
</FormMultiField> | ||
</> | ||
); | ||
}; | ||
|
||
export default TemperatureField; |