Skip to content

Commit d457c58

Browse files
committed
All parents get add button, theme
1 parent 4e8ec91 commit d457c58

File tree

2 files changed

+64
-26
lines changed

2 files changed

+64
-26
lines changed

src/components/Tree.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#child-name {
2+
top : 50%;
3+
left : 50%;
4+
right : auto;
5+
bottom : auto;
6+
margin-right : -50%;
7+
transform : translate(2%, 25%);
8+
width : 250px;
9+
height : 30px;
10+
background-color: rgb(255, 225, 235);
11+
border: 2px solid rgb(32, 32, 32);
12+
}
13+
14+
#child-name:focus {
15+
outline-width: 0;
16+
}
17+
18+
.submit {
19+
margin-top: 50%;
20+
margin-left: -30px;
21+
}
22+
23+
form{
24+
overflow: hidden;
25+
}

src/components/Tree.js

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { Component } from 'react'
22
import {Treebeard} from 'react-treebeard';
33
import Modal from 'react-modal';
4-
import Folder from './Folder'
5-
import File from './File'
4+
import './Tree.css'
65

76
const customStyles = {
87
content : {
@@ -14,6 +13,8 @@ const customStyles = {
1413
transform : 'translate(-50%, -50%)',
1514
width : '300px',
1615
height : '300px',
16+
backgroundColor : '#FF80AB',
17+
overflow : 'hidden'
1718
}
1819
};
1920

@@ -56,36 +57,48 @@ export default class Tree extends Component {
5657
this.state = {
5758
data,
5859
modalIsOpen: false,
59-
value: "Enter",
60+
value: "",
6061
activeNode:{}
6162
};
6263
}
6364

6465
openModal = (node)=> {
65-
console.log(node);
66-
this.setState({modalIsOpen: true,activeNode:node});
66+
this.setState({ modalIsOpen: true, activeNode:node });
6767
}
6868

6969

7070
closeModal = ()=> {
7171
this.setState({modalIsOpen: false});
7272
}
7373

74-
75-
componentWillMount = () => {
76-
this.state.data.children.map((child, index)=> {
74+
addIcon = (node) => {
75+
console.log(node);
76+
77+
node.map((child)=> {
7778
const name1 = child.name;
78-
child.name = <div>HI {name1} <span onClick={(e)=>this.openModal(child,e)}><i className="far fa-plus-square"/></span></div>;
79+
(name1.indexOf('.') === -1) ?
80+
child.name = <div><i className="far fa-folder px-2"></i>
81+
{name1} <span onClick={(e)=>this.openModal(child,e)}><i className="far fa-plus-square pl-2"/></span></div>
82+
: child.name = <div><i className="far fa-file-code px-2"></i> {name1}</div>
83+
if(child.children){
84+
this.addIcon(child.children)
85+
}
7986
})
8087
}
8188

89+
componentWillMount = () => {
90+
this.addIcon(this.state.data.children)
91+
}
92+
93+
8294
handleSubmit = (e) =>{
8395
e.preventDefault();
84-
const name = e.target.value;
85-
this.state.activeNode.children.push({name:this.state.value});
96+
if(this.state.activeNode.children){
97+
this.state.activeNode.children.push({name: this.state.value});
98+
}
8699
const newData = this.state.data;
87-
this.setState({data: newData});
88-
this.closeModal()
100+
// this.setState({data: newData});
101+
this.closeModal();
89102
}
90103
handleChange(event) {
91104
this.setState({value: event.target.value});
@@ -98,7 +111,7 @@ export default class Tree extends Component {
98111
}
99112
node.active = true;
100113
if (node.children) {
101-
node.toggled = toggled;
114+
node.toggled = toggled;
102115
}
103116
this.setState(() => ({cursor: node, data: Object.assign({}, data)}));
104117
}
@@ -107,15 +120,15 @@ export default class Tree extends Component {
107120
return (
108121
<React.Fragment>
109122
<Modal
110-
isOpen={this.state.modalIsOpen}
111-
onAfterOpen={this.afterOpenModal}
112-
onRequestClose={this.closeModal}
113-
style={customStyles}
114-
contentLabel="Example Modal"
123+
isOpen={this.state.modalIsOpen}
124+
onAfterOpen={this.afterOpenModal}
125+
onRequestClose={this.closeModal}
126+
style={customStyles}
127+
contentLabel="Example Modal"
115128
>
116129
<form onSubmit={(e)=>{this.handleSubmit(e)}}>
117-
<input type="text" value={this.state.value} onChange={(e)=>{this.handleChange(e)}} />
118-
<input type="submit" value="ENTER"/>
130+
<input id= "child-name" type="text" value={this.state.value} onChange={(e)=>{this.handleChange(e)}} />
131+
<input className='btn btn-md btn-dark submit' type="submit" value="ENTER"/>
119132
</form>
120133

121134
</Modal>
@@ -135,10 +148,10 @@ const style = {
135148
tree: {
136149
base: {
137150
listStyle: 'none',
138-
backgroundColor: '#21252B',
151+
backgroundColor: '#fff1ff',
139152
margin: '10px',
140153
padding: '10px',
141-
color: '#9DA5AB',
154+
color: '#b00020',
142155
fontFamily: 'lucida grande ,tahoma,verdana,arial,sans-serif',
143156
fontSize: '18px'
144157
},
@@ -153,7 +166,7 @@ const style = {
153166
display: 'block'
154167
},
155168
activeLink: {
156-
background: '#31363F'
169+
background: '#fff'
157170
},
158171
toggle: {
159172
base: {
@@ -174,15 +187,15 @@ const style = {
174187
height: 14,
175188
width: 14,
176189
arrow: {
177-
fill: '#9DA5AB',
190+
fill: '#b00020',
178191
strokeWidth: 0
179192
}
180193
},
181194
header: {
182195
base: {
183196
display: 'inline-block',
184197
verticalAlign: 'top',
185-
color: '#9DA5AB'
198+
color: '#b00020'
186199
},
187200
connector: {
188201
width: '2px',

0 commit comments

Comments
 (0)