-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds BodyData Page with Measurement Form
- Loading branch information
Showing
10 changed files
with
568 additions
and
6 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
117 changes: 117 additions & 0 deletions
117
src/components/bodydata/measurementform/MeasurementForm.js
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,117 @@ | ||
// React | ||
import React from "react"; | ||
import { useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
// Components | ||
import Measurement from "models/Measurement"; | ||
|
||
// Styles | ||
import "./measurements.scss"; | ||
|
||
const MeasurementForm = (props) => { | ||
const { | ||
propstime = Date.now(), | ||
propsweight = "", | ||
propsbodysize = "", | ||
propsheadcircumference = "", | ||
headline = 'new Measurement', | ||
submitText = 'save' | ||
} = props; | ||
|
||
let [time, setTime] = useState(propstime); | ||
let [weight, setWeight] = useState(propsweight); | ||
let [bodySize, setBodySize] = useState(propsbodysize); | ||
let [headCircumference, setHeadCircumference] = useState(propsheadcircumference); | ||
|
||
const onSubmit = (e) => { | ||
e.preventDefault(); | ||
const measurement = new Measurement(time, weight, bodySize, headCircumference); | ||
|
||
setTime(Date.now()); | ||
setWeight(""); | ||
setBodySize(""); | ||
setHeadCircumference(""); | ||
|
||
props.onSubmit(measurement); | ||
}; | ||
|
||
const onDateTimeChanged = (e) => { | ||
if (e.target.value) { | ||
setTime(new Date(e.target.value).getTime()); | ||
} | ||
}; | ||
|
||
const formatTimestampToInputDateTime = (ts) => { | ||
let date = new Date(ts); | ||
let dd = (date.getDate() < 10 ? "0" : "") + date.getDate(); | ||
let MM = (date.getMonth() + 1 < 10 ? "0" : "") + (date.getMonth() + 1); | ||
let yyyy = date.getFullYear(); | ||
let hh = (date.getHours() < 10 ? "0" : "") + date.getHours(); | ||
let mm = (date.getMinutes() < 10 ? "0" : "") + date.getMinutes(); | ||
let str = `${yyyy}-${MM}-${dd}T${hh}:${mm}`; | ||
return str; | ||
}; | ||
|
||
return ( | ||
<form className="measurement_form" onSubmit={onSubmit}> | ||
<fieldset> | ||
<legend>{headline}</legend> | ||
<label htmlFor="time">Time of Measurement</label> | ||
<input | ||
type="datetime-local" | ||
name="time" | ||
id="time" | ||
value={formatTimestampToInputDateTime(time)} | ||
onChange={onDateTimeChanged} | ||
/> | ||
<label htmlFor="weight">Weight (g)</label> | ||
<input | ||
type="number" | ||
className="weight" | ||
id="weight" | ||
placeholder="Weight (g)" | ||
value={weight} | ||
onChange={(e) => { | ||
setWeight(e.target.value); | ||
}} | ||
/> | ||
<label htmlFor="bodySize">Body Size (cm)</label> | ||
<input | ||
type="number" | ||
className="bodySize" | ||
id="bodySize" | ||
placeholder="Body Size (cm)" | ||
value={bodySize} | ||
onChange={(e) => { | ||
setBodySize(e.target.value); | ||
}} | ||
/> | ||
<label htmlFor="headCircumference">Head Circumference (cm)</label> | ||
<input | ||
type="number" | ||
className="headCircumference" | ||
id="headCircumference" | ||
placeholder="Head Circumference (cm)" | ||
value={headCircumference} | ||
onChange={(e) => { | ||
setHeadCircumference(e.target.value); | ||
}} | ||
/> | ||
<input type="submit" value={submitText} className="button" /> | ||
</fieldset> | ||
</form> | ||
); | ||
}; | ||
|
||
MeasurementForm.propTypes = { | ||
time: PropTypes.number, | ||
weight: PropTypes.number, | ||
bodySize: PropTypes.number, | ||
headCircumference: PropTypes.number, | ||
onSubmit: PropTypes.func.isRequired, | ||
headline: PropTypes.string, | ||
submitText: PropTypes.string | ||
}; | ||
|
||
export default MeasurementForm; |
102 changes: 102 additions & 0 deletions
102
src/components/bodydata/measurementform/measurements.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
@import '../../../assets/scss/breakpoints'; | ||
@import '../../../assets/scss/colors'; | ||
|
||
.measurement_form { | ||
display: grid; | ||
gap: 1rem; | ||
grid-template-columns: 1fr 1fr; | ||
grid-template-rows: repeat(7, auto); | ||
grid-template-areas: | ||
"legend legend" | ||
"timelabel timelabel" | ||
"time time" | ||
"weightlabel weightlabel" | ||
"weight weight" | ||
"bodysizelabel bodysizelabel" | ||
"bodysize bodysize" | ||
"headcircumferencelabel headcircumferencelabel" | ||
"headcircumference headcircumference" | ||
"submit submit"; | ||
|
||
fieldset { | ||
display: contents; | ||
|
||
legend { | ||
grid-area: legend; | ||
font-size: 1.4rem; | ||
color: $mid; | ||
font-weight: bold; | ||
} | ||
|
||
input { | ||
border: none; | ||
border-bottom: 1px solid $light; | ||
color: $dark; | ||
outline: none; | ||
width: 100%; | ||
font-size: 1.3rem; | ||
|
||
&:focus { | ||
border-bottom: 1px solid $highlight; | ||
} | ||
} | ||
|
||
label[for=time] { | ||
grid-area: timelabel; | ||
} | ||
|
||
input#time { | ||
grid-area: time; | ||
} | ||
|
||
label[for=weight] { | ||
grid-area: weightlabel; | ||
} | ||
|
||
.weight { | ||
grid-area: weight; | ||
} | ||
|
||
label[for=bodySize] { | ||
grid-area: bodysizelabel; | ||
} | ||
|
||
.bodySize { | ||
grid-area: bodysize; | ||
} | ||
|
||
label[for=headCircumference] { | ||
grid-area: headcircumferencelabel; | ||
} | ||
|
||
.headCircumference { | ||
grid-area: headcircumference; | ||
} | ||
|
||
input[type=submit] { | ||
grid-area: submit; | ||
border: none; | ||
grid-row: 0 / span 2; | ||
} | ||
} | ||
} | ||
|
||
.dark { | ||
.naps_form { | ||
legend { | ||
color: $light; | ||
} | ||
|
||
input { | ||
background-color: transparent; | ||
color: $white; | ||
border-bottom: 1px solid $highlight; | ||
} | ||
|
||
input[type=submit] { | ||
background-color: $highlight; | ||
color: $dark; | ||
border: none; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.