-
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.
[#272] Make numeric field widths consistent
* Add BloodPressureField component to handle BP entry Apply custom styles to BloodPressureField so the fields and error messages lay out correctly. Simplify range validation error message. Revert the FormInput changes, and remove the valueAsNumber prop, which isn't settable. Revert changes in _uswds-theme-custom-styles.scss. * Show an error state on the blood pressure label for range errors Fix the layout of the O2 field and range error. --------- Co-authored-by: Francis Li <francisli@users.noreply.github.com>
- Loading branch information
1 parent
ba8ec63
commit 40c5814
Showing
6 changed files
with
127 additions
and
68 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
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,57 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { ValidationState } from '../Models/PatientFieldData'; | ||
import FormInput from '../Components/FormInput'; | ||
import { useForm } from '../Components/Form'; | ||
|
||
import './BloodPressureField.scss'; | ||
|
||
function BPInput({ metadata, unit }) { | ||
const { data, onChange } = useForm(); | ||
const { name, range = {} } = metadata; | ||
const { min, max } = range; | ||
|
||
return ( | ||
// we need to add a wrapper around the FormInput component because it outputs | ||
// multiple children in a fragment. we need each input's error message to be | ||
// grouped with its input in a div because the fields are arranged horizontally | ||
// in a row. since the errors are absolutely positioned, they'd both shift to | ||
// the left margin of the .bpfield without this extra div, causing an overlap. | ||
<div className="bpfield__input"> | ||
<FormInput | ||
type="number" | ||
property={name} | ||
value={data[name]} | ||
validationState={data.getValidationState(name)} | ||
unit={unit || metadata.unit} | ||
min={min} | ||
max={max} | ||
onChange={onChange} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default function BloodPressureField({ systolicMetadata, diastolicMetadata }) { | ||
const { data } = useForm(); | ||
const validations = [data.getValidationState(systolicMetadata.name), data.getValidationState(diastolicMetadata.name)]; | ||
const hasError = validations.includes(ValidationState.RANGE_ERROR); | ||
|
||
return ( | ||
<> | ||
<label htmlFor={systolicMetadata.name} className={classNames('usa-label', { 'usa-label--error': hasError })}> | ||
Blood pressure | ||
</label> | ||
<div className="bpfield"> | ||
<BPInput metadata={systolicMetadata} unit="/" /> | ||
<BPInput metadata={diastolicMetadata} unit="mmHG" /> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
BloodPressureField.propTypes = { | ||
systolicMetadata: PropTypes.object.isRequired, | ||
diastolicMetadata: PropTypes.object.isRequired, | ||
}; |
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,22 @@ | ||
@import '../theme/base'; | ||
|
||
.bpfield { | ||
display: flex; | ||
gap: 0.6rem; | ||
position: relative; | ||
} | ||
|
||
.bpfield__input { | ||
.grid-row { | ||
flex-wrap: nowrap; | ||
} | ||
|
||
.usa-input { | ||
width: 13ex; | ||
} | ||
|
||
.usa-error-message { | ||
top: 3rem; | ||
max-width: 9rem; | ||
} | ||
} |
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