Skip to content

Commit e8ee9e7

Browse files
committed
btnClass not working 2
1 parent 179a9e9 commit e8ee9e7

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import styles from './Cockpit.module.css';
3+
const cockpit = (props) => {
4+
5+
const assignedClasses = [];
6+
let btnClass = '';
7+
if(props.showPersons){
8+
9+
btnClass = styles.Button;
10+
console.log('btnclass', btnClass);
11+
if (props.showPersons) {
12+
13+
btnClass = [styles.Button, styles.Red].join( ' ' );
14+
console.log('showing Persons', btnClass);
15+
}
16+
}
17+
18+
if (props.persons.length <= 2) {
19+
assignedClasses.push(styles.red);
20+
console.log('ass. class',assignedClasses);
21+
}
22+
if (props.persons.length <= 1) {
23+
assignedClasses.push(styles.bold);
24+
console.log('ass. class', assignedClasses );
25+
}
26+
27+
return(
28+
<div>
29+
<h1>tekstiä</h1>
30+
<p className={assignedClasses.join(' ')}>lisää tekstiä</p>
31+
32+
<button
33+
className={btnClass}
34+
onClick={props.clicked}>Toggle Persons</button>
35+
</div>
36+
)
37+
};
38+
export default cockpit;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
.red {
3+
color: red;
4+
}
5+
6+
.bold {
7+
font-weight: bold;
8+
}
9+
10+
.Button button {
11+
border: 1px solid blue;
12+
padding: 16px;
13+
background-color: green;
14+
font: inherit;
15+
color: white;
16+
cursor: pointer;
17+
}
18+
19+
.Button button:hover {
20+
background-color: lightgreen;
21+
color: black;
22+
}
23+
24+
.Button button.Red {
25+
background-color: red;
26+
}
27+
28+
.Button button.Red:hover {
29+
background-color: salmon;
30+
color: black;
31+
}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, {Component} from 'react'
2+
import Person from './person/Person'
3+
class Persons extends Component{
4+
constructor(props){
5+
super(props);
6+
console.log('[Persons.js] Inside constructor', props);
7+
8+
}
9+
componentWillMount() {
10+
console.log('[Persons.js] Inside componentWillMount ');
11+
12+
}
13+
14+
componentDidMount(){
15+
console.log('[Persons.js] Inside componentWillMount ');
16+
}
17+
18+
componentWillReceiveProps(nextProps){
19+
console.log('[UPDATE Persons.js] Inside componentWillReceiveProps, nextProps');
20+
}
21+
22+
// shouldComponentUpdate(nextProps,nextState){
23+
// console.log('[UPDATE Persons.js] Inside componentShouldUpdate, nextProps');
24+
// return nextProps.persons !== this.props.persons ||
25+
// nextProps.changed !== this.props.changed ||
26+
// nextProps.clicked !== this.props.clicked;
27+
// }
28+
29+
componentWillUpdate(nextProps,nextState){
30+
console.log('Inside componentWillUpdate, nextProps');
31+
32+
}
33+
34+
componentDidUpdate(){
35+
console.log('[UPDATE Persons.js] Inside ComponentDidUpdate ');
36+
}
37+
38+
39+
render(){
40+
console.log('[Persons.js] inside render');
41+
return this.props.persons.map( (person, index) => {
42+
43+
return <Person
44+
45+
click={() => this.props.clicked(index)}
46+
nimi={ person.nimi }
47+
key={ person.id }
48+
changed={( event ) => this.props.changed( event, person.id )}
49+
/>
50+
51+
} );
52+
}
53+
}
54+
export default Persons;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { Component } from 'react';
2+
3+
import styles from './Person.module.css';
4+
5+
class Person extends Component {
6+
constructor(props){
7+
super(props);
8+
console.log('[Person.js] Inside constructor', props);
9+
10+
}
11+
componentWillMount() {
12+
console.log('[Person.js] Inside componentWillMount ');
13+
14+
}
15+
16+
componentDidMount(){
17+
console.log('[Person.js] Inside componentWillMount ');
18+
}
19+
render(){
20+
console.log('[Person.js] inside render');
21+
// const rnd = Math.random();
22+
// console.log('rnd:', rnd);
23+
// if ( rnd > 0.7 ) {
24+
// throw new Error ( 'Something went wrong' );
25+
// }
26+
27+
return (
28+
<div className={styles.Person}>
29+
<p onClick={this.props.click}>I am {this.props.nimi} and I am {4} years old!</p>
30+
<p>{this.props.children}</p>
31+
<input type="text" onChange={this.props.changed} value={this.props.nimi} />
32+
</div>
33+
)
34+
};
35+
}
36+
37+
export default Person;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.Person {
2+
width: 60%;
3+
margin: 16px auto;
4+
border: 1px solid #eee;
5+
box-shadow: 0 2px 3px #ccc;
6+
padding: 16px;
7+
text-align: center;
8+
}
9+
@media (min-width: 500px) {
10+
.Person{
11+
width: 450px;
12+
}
13+
}

0 commit comments

Comments
 (0)