Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/slides/src/assets/tomhanksmeme.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions examples/slides/src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import Link from './Link';
import Thanks from './Thanks';
import Slideshow, { Slide } from './Slideshow';
import Code from './Code';
import { getFunction, getBlockAfter } from '../helpers/functions';
Expand Down Expand Up @@ -175,12 +176,7 @@ export default class App extends React.Component {
],
},
{
title: 't.hanks',
children: [
<Link to="https://github.com/nickav/react">
https://github.com/nickav/react
</Link>,
],
children: [<Thanks />],
},
];

Expand Down
13 changes: 13 additions & 0 deletions examples/slides/src/components/Thanks.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.thanks-container {
margin-top: 10px;
}
.thanks-row {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ^ use prettier to format files

margin: 0 auto;
display: flex;
justify-content: space-between;
}

.thanks__img {
max-width: 100%;
max-height: 100%;
}
67 changes: 67 additions & 0 deletions examples/slides/src/components/Thanks.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';

import Link from './Link';
import './Thanks.css';
import meme from '../assets/tomhanksmeme.jpg';

export default class Thanks extends React.Component {
static MAX_HANKS = 40;

constructor() {
super();
this.state.message = 'T.hanks';
this.state.numOfHanks = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefer this.state = {} in constructor
nit: prefer instance variable syntax without constructor state = { message: '', numOfHanks: 1 }

}

clickHandler = () => {
if (this.state.numOfHanks < Thanks.MAX_HANKS) {
this.setState({
message: 'T.hanks a lot!',
numOfHanks: this.state.numOfHanks * 2,
});
}
};

render() {
const HanksByRow = [];
for (let i = 1; i <= this.state.numOfHanks; i++) {
const currHanksRow = [];
for (let j = 1; j <= this.state.numOfHanks; j *= 2) {
currHanksRow.push(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefer lowerCamelCase for var names
nit: prefer doing maps in the render block rather than accumulating data before

tHanksMeme({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: component names are UpperCamelCase, this should be an explicit render e.g. <THanksMeme key={i} />

key: i,
onClick: () => {
this.clickHandler();
},
})
);
}
HanksByRow.push(currHanksRow);
}

return (
<div class="thanks-component">
<h1>{this.state.message}</h1>
<Link to="https://github.com/nickav/react">
https://github.com/nickav/react
</Link>
<div class="thanks-container">
{HanksByRow.map((row) => (
<div class="thanks-row">{row}</div>
))}
</div>
</div>
);
}
}

const tHanksMeme = (props) => (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this a static property of the Thanks component or move this above the Thanks component class definition

<div class="thanks__image-wrapper">
<img
src={meme}
alt="t.hanks meme of tom hanks"
class="thanks__img"
{...props}
/>
</div>
);
4 changes: 4 additions & 0 deletions examples/slides/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ module.exports = {
test: /\.(css)$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpg)$/,
use: ['url-loader'],
},
],
},
resolve: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"css-loader": "^2.1.1",
"raw-loader": "^2.0.0",
"style-loader": "^0.23.1",
"url-loader": "^2.0.0",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.4.1"
Expand Down
Loading