add a color option
This commit is contained in:
+26
-1
@@ -12,6 +12,7 @@ function App() {
|
|||||||
const [boxID, setBoxID] = useState(undefined);
|
const [boxID, setBoxID] = useState(undefined);
|
||||||
const [boxName, setBoxName] = useState('');
|
const [boxName, setBoxName] = useState('');
|
||||||
const [boxDescription, setBoxDescription] = useState('');
|
const [boxDescription, setBoxDescription] = useState('');
|
||||||
|
const [boxColor, setBoxColor] = useState(0);
|
||||||
|
|
||||||
const [showModalBox, setShowModalBox] = useState(false);
|
const [showModalBox, setShowModalBox] = useState(false);
|
||||||
const [showModalItem, setShowModalItem] = useState(false);
|
const [showModalItem, setShowModalItem] = useState(false);
|
||||||
@@ -116,6 +117,10 @@ function App() {
|
|||||||
setBoxDescription(e.target.value);
|
setBoxDescription(e.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleColorBox = (event) => {
|
||||||
|
setBoxColor(parseInt(event.target.value));
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmitBox = (event) => {
|
const handleSubmitBox = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setShowModalBox(false);
|
setShowModalBox(false);
|
||||||
@@ -123,7 +128,8 @@ function App() {
|
|||||||
const boxData = {
|
const boxData = {
|
||||||
id: boxID,
|
id: boxID,
|
||||||
name: boxName,
|
name: boxName,
|
||||||
description: boxDescription
|
description: boxDescription,
|
||||||
|
color: boxColor
|
||||||
};
|
};
|
||||||
if (editBoxBool)
|
if (editBoxBool)
|
||||||
editBox(boxData);
|
editBox(boxData);
|
||||||
@@ -147,6 +153,7 @@ function App() {
|
|||||||
setEditBoxBool(true);
|
setEditBoxBool(true);
|
||||||
setBoxName(box.name);
|
setBoxName(box.name);
|
||||||
setBoxDescription(box.description);
|
setBoxDescription(box.description);
|
||||||
|
setBoxColor(box.color);
|
||||||
setBoxID(id);
|
setBoxID(id);
|
||||||
setShowModalBox(true);
|
setShowModalBox(true);
|
||||||
}
|
}
|
||||||
@@ -194,6 +201,7 @@ function App() {
|
|||||||
handleRemove: handleRemoveBox,
|
handleRemove: handleRemoveBox,
|
||||||
handleName: handleNameBox,
|
handleName: handleNameBox,
|
||||||
handleDescription: handleBoxDescription,
|
handleDescription: handleBoxDescription,
|
||||||
|
handleColor: handleColorBox,
|
||||||
handleEdit: handleEditBox,
|
handleEdit: handleEditBox,
|
||||||
handleDragStart: handleDragStartBox,
|
handleDragStart: handleDragStartBox,
|
||||||
handleDragOver: handleDragOverBox,
|
handleDragOver: handleDragOverBox,
|
||||||
@@ -344,6 +352,22 @@ function App() {
|
|||||||
const handleClearFilter = () => {
|
const handleClearFilter = () => {
|
||||||
setFilter('');
|
setFilter('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const colors = {
|
||||||
|
default: 0,
|
||||||
|
red: 1,
|
||||||
|
green: 2,
|
||||||
|
};
|
||||||
|
const colorSelector =
|
||||||
|
<div className="color-selector-container">
|
||||||
|
<label className={`${boxColor === colors.red ? "selected" : null} color`} htmlFor="color">
|
||||||
|
<input checked={boxColor === colors.red} onChange={boxHandler.handleColor} id="color" type="radio" value={colors.red}></input>
|
||||||
|
</label>
|
||||||
|
<label className={`${boxColor === colors.green ? "selected" : null} color`} htmlFor="color">
|
||||||
|
<input checked={boxColor === colors.green} onChange={boxHandler.handleColor} id="color" type="radio" value={colors.green}></input>
|
||||||
|
</label>
|
||||||
|
</div>;
|
||||||
|
|
||||||
const boxForm =
|
const boxForm =
|
||||||
<form onSubmit={boxHandler.handleSubmit}>
|
<form onSubmit={boxHandler.handleSubmit}>
|
||||||
<input id="id" name="id" value={boxID} readOnly hidden></input>
|
<input id="id" name="id" value={boxID} readOnly hidden></input>
|
||||||
@@ -355,6 +379,7 @@ function App() {
|
|||||||
<label htmlFor="box-description">description
|
<label htmlFor="box-description">description
|
||||||
<input onChange={boxHandler.handleDescription} value={boxDescription} id="box-description" name="description" type="text" />
|
<input onChange={boxHandler.handleDescription} value={boxDescription} id="box-description" name="description" type="text" />
|
||||||
</label>
|
</label>
|
||||||
|
{colorSelector}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<button type="submit">submit</button>
|
<button type="submit">submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -297,3 +297,23 @@ button.button:hover {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.color-selector-container {
|
||||||
|
display: grid;
|
||||||
|
}
|
||||||
|
.color-selector-container > .color {
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: red;
|
||||||
|
width: 2em;
|
||||||
|
height: 2em;
|
||||||
|
}
|
||||||
|
.color-selector-container > .color.selected {
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
.color-selector-container > .color:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.color-selector-container > .color > input[type=radio] {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ var boxSchema = new mongoose.Schema({
|
|||||||
description: String,
|
description: String,
|
||||||
item: [itemSchema],
|
item: [itemSchema],
|
||||||
sort: Number,
|
sort: Number,
|
||||||
|
color: Number,
|
||||||
});
|
});
|
||||||
|
|
||||||
//compile schema into model
|
//compile schema into model
|
||||||
|
|||||||
Reference in New Issue
Block a user