Skip to content

Commit 019bc1e

Browse files
committed
Allow showing the images horizontally
1 parent ad078f3 commit 019bc1e

File tree

4 files changed

+64
-26
lines changed

4 files changed

+64
-26
lines changed

src/components/App/App.jsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class App extends React.Component {
1515
this.state = {
1616
afterLoadText: 'afterLoad triggered',
1717
beforeLoadText: 'beforeLoad triggered',
18+
direction: 'vertical',
1819
effect: '',
1920
showLowResImages: true,
2021
threshold: 100
@@ -46,11 +47,11 @@ export default class App extends React.Component {
4647
}
4748

4849
render() {
49-
const {afterLoadText, beforeLoadText,
50+
const {afterLoadText, beforeLoadText, direction,
5051
effect, showLowResImages, threshold} = this.state;
5152

5253
return (
53-
<div>
54+
<div className={'app ' + direction}>
5455
<form className="app-controls">
5556
<a href="https://github.com/Aljullu/react-lazy-load-image-component">
5657
<img
@@ -68,18 +69,6 @@ export default class App extends React.Component {
6869
effect={effect}
6970
onChange={this.onChangeEffect()} />
7071
</p>
71-
</fieldset>
72-
<br />
73-
<fieldset className="app-controls-fieldset">
74-
<p>
75-
<label>
76-
<input className="app-controls-number"
77-
type="number"
78-
onChange={this.onChangeNumber('threshold')}
79-
value={threshold} />
80-
threshold <small>(px)</small>
81-
</label>
82-
</p>
8372
<p>
8473
<label>
8574
<input className="app-controls-checkbox"
@@ -95,6 +84,37 @@ export default class App extends React.Component {
9584
</p>
9685
</fieldset>
9786
<br />
87+
<fieldset className="app-controls-fieldset">
88+
<p>
89+
Direction:<br/>
90+
<label>
91+
<input type="radio"
92+
checked={direction === 'vertical'}
93+
name="direction"
94+
onChange={this.onChangeText('direction')}
95+
value="vertical" />
96+
Vertical
97+
</label>
98+
<label>
99+
<input type="radio"
100+
checked={direction === 'horizontal'}
101+
name="direction"
102+
onChange={this.onChangeText('direction')}
103+
value="horizontal" />
104+
Horizontal
105+
</label>
106+
</p>
107+
<p>
108+
<label>
109+
<input className="app-controls-number"
110+
type="number"
111+
onChange={this.onChangeNumber('threshold')}
112+
value={threshold} />
113+
threshold <small>(px)</small>
114+
</label>
115+
</p>
116+
</fieldset>
117+
<br />
98118
<fieldset className="app-controls-fieldset">
99119
<p>
100120
Text that will be displayed in the console when the
@@ -122,6 +142,7 @@ export default class App extends React.Component {
122142
<Gallery
123143
afterLoadText={afterLoadText}
124144
beforeLoadText={beforeLoadText}
145+
direction={direction}
125146
effect={effect}
126147
showLowResImages={showLowResImages}
127148
threshold={threshold} />

src/components/App/app.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ h1 {
2222
margin: 0 0 .5em;
2323
}
2424

25+
.app.horizontal {
26+
width: -moz-min-content;
27+
width: -webkit-min-content;
28+
width: min-content;
29+
}
30+
2531
.app-controls {
2632
background: #fff;
2733
border: 1px solid #ddd;
34+
box-sizing: border-box;
2835
box-shadow: 0 3px 5px #ddd;
29-
margin: 1em auto;
30-
max-width: 1034px;
36+
margin: 1em 20vw;
3137
padding: 1em 1.5em 1em;
38+
width: 60vw;
39+
}
40+
41+
.app.horizontal .app-controls {
42+
position: sticky;
43+
left: 0;
3244
}
3345

3446
.app-controls-github {

src/components/Gallery/Gallery.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export class Gallery extends React.Component {
2020
}
2121

2222
render() {
23-
const {afterLoadText, beforeLoadText, effect,
23+
const {afterLoadText, beforeLoadText, effect, direction,
2424
scrollPosition, showLowResImages, threshold} = this.props;
2525
const photos = getPhotos();
2626

2727
return (
28-
<div className="gallery">
28+
<div className={ 'gallery ' + direction }>
2929
{photos.map((photo) =>
3030
<LazyLoadImage
3131
alt={photo.src}
@@ -50,6 +50,8 @@ export class Gallery extends React.Component {
5050
Gallery.propTypes = {
5151
afterLoadText: PropTypes.string.isRequired,
5252
beforeLoadText: PropTypes.string.isRequired,
53+
direction: PropTypes.oneOf([
54+
'horizontal', 'vertical']).isRequired,
5355
effect: PropTypes.oneOf([
5456
'black-and-white', 'blur', 'opacity', '']).isRequired,
5557
showLowResImages: PropTypes.bool.isRequired,

src/components/Gallery/gallery.css

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
max-width: 1034px;
44
}
55

6-
.gallery-img,
7-
.gallery-img-wrapper {
8-
float: left;
9-
margin-bottom: 10px;
6+
.gallery.horizontal {
7+
max-width: none;
8+
white-space: nowrap;
109
}
1110

12-
.gallery-img:nth-child(2n),
13-
.gallery-img-wrapper:nth-child(2n) {
11+
.gallery.horizontal .gallery-img-wrapper {
1412
margin-left: 10px;
1513
}
1614

17-
.gallery-img-wrapper > .gallery-img {
18-
margin: 0;
15+
.gallery:not(.horizontal) .gallery-img-wrapper {
16+
float: left;
17+
margin-bottom: 10px;
18+
}
19+
20+
.gallery:not(.horizontal) .gallery-img-wrapper:nth-child(2n) {
21+
margin-left: 10px;
1922
}

0 commit comments

Comments
 (0)