-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathindex.js
153 lines (143 loc) · 5.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import React, { Component } from "react";
import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import MobileDetect from "mobile-detect";
import Card from "../components/card";
import Image from "../components/image";
import Carousel from "react-multi-carousel";
import CarouselWithCustomDots from "../components/carousel-with-custom-dots";
import "../style.css";
import "react-multi-carousel/lib/styles.css";
class Index extends Component {
static getInitialProps({ req }) {
let userAgent;
let deviceType;
if (req) {
userAgent = req.headers["user-agent"];
} else {
userAgent = navigator.userAgent;
}
const md = new MobileDetect(userAgent);
if (md.tablet()) {
deviceType = "tablet";
} else if (md.mobile()) {
deviceType = "mobile";
} else {
deviceType = "desktop";
}
return { deviceType };
}
state = { isMoving: false };
render() {
const { classes } = this.props;
const images = [
"https://images.unsplash.com/photo-1549989476-69a92fa57c36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1549396535-c11d5c55b9df?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550133730-695473e544be?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550167164-1b67c2be3973?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550338861-b7cfeaf8ffd8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550223640-23097fc71cb2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550353175-a3611868086b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550330039-a54e15ed9d33?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1549737328-8b9f3252b927?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1549833284-6a7df91c1f65?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1549985908-597a09ef0a7c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60",
"https://images.unsplash.com/photo-1550064824-8f993041ffd3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60"
];
const texts = [
"Appending currency sign to a purchase form in your e-commerce site using plain JavaScript.",
"Fixing CSS load order/style.chunk.css incorrect in Nextjs",
"React Carousel with Server Side Rendering Support – Part 1",
"React Carousel with Server Side Rendering Support – Part 2",
"Flutter Xcode couldn’t find any iOS App Development provisioning profiles"
];
const fakerData = Array(12)
.fill(0)
.map((item, index) => {
return {
image: images[index],
headline: "w3js -> web front-end studio",
description: texts[index] || texts[0]
};
});
const responsive = {
desktop: {
breakpoint: { max: 3000, min: 1024 },
items: 3,
slidesToSlide: 3
},
tablet: {
breakpoint: { max: 1024, min: 464 },
items: 2,
slidesToSlide: 2
},
mobile: {
breakpoint: { max: 464, min: 0 },
items: 1,
slidesToSlide: 1
}
};
return (
<div className={classes.root}>
<Typography className={classes.title} variant="h6" color="grey">
<a target="_blank" href="https://w3js.com/">
A Carousel supports multiple items and server-side rendering
</a>
</Typography>
<Typography className={classes.title} variant="p" color="grey">
<a target="_blank" href="https://w3js.com/">
This is the server-side rendering demo of the libiary, try to
disable the JavaScript in your browser, you will still see our
Carousel renders nicely
</a>
</Typography>
<Carousel
/*
swipeable={false}
draggable={false}
*/
responsive={responsive}
ssr
infinite={false}
beforeChange={() => this.setState({ isMoving: true })}
afterChange={() => this.setState({ isMoving: false })}
containerClass="first-carousel-container container"
deviceType={this.props.deviceType}
>
{fakerData.map(card => {
return <Card isMoving={this.state.isMoving} {...card} />;
})}
</Carousel>
<Carousel
/*
swipeable={false}
draggable={false}
*/
responsive={responsive}
ssr
showDots
infinite
containerClass="container-with-dots"
itemClass="image-item"
deviceType={this.props.deviceType}
>
{fakerData.slice(0, 5).map(card => {
return <Image url={card.image} alt={card.headline} />;
})}
</Carousel>
<CarouselWithCustomDots deviceType={this.props.deviceType} />
</div>
);
}
}
const styles = () => ({
root: {
textAlign: "center"
},
title: {
maxWidth: 400,
margin: "auto",
marginTop: 10
}
});
export default withStyles(styles)(Index);