-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-entry.tsx
More file actions
59 lines (44 loc) · 2.25 KB
/
react-entry.tsx
File metadata and controls
59 lines (44 loc) · 2.25 KB
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
import React from 'react';
import ReactDOM from 'react-dom';
import { PictureSmart } from '../src/react';
import { backgroundCssSmart } from '../src/utils/backgroundCss';
import { getOriginal } from '../src/utils';
// Adds 'webp' or 'avif' class to html element if the browser supports it.
import '../src/utils/imgSupportDetector';
const oneImageForAllBreakpoints = require.context('./images/oneImageForAllBreakpoints');
const differentBreakpoints = require.context('./images/differentBreakpoints');
const imageWithoutResize = require.context('./images/oneImageForAllBreakpoints?dontresize');
const myImageData = require('./images/oneImageForAllBreakpoints/all.png');
const myImageWithoutResizeData = require('./images/oneImageForAllBreakpoints/all.png?dontresize');
// Usage example getOriginal ()
console.log(getOriginal(myImageData));
console.log(getOriginal(myImageWithoutResizeData));
ReactDOM.render(
<div>
<h1>Example usage of csssr.images</h1>
<h2>As picture tag</h2>
<h3>One image for all resolutions</h3>
<PictureSmart requireImages={oneImageForAllBreakpoints} alt="One image for all resolutions" />
<h3>Image with different breakpoints</h3>
<PictureSmart requireImages={differentBreakpoints} alt="Image with different breakpoints" />
<h3>Image without resize</h3>
<PictureSmart requireImages={imageWithoutResize} alt="Image without resize" />
<h2>As background css</h2>
<h3>One image for all resolutions</h3>
<div className="one-image-for-all-resolutions" style={{ width: '100%', height: '100%' }}>
One image for all resolutions on background
</div>
<style>{backgroundCssSmart('.one-image-for-all-resolutions', oneImageForAllBreakpoints)}</style>
<h3>Different breakpoints</h3>
<div className="different-breakpoints" style={{ width: '100%', height: '100%' }}>
Image with different breakpoints on background
</div>
<style>{backgroundCssSmart('.different-breakpoints', differentBreakpoints)}</style>
<h3>Image without resize</h3>
<div className="image-without-resize" style={{ width: '100%', height: '100%' }}>
Image without resize on background
</div>
<style>{backgroundCssSmart('.image-without-resize', imageWithoutResize)}</style>
</div>,
document.getElementById('app'),
);