This commit is contained in:
Nilstrieb 2021-02-13 18:43:35 +01:00
parent 4e2d32cf04
commit 9bb74df734
6 changed files with 14 additions and 13 deletions

View file

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 492 KiB

After

Width:  |  Height:  |  Size: 492 KiB

Before After
Before After

View file

@ -1,15 +1,14 @@
import React, {Component} from "react"; import React, {Component} from "react";
import ModelImage from "./Plane"; import ModelImage from "./Plane";
import f22 from './img/f22.png'
class Home extends Component { class Home extends Component {
render() { render() {
return ( return (
<div> <div>
<h1>Hugos Favoriten</h1> <h1>Hugos Favoriten</h1>
<ModelImage img={f22} name="F-22 Raptor"/> <ModelImage src="f22.png" name="F-22 Raptor"/>
</div> </div>
) );
} }
} }

View file

@ -1,17 +1,16 @@
import React from 'react'; import React from 'react';
import ModelImage from './Plane' import ModelImage from './Plane'
import f22 from './img/f22.png'
import harrier from './img/harrier.jpg'
class Modern extends React.Component { class Modern extends React.Component {
render() { render() {
const items = Array(100).fill(1).map((x, y) => x + y) const items = Array(100).fill(1).map((x, y) => x + y)
.map(x => <ModelImage img={f22} name={'F' + (20 + x) + ' Raptor'}/>); .map(x => <ModelImage src="f22.png" name={'F' + (20 + x) + ' Raptor'}/>);
return ( return (
<div> <div>
{items} {items}
<ModelImage img={harrier} name="AV-8B Harrier"/> <ModelImage src="harrier.jpg" name="AV-8B Harrier"/>
</div> </div>
) )
} }

View file

@ -1,3 +1,7 @@
:root {
--model-image-height: 200px;
}
.model { .model {
position: relative; position: relative;
text-align: center; text-align: center;
@ -26,7 +30,7 @@
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
line-height: 200px; line-height: var(--model-image-height);
} }
.model:hover .model-info { .model:hover .model-info {
@ -35,7 +39,7 @@
} }
.model img { .model img {
height: 200px; height: var(--model-image-height);
} }

View file

@ -6,20 +6,19 @@ class ModelImage extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
img: '',
name: '', name: '',
src: '',
} }
} }
static getDerivedStateFromProps(props) { static getDerivedStateFromProps(props) {
return {img: props.img, name: props.name}; return {name: props.name, src: props.src};
} }
render() { render() {
//const style = {backgroundImage: `url('/img/${this.state.img}')`};
return ( return (
<a href="" className="model"> <a href="" className="model">
<img src={this.state.img} alt={this.state.name}/> <img src={process.env.PUBLIC_URL + '/img/' + this.state.src} alt={this.state.name}/>
<div className="model-info"> <div className="model-info">
<span className="model-info-text">{this.state.name}</span> <span className="model-info-text">{this.state.name}</span>
</div> </div>