Skip to content

Commit 83d1591

Browse files
author
HigorLoren
committed
✨ Add New Card
1 parent bcfad96 commit 83d1591

File tree

8 files changed

+179
-23
lines changed

8 files changed

+179
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ node_modules
1212
# production
1313
/build
1414

15+
#vscode
16+
.vscode
17+
1518
# misc
1619
.DS_Store
1720
.env.local

src/components/Cards/Card/Card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default class Card extends PureComponent {
152152
className={classes.DashGradientCard}
153153
style={{ background: this.state.dashNewColor }}
154154
/>
155-
<div className="absolute mt3 left-30perc shadow-5 z-3 bg-white br2 flex justify-end flex-wrap">
155+
<div className="absolute mt3 left30 shadow-5 z-3 bg-white br2 flex justify-end flex-wrap">
156156
<TwitterPicker
157157
color={this.state.dashNewColor}
158158
colors={colorsPicker}

src/components/Cards/Card/Card.module.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
.Card {
2+
background-color: #f7f8f9;
3+
min-width: 300px;
4+
}
5+
16
.DashGradientCard {
27
border-radius: 0.5rem 0.5rem 0 0;
38
height: 5px;
49
width: 100%;
510
}
6-
7-
.Card {
8-
background-color: #f7f8f9;
9-
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React, { useState, useEffect } from "react";
2+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3+
4+
const newCardDashColor = "#636363";
5+
6+
const CardBuilder = props => {
7+
const [textInputNameCard, setTextInputNameCard] = useState("New Name");
8+
const [initial, setInitial] = useState(true);
9+
10+
useEffect(() => {
11+
if (!initial) {
12+
props.scrollToNewCard();
13+
}
14+
}, [props, initial]);
15+
16+
const handleLeaveInputNameCard = () => {
17+
setTextInputNameCard("New Name");
18+
setInitial(true);
19+
props.newCard({ name: textInputNameCard, dashColor: newCardDashColor });
20+
};
21+
22+
const handleKeyDown = event => {
23+
if (event.key === "Enter") {
24+
handleLeaveInputNameCard();
25+
}
26+
};
27+
28+
return initial ? (
29+
<div className="w-25 flex" style={{ minWidth: "300px", minHeight: "270px" }}>
30+
<div
31+
onClick={() => setInitial(false)}
32+
className="mh3 br3 w-100 pa3 black-05 bg-black-03 flex justify-center items-center dim pointer"
33+
>
34+
<FontAwesomeIcon icon="plus-circle" size="2x" />
35+
</div>
36+
</div>
37+
) : (
38+
<div id="newCard">
39+
<div
40+
className="w-25 mh3 pb2 br3 shadow-6 relative"
41+
style={{ minWidth: "300px", backgroundColor: "#f7f8f9" }}
42+
>
43+
<div
44+
style={{
45+
background: newCardDashColor,
46+
borderRadius: "0.5rem 0.5rem 0 0",
47+
height: "5px",
48+
width: "100%"
49+
}}
50+
/>
51+
<div className="ph3">
52+
<div className="flex mt3 mb4 justify-between items-center relative">
53+
<input
54+
type="text"
55+
autoFocus
56+
onFocus={({ target }) => target.select()}
57+
name="cardName"
58+
defaultValue={textInputNameCard}
59+
onBlur={handleLeaveInputNameCard}
60+
onKeyDown={handleKeyDown}
61+
onChange={event => setTextInputNameCard(event.target.value)}
62+
className="f4 w-100 br2 bw1 b--moon-gray b--solid outline-0 ph2 gray ma0 fw5"
63+
/>
64+
<button className="button-reset pointer gray hover-mid-gray textshadow-1">
65+
<FontAwesomeIcon icon="ellipsis-v" className="" />
66+
</button>
67+
</div>
68+
<form className="w-100 mb2">
69+
<div className="flex mt-4 mb-1">
70+
<input
71+
type="text"
72+
className="w-90 br2 pv1 pl3 bn shadow-6 lh-copy f6"
73+
placeholder="new item"
74+
readOnly
75+
/>
76+
<button
77+
className="lh-copy w2-5 pointer ba br2 shadow-6 bg-moon-gray white ml1 b--light-gray dim"
78+
type="button"
79+
>
80+
<FontAwesomeIcon icon="plus" className="" style={{ width: ".575em" }} />
81+
</button>
82+
</div>
83+
</form>
84+
</div>
85+
</div>
86+
</div>
87+
);
88+
};
89+
90+
export default CardBuilder;

src/components/Cards/Cards.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import React from "react";
22
import Card from "./Card/Card";
3+
import CardBuilder from "./CardBuilder/CardBuilder";
34

4-
const Cards = props =>
5-
props.cards.map(card => {
6-
return (
7-
<Card
8-
key={card.id}
9-
cardId={card.id}
10-
cardName={card.name}
11-
notes={card.notes}
12-
dashColor={card.dashColor}
13-
deleteMe={() => props.deleteCard(card)}
14-
/>
15-
);
16-
});
17-
5+
const Cards = props => {
6+
return (
7+
<React.Fragment>
8+
{props.cards.map(card => {
9+
return (
10+
<Card
11+
key={card.id}
12+
cardId={card.id}
13+
cardName={card.name}
14+
notes={card.notes}
15+
dashColor={card.dashColor}
16+
deleteMe={() => props.deleteCard(card)}
17+
/>
18+
);
19+
})}
20+
<CardBuilder scrollToNewCard={props.scrollToNewCard} newCard={card => props.newCard(card)} />
21+
</React.Fragment>
22+
);
23+
};
1824
export default Cards;

src/components/SidebarMenu/SidebarMenu.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.SidebarMenu {
22
height: auto;
3+
z-index: 1;
34
background-color: #fff;
45
box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.1);
56
border-radius: 0 0 0 5px;

src/containers/Workbench/Workbench.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,42 @@ export default class Workbench extends Component {
6868
let updatedCards = this.state.openBoard.cards.filter(card => card.id !== cardToDelete.id);
6969
// --END--
7070

71-
this.setState({ openBoard: { cards: updatedCards } });
71+
this.setState(prevState => ({
72+
openBoard: {
73+
...prevState.openBoard,
74+
cards: updatedCards
75+
}
76+
}));
77+
};
78+
79+
handleNewCard = newCard => {
80+
// BACKENDPLACEHOLDER:
81+
let maxCardId = 0;
82+
this.state.openBoard.cards.forEach(card => {
83+
if (card.id > maxCardId) maxCardId = card.id;
84+
});
85+
let updatedCards = [
86+
...this.state.openBoard.cards,
87+
{
88+
id: maxCardId + 1,
89+
name: newCard.name,
90+
dashColor: newCard.dashColor,
91+
notes: []
92+
}
93+
];
94+
// --END--
95+
96+
this.setState(prevState => ({
97+
openBoard: {
98+
...prevState.openBoard,
99+
cards: updatedCards
100+
}
101+
}));
72102
};
73103

104+
//
105+
// Handler Boards
106+
74107
handleNewBoard = event => {
75108
event.preventDefault();
76109
// BACKENDPLACEHOLDER:
@@ -87,6 +120,22 @@ export default class Workbench extends Component {
87120
this.handleSidebarItemChange(newBoard);
88121
};
89122

123+
//
124+
// Handle Cards Zone
125+
126+
// @ Scroll to the right until get to the end
127+
handleScrollToRightOfCardsZone = () => {
128+
let lastScroll;
129+
130+
let slideToRightInterval = setInterval(() => {
131+
document.getElementById("cardsZone").scrollLeft += 10;
132+
if (lastScroll === document.getElementById("cardsZone").scrollLeft) {
133+
window.clearInterval(slideToRightInterval);
134+
}
135+
lastScroll = document.getElementById("cardsZone").scrollLeft;
136+
}, 25);
137+
};
138+
90139
render() {
91140
let modal = null;
92141

@@ -132,9 +181,14 @@ export default class Workbench extends Component {
132181
boards={this.state.boards}
133182
newBoard={() => this.setState({ newBoardModalShow: true })}
134183
/>
135-
<div className="fl pa4 w-100 items-start flex">
184+
<div id="cardsZone" className="fl pa4 w-100 overflow-auto items-start flex z-0">
136185
{this.state.openBoard.cards.length > 0 ? (
137-
<Cards cards={this.state.openBoard.cards} deleteCard={this.handleDeleteCard} />
186+
<Cards
187+
cards={this.state.openBoard.cards}
188+
newCard={this.handleNewCard}
189+
deleteCard={this.handleDeleteCard}
190+
scrollToNewCard={this.handleScrollToRightOfCardsZone}
191+
/>
138192
) : (
139193
<p className="fw1 f3 h100 flex items-center center light-silver">
140194
Select a board to start.

src/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ button:focus {
2424

2525
#root {
2626
border-radius: 5px;
27+
overflow: hidden;
2728
box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.06);
2829
background-color: #f7f8f9;
2930
}
@@ -53,7 +54,7 @@ button:focus {
5354
box-shadow: none !important;
5455
}
5556

56-
.left-30perc {
57+
.left30 {
5758
left: 30%;
5859
}
5960

0 commit comments

Comments
 (0)