Skip to content

Commit

Permalink
Better add form
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaq committed Oct 5, 2024
1 parent e38c636 commit afe76cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
19 changes: 10 additions & 9 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ function AddForm({ setShow, getItems }) {
}

const fieldsArray = Object.entries(fields).map(([name, label]) => (
<div key={name}>
<label>{label}:
<input type="text" name={name} onChange={changeHandler} />
</label>
<br />
<div key={name} className="field">
<label htmlFor={`add-${name}`}>{label}:</label>
<input type="text" id={`add-${name}`} name={name} onChange={changeHandler} />
</div>
));

Expand Down Expand Up @@ -110,13 +108,16 @@ function AddForm({ setShow, getItems }) {
}

return (
<div className="add-form">
<form onSubmit={submitHandler}>
<form className="add-form" onSubmit={submitHandler}>
<h3>Add item</h3>
<div className="add-form-fields">
{fieldsArray}
</div>
<div className="add-form-footer">
<input type="submit" id="submit-add" value="Add item" />
<button onClick={() => setShow(false)}>Cancel</button>
</form>
</div>
</div>
</form>
);
}

Expand Down
20 changes: 20 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ body {
background-color: pink;
padding: var(--padding);
border-radius: var(--padding);
display: flex;
flex-flow: column nowrap;
gap: var(--padding);
}

.add-form-fields {
display: flex;
flex-flow: column nowrap;
}

.add-form-fields > .field {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}

.add-form-footer {
display: flex;
flex-flow: row nowrap;
justify-content: flex-end;
}

.nutritional-table {
Expand Down

0 comments on commit afe76cd

Please sign in to comment.