/
index.jsx
94 lines (91 loc) · 3.27 KB
/
index.jsx
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
/* eslint-disable react/no-unescaped-entities */
import React, { useState } from "react";
import { Code } from "../../components/code";
import { TwicAbstract } from "../../components/demo-wrapper/twicAbstract";
import { TwicWrapper } from "../../components/demo-wrapper/twicWrapper";
import { TwicImg } from "@twicpics/components/react";
import "./index.scss";
const imgUrl = `components/woman-and-winter.jpg`;
const ratioValues = [`2.39`, `16/9`, `4/3`, ``, `0.75`];
const TwicRatio = () => {
const [ratioIndex, setRatioIndex] = useState(0);
const [fullWidthAera, setFullWidthAera] = useState(true);
return (
<div id="twic-ratio-container">
<TwicWrapper gitHubUrl="src/pages/ratio/index.jsx">
<TwicAbstract title="ratio property">
<p>
<strong>
The <dfn>ratio</dfn> property determines the value of the
width/height ratio of the image display area.
</strong>
</p>
<p>Its value can be:</p>
<ul>
<li>
a ratio expression of the form <b>width/height</b> or{" "}
<b>width:height</b> like
<Code>4/3</Code>,<Code>4:3</Code>,<Code>800/600</Code>...
</li>
<li>
a number that is the result of such an expression like
<Code>1.85</Code>,<Code>2</Code>, or
<Code>0.5</Code>.
</li>
<li>
"none" as in<Code>ratio="none"</Code>. In this case the media
displayed has a "free" ratio defined by the dimensions of its
container. Particularly useful in the case of
<a href="/hero" target="_blank" rel="noreferrer">
image or video hero
</a>
.
</li>
</ul>
<p>
A square area (<Code>ratio="1"</Code>) will be created by default.
</p>
</TwicAbstract>
<div className="twic-testing-container">
<button
className="twic-button"
onClick={() => setRatioIndex((ratioIndex + 1) % ratioValues.length)}
>
Click to change the aspect-ratio
</button>
<button
className="twic-button"
onClick={() => setFullWidthAera(!fullWidthAera)}
>
Click to change the area width
</button>
</div>
<div className={`twic-grid ${fullWidthAera && `half-width`}`}>
<div className="twic-item">
<TwicImg src={imgUrl} ratio={ratioValues[ratioIndex]} />
<span>
<span className="twic-code">
ratio="{ratioValues[ratioIndex] ? ratioValues[ratioIndex] : 1}"
</span>
(mode is<Code>cover</Code>)
</span>
</div>
<div className="twic-item">
<TwicImg
src={imgUrl}
mode="contain"
ratio={ratioValues[ratioIndex]}
/>
<span>
<span className="twic-code">
ratio="{ratioValues[ratioIndex] ? ratioValues[ratioIndex] : 1}"
</span>
(mode is<Code>contain</Code>)
</span>
</div>
</div>
</TwicWrapper>
</div>
);
};
export default TwicRatio;