Skip to content

Commit a6bfb2f

Browse files
committed
add palette
1 parent e206343 commit a6bfb2f

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

src/App.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,22 @@ function App() {
163163

164164
function addCard(cardData = {}) {
165165
setCards(
166-
cardsArr.concat([new Card({ id: ++cardCount, name: cardData.name, completed: cardData.sel, text: cardData.text })])
166+
cardsArr.concat([new Card({ id: ++cardCount, name: cardData.name, color: cardData.color, text: cardData.text })])
167167
)
168168
}
169169

170-
function changeCardState(index) {
171-
cardsArr[index].completed = !cardsArr[index].completed
170+
function changeCardColor(index, color) {
171+
cardsArr[index].color = color
172172
setCards([...cardsArr])
173173
}
174174

175175
function editCardContent(index, name, text) {
176-
177176
if (cardsArr[index]) {
178177
let card
179178
card = new Card(cardsArr[index])
180179
card.name = name
181180
card.text = text
182-
cardsArr[index]=card
181+
cardsArr[index] = card
183182
}
184183
setCards([...cardsArr])
185184
}
@@ -198,7 +197,7 @@ function App() {
198197
///////////
199198

200199
return (
201-
<Context.Provider value={{ removeCard, changeCardState, setEditCard, unsetEditCard, editCardContent, editCardId }}>
200+
<Context.Provider value={{ removeCard, changeCardColor, setEditCard, unsetEditCard, editCardContent, editCardId }}>
202201
<div className="App pb-3 mb-3">
203202
<header className="p-1">
204203
<nav className="d-flex container px-0 flex-wrap-reverse justify-content-around">

src/Cards/AddCard.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react'
22
import PropTypes from 'prop-types'
33
import TextareaAutosize from 'react-textarea-autosize'
4+
import Palette, { colors } from './palette'
45

56
function useInputValue(defaultValue) {
67
const [value, setValue] = useState(defaultValue)
@@ -16,12 +17,15 @@ function useInputValue(defaultValue) {
1617

1718
function AddCard({ onCreate, onDeleteAll }) {
1819
const input = useInputValue('')
19-
const select = useInputValue(0)
20+
21+
const defColor = colors[0]
22+
const [color, setColor] = React.useState(defColor)
2023

2124
function submitHandler() {
22-
if (String(input.value()).trim() && String(select.value()).trim()) {
23-
onCreate({ name: String(input.value()).trim(), text: "", sel: Boolean(Number(select.value())) })
25+
if (String(input.value()).trim() && String(color).trim()) {
26+
onCreate({ name: String(input.value()).trim(), text: "", color: String(color) })
2427
input.clear()
28+
setColor(defColor)
2529
}
2630
}
2731

@@ -40,10 +44,7 @@ function AddCard({ onCreate, onDeleteAll }) {
4044
</div>
4145

4246
<div className="col-lg-8 col-md-6 col-sm-4 p-1">
43-
<select className="custom-select" id="Status" {...select.bind}>
44-
<option value="1">Done</option>
45-
<option value="0">Not done</option>
46-
</select>
47+
<Palette setColor={setColor} className="btn btn-outline-secondary" style={{ width: "100%" }}></Palette>
4748
</div>
4849

4950
<div className="col-lg-2 col-md-3 col-sm-4 col-6 p-1">

src/Cards/CardItem.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useContext } from 'react'
22
import PropTypes from 'prop-types'
33
import Context from '../context'
44
import Card from '../Shared/Card'
5+
import Palette from './palette'
56

67
function createHTML(text) {
78
let el = document.createElement("p")
@@ -10,15 +11,18 @@ function createHTML(text) {
1011
}
1112

1213
function CardItem(props) {
13-
const { removeCard, changeCardState, setEditCard } = useContext(Context)
14+
const { removeCard, changeCardColor, setEditCard } = useContext(Context)
1415
const { card, index } = props
1516
const cardItem = card && new Card(card)
1617
const lineClip = 12
17-
const [color, btcolor] = cardItem && cardItem.completed ? ["green", "success"] : ["red", "danger"]
18+
const bgColor = cardItem.color
19+
function tryChangeColor(color) {
20+
changeCardColor(index, color)
21+
}
1822
return (
1923

2024
<div className="p-1" >
21-
<div className="card" style={{ color: "white", backgroundColor: color }} >
25+
<div className="card" style={{ backgroundColor: bgColor }} >
2226

2327
<div className="card-body" onClick={() => setEditCard(index)} >
2428
<h5 className="card-title">{cardItem.name}</h5>
@@ -31,19 +35,17 @@ function CardItem(props) {
3135

3236
<div className="card-body pt-0">
3337
<button
34-
className={`btn btn-${btcolor} p-0`}
38+
className={`btn btn-light p-0`}
3539
style={{ width: "1.8em", height: "1.8em", float: "right", borderColor: "transparent", backgroundColor: "transparent" }}
3640
onClick={() => removeCard(index)}
3741
>
3842
&#10007;
3943
</button>
40-
<button
41-
className={`btn btn-${btcolor} p-0 mx-2`}
44+
<Palette
45+
className={`btn btn-light p-0 mx-2`}
4246
style={{ width: "1.8em", height: "1.8em", float: "right", borderColor: "transparent", backgroundColor: "transparent" }}
43-
onClick={() => changeCardState(index)}
44-
>
45-
&#10003;
46-
</button>
47+
setColor={tryChangeColor}
48+
></Palette>
4749
</div>
4850

4951
</div>

src/Cards/ModalCardEdit.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import TextareaAutosize from 'react-textarea-autosize'
55
import Modal, { ModalProps } from "../Shared/Modal/Modal"
66
import debounce from '../Shared/debounce'
77
import Card from '../Shared/Card'
8+
import Palette from './palette'
89

910
function calcMaxRows() {
1011
const small = 576
@@ -20,7 +21,7 @@ function calcMaxRows() {
2021
}
2122

2223
function ModalCardEdit(props) {
23-
const { removeCard, changeCardState, unsetEditCard, editCardContent } = React.useContext(Context)
24+
const { removeCard, changeCardColor, unsetEditCard, editCardContent } = React.useContext(Context)
2425
const { card, index } = props
2526
React.useEffect(() => { if (card !== null) open() }, [card])
2627

@@ -57,8 +58,8 @@ function ModalCardEdit(props) {
5758
save(name, text)
5859
}
5960

60-
function tryStateChange() {
61-
changeCardState(index)
61+
function tryChangeColor(color) {
62+
changeCardColor(index, color)
6263
}
6364
function tryRemove() {
6465
unsetEditCard();
@@ -70,9 +71,6 @@ function ModalCardEdit(props) {
7071
close()
7172
}
7273

73-
// eslint-disable-next-line no-unused-vars
74-
const [color, btcolor] = cardEdit && cardEdit.completed ? ["green", "success"] : ["red", "danger"]
75-
7674
return (
7775
<Modal {...modalProps.bind()}>
7876
<div className="container p-2">
@@ -91,9 +89,9 @@ function ModalCardEdit(props) {
9189
/>
9290

9391
<p style={{ fontWeight: "500" }} className="mb-2 text-dark">
94-
Completed:
95-
<span className={`m-1 d-inline-block text-center badge badge-${btcolor}`} style={{ width: "3em" }}>
96-
{String(cardEdit.completed)}
92+
Color:
93+
<span className={`m-1 d-inline-block text-center badge`} style={{ width: "3em", backgroundColor: cardEdit.color }}>
94+
&nbsp;
9795
</span>
9896
</p>
9997

@@ -114,11 +112,11 @@ function ModalCardEdit(props) {
114112

115113
<div style={{ display: "flex", justifyContent: "space-around", alignItems: "center", flexWrap: "wrap" }}>
116114
<div>
117-
<button
115+
<Palette
118116
className="btn btn-light mx-1"
119117
disabled={!cardEdit}
120-
onClick={tryStateChange}
121-
>&#10003;</button>
118+
setColor={tryChangeColor}
119+
></Palette>
122120
<button
123121
className="btn btn-light"
124122
disabled={!cardEdit}

0 commit comments

Comments
 (0)