-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.html
348 lines (314 loc) · 10.3 KB
/
grid.html
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style>
body {
margin: 0;
}
body * {
box-sizing: border-box;
}
label {
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 11px;
line-height: 13px;
margin-bottom: 8px;
color: #5B6971;
}
form {
margin: 0;
display: grid;
grid-template-columns: 1fr 1fr;
padding: 20px 16px;
column-gap: 12px;
row-gap: 20px;
}
input {
background: #FFFFFF;
border: 1px solid #E5E5E5;
height: 36px;
outline: none;
padding: 12px;
font-family: Roboto;
font-style: normal;
font-weight: bold;
font-size: 11px;
line-height: 13px;
color: #0F0F0F;
}
.formInput {
display: grid;
}
.demonstration {
padding: 20px;
width: 100%;
padding-top: 0;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.demoGrid {
display: inline-grid;
grid-auto-flow: column;
grid-auto-columns: auto;
height: 100px;
overflow: auto;
border: 1px solid #B0BDC5;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 11px;
line-height: 13px;
text-align: center;
max-width: 362px;
color: #5B6971;
}
.demoGrid>* {
display: flex;
justify-content: center;
align-items: center;
align-content: center;
}
.margin,
.gutter {
background: #E7EBED;
}
.box {
background: white;
max-width: 140px;
}
.error {
border-color: red;
}
.boxWidth {
display: flex;
max-width: 100%;
font-family: Roboto;
align-items: center;
font-style: normal;
font-weight: normal;
font-size: 11px;
width: 362px;
line-height: 13px;
text-align: center;
color: #5B6971;
margin-bottom: 11px;
}
.line {
height: 1px;
flex-grow: 1;
background-color: #B0BDC5;
position: relative;
}
.width {
margin: 0 10px;
}
.resultContainer {
display: none;
overflow: hidden;
border-radius: 2px;
padding: 9px 16px;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 14px;
}
.resultContainer.error {
background: #FFF4EB;
color: #D2431E;
}
.resultContainer.success {
background: #EFFBF6;
color: #00B16A;
}
.backButton {
border-top: 1px solid #E7EBED;
text-align: center;
padding: 14px 0;
background: #F7F8F9;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 11px;
display: flex;
gap: 4px;
align-items: center;
cursor: pointer;
align-content: center;
justify-content: center;
line-height: 13px;
color: #5B6971;
transition: 0.3s all;
}
.backButton:hover {
background-color: #F1F3F4;
}
</style>
<div class="innerFrame">
<form>
<div class="formInput">
<label for="layoutWidth">Layout Width</label>
<input type="number" name="layoutWidth" value="360" min="1" oninput="changeWidth(this)">
</div>
<div class="formInput">
<label for="columns">Columns</label>
<input type="number" name="columns" value="2" min="1" oninput="changeColumns(this)">
</div>
<div class="formInput">
<label for="margin">Margin</label>
<input type="number" name="margin" value="20" min="0" oninput="changeMargin(this)">
</div>
<div class="formInput">
<label for="gutter">Gutter</label>
<input type="number" name="gutter" value="40" min="0" oninput="changeGutter(this)">
</div>
</form>
<div class="resultContainer error">
The values you entered are invalid. Please adjust the values so that the box is able to fit.
</div>
<div class="demonstration">
<div class="boxWidth">
<div class="line left"></div>
<span class="width">
360
</span>
<div class="line right"></div>
</div>
<div class="demoGrid">
<div class="margin" style="width: 20px">20</div>
<div class="box" style="width: 140px">140</div>
<div class="gutter" style="width: 40px">40</div>
<div class="box" style="width: 140px">140</div>
<div class="margin" style="width: 20px">20</div>
</div>
</div>
<div class="backButton" onclick="goBack()">
<svg width="8" height="8" viewBox="0 0 8 8" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 3.5H1.915L4.71 0.705L4 0L0 4L4 8L4.705 7.295L1.915 4.5H8V3.5Z" fill="#5B6971" />
</svg>
Back
</div>
</div>
<script>
let margin = 20
let gutter = 40
let columns = 2
let width = 360
let boxSize = 140
let calc = (width - (margin * 2) - (gutter * (columns - 1))) / columns
let logCalc = `(${width} - (${margin} * 2) - (${gutter} * (${columns} - 1))) / ${columns})`
function goBack() {
parent.postMessage({
pluginMessage: {
type: 'open-menu',
}
}, '*')
}
function changeWidth(el) {
width = el.value
calc = (width - (margin * 2) - (gutter * (columns - 1))) / columns
let boxSize = (width / columns) - (margin * 2) - (gutter * (columns - 1))
if (calc < 1 || !Number.isInteger(calc) || calc == Infinity) {
el.classList.add("error")
displayError()
} else {
el.classList.remove("error")
resizeBox()
}
}
function changeColumns(el) {
columns = el.value
calc = (width - (margin * 2) - (gutter * (columns - 1))) / columns
if (calc < 1 || !Number.isInteger(calc) || calc == Infinity) {
el.classList.add("error")
displayError()
} else {
el.classList.remove("error")
resizeBox()
}
}
function changeGutter(el) {
gutter = el.value
calc = (width - (margin * 2) - (gutter * (columns - 1))) / columns
if (calc < 1 || !Number.isInteger(calc) || calc == Infinity) {
el.classList.add("error")
displayError()
} else {
el.classList.remove("error")
resizeBox()
}
}
function changeMargin(el) {
margin = el.value
calc = (width - (margin * 2) - (gutter * (columns - 1))) / columns
if (calc < 1 || !Number.isInteger(calc) || calc == Infinity) {
el.classList.add("error")
displayError()
} else {
el.classList.remove("error")
resizeBox()
}
}
function resizeBox() {
calc = (width - (margin * 2) - (gutter * (columns - 1))) / columns
document.querySelectorAll(".error").forEach(q => {
if (q.classList.contains("resultContainer")) return
q.classList.remove('error')
})
if (calc < 1 || !Number.isInteger(calc)) {
document.querySelector('.width').style.color = '#F22A42'
displayError()
} else {
document.querySelector('.width').style.color = ''
let divider = 360 / width
document.querySelector('.width').innerHTML = width;
let grid = `
<div class="margin" style="width:20px">${margin}</div>
<div class="box" style="width:140px">${calc}</div>
<div class="gutter" style="width:40px">${gutter}</div>
<div class="box" style="width:140px">${calc}</div>
`
grid += `<div class="margin" style="width:20px">${margin}</div>`
parent.postMessage({
pluginMessage: {
type: 'grid',
width: width,
columns: columns,
gutter: gutter,
boxWidth: calc,
margin: margin
}
}, '*')
document.querySelector('.demoGrid').innerHTML = grid;
document.querySelector('.boxWidth').style.width = document.querySelector('.demoGrid').clientWidth +
'px';
}
}
function displayError() {
document.querySelectorAll('.demoGrid .box').forEach(m => {
m.innerHTML = "N/A"
m.style.color = '#F22A42'
})
}
parent.postMessage({
pluginMessage: {
type: 'grid',
width: width,
columns: columns,
gutter: gutter,
boxWidth: boxSize,
margin: margin
}
}, '*')
</script>
</body>
</html>