-
Notifications
You must be signed in to change notification settings - Fork 28
/
screenshots.js
143 lines (130 loc) · 3.52 KB
/
screenshots.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
import { useTransition, animated } from 'react-spring'
import React, { useCallback, useState } from 'react'
import { layout, speed, toPx } from 'theme'
import styled from 'styled-components'
import { aspectRatio, cdnUrl } from 'helpers'
import { navigate } from 'gatsby'
import map from 'lodash/map'
import {
Hide,
Box,
Button,
Caps,
Flex,
Image,
Link,
Text
} from 'components/elements'
import { Block, Legend } from 'components/patterns'
export const screenshots = [
{ theme: 'dark', id: 'apple' },
{ theme: 'light', id: 'mdn' },
{ theme: 'light', id: 'stackoverflow' },
{ theme: 'light', id: 'producthunt' },
{ theme: 'dark', id: 'nasa' }
].map(({ theme, id }) => {
const filename = `${id}.png`
return {
id,
filename,
cdnUrl: cdnUrl(`screenshot/browser/${theme}/${filename}`)
}
})
const screenshotsUrls = map(screenshots, 'cdnUrl')
class ImageWithRef extends React.Component {
render () {
return <Image {...this.props} />
}
}
export const AnimatedImage = animated(styled(ImageWithRef)`
position: absolute;
top: 0px;
left: 0px;
will-change: opacity;
`)
export const screenshotHeight = (() => {
const width = 960
const ratio = 1.453403141
const height = width / ratio
return aspectRatio.ratios.map(n => toPx(height * n))
})()
const Screenshots = props => {
const [index, setIndex] = useState(0)
const onClick = useCallback(
() => setIndex(state => (state + 1) % screenshotsUrls.length),
[]
)
const transitions = useTransition(index, p => p, {
from: { opacity: 0 },
enter: { opacity: 1 },
leave: { opacity: 0 },
config: {
duration: speed.quickly
}
})
const blockOne = (
<Legend sup='screenshot' title='Turn websites into a snapshot' />
)
const blockTwo = (
<Flex justifyContent='center' alignItems='center' flexDirection='column'>
<Box pt={3}>
<Flex
height={screenshotHeight}
width={aspectRatio.width}
style={{ position: 'relative' }}
>
{transitions.map(({ item, props, key }) => {
return (
<AnimatedImage
alt='microlink screenshot example'
key={key}
style={props}
src={screenshotsUrls[item]}
/>
)
})}
</Flex>
</Box>
<Text
mt={[2, 0, 0, 0]}
mb={[0, 0, 0, 3]}
px={[5, 6, 6, 6]}
textAlign='center'
maxWidth={layout.medium}
>
<Hide breakpoints={[1, 2, 3]}>
Take a retina display screenshot of any URL. Automatic CDN
redistribution.
</Hide>
<Hide breakpoints={[0]}>
Take a retina display screenshot of any URL. Export them to PNG or
JPEG. Automatic CDN redistribution. Overlay composition using a
browser framer & background. Just in time stale refresh, keeping them
up to date.
</Hide>
</Text>
<Flex pt={3} alignItems='center' justifyContent='center'>
<Button onClick={() => navigate('/screenshot')}>
<Caps fontSize={0}>Live Demo</Caps>
</Button>
<Link
onClick={() => navigate('/docs/api/parameters/screenshot')}
ml={3}
>
<Caps fontWeight='regular' fontSize={0} children='See docs' />
</Link>
</Flex>
</Flex>
)
return (
<Block
id='screenshot'
flexDirection='column'
onClick={onClick}
blockOne={blockOne}
blockTwo={blockTwo}
{...props}
/>
)
}
export default Screenshots