forked from learningequality/kolibri-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkcardgrid.vue
564 lines (507 loc) · 18.7 KB
/
kcardgrid.vue
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<template>
<DocsPageTemplate apiDocs>
<DocsPageSection title="Overview" anchor="#overview">
<p>Displays a grid of cards <DocsLibraryLink component="KCard" />.</p>
<p><code>KCardGrid</code> provides base layouts for the most common grids in our ecosystem, as well as advanced configuration via <code>useKCardGrid</code> (TBD), allowing customization or complete override of the base layouts.</p>
<p>Together with <code>KCard</code>, it ensures accessible navigation within card lists, such as announcing only their titles when using the tab key to avoid overwhelming screen reader outputs.</p>
<p>Grid's visual behavior is based on the <DocsInternalLink text="window breakpoint system" href="/layout#responsiveness" />. <code>KCardGrid</code> determines how many cards per row to display based on its layout and a current window breakpoint.</p>
<p><code>KCardGrid</code> doesn't manage inner card content. This is <code>KCard</code>'s responsibility.</p>
</DocsPageSection>
<DocsPageSection title="Guidelines" anchor="#guidelines">
<ul>
<li>
<code>KCardGrid</code> must be a direct parent of <code>KCard</code> (<DocsInternalLink text="KCard: KCard and KCardGrid" href="/kcard#k-card-and-grid" />)
</li>
<li>
Avoid setting card widths. Rely on <code>KCardGrid</code> layouts and customization options (<DocsInternalLink text="Base layouts" href="#base-layouts" />, <DocsInternalLink text="Layout customization" href="#layout-customization" />)
</li>
<li>
Avoid setting card heights. Instead, set heights on card sections, use text truncation, or limit content in other ways (<DocsInternalLink text="Card height, content tolerance and alignment" href="#card-height-and-alignment" />)
</li>
<li>
Ensure robust content tolerance and consistent content alignment (<DocsInternalLink text="Card height, content tolerance and alignment" href="#card-height-and-alignment" />)
</li>
<li>Preview cards on all screen sizes (<DocsInternalLink text="Fine-tuning responsiveness" href="#fine-tuning-responsiveness" />)</li>
</ul>
<p>Also follow <DocsInternalLink text="KCard guidelines" href="/kcard#guidelines" />.</p>
</DocsPageSection>
<DocsPageSection title="Usage" anchor="#usage">
<DocsSubNav
:items="[
{ text: 'Base layouts', href: '#base-layouts' },
{ text: 'Layout customization (TBD)', href: '#layout-customization' },
{ text: 'Card height, content tolerance and alignment', href: '#card-height-and-alignment' },
{ text: 'Fine-tuning responsiveness', href: '#fine-tuning-responsiveness' },
{ text: 'Loading state (TBD)', href: '#loading-state' },
]"
/>
<h3>
Base layouts
<DocsAnchorTarget anchor="#base-layouts" />
</h3>
<p>Three base layouts are available: <code>'1-1-1'</code>, <code>'1-2-2'</code>, and <code>'1-2-3'</code>. They determine the number of cards per row for each <DocsInternalLink text="window breakpoint level" href="/layout#responsiveness" />.</p>
<h4>
'1-1-1' grid
<DocsAnchorTarget anchor="#1-1-1-grid" />
</h4>
<p>Displays a grid with 1 card per row on every screen size. <DocsToggleButton contentId="more-1-1-1-grid" showText="Show full definition" hideText="Hide full definition" /></p>
<DocsToggleContent id="more-1-1-1-grid">
<DocsTable>
<tr>
<th></th>
<th>Level 0</th>
<th>Level 1</th>
<th>Level 2</th>
<th>Level 3</th>
<th>Level 4</th>
<th>Level 5</th>
<th>Level 6</th>
<th>Level 7</th>
</tr>
<tr>
<th>Cards per row</th>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</DocsTable>
</DocsToggleContent>
<DocsShow block>
<KCardGrid layout="1-1-1">
<DocsKCard
v-for="i in 2"
:key="i"
:headingLevel="5"
orientation="horizontal"
:prependTitle="`(${i})`"
/>
</KCardGrid>
</DocsShow>
<!-- eslint-disable -->
<DocsShowCode language="html">
<KCardGrid layout="1-1-1">
<KCard
v-for="i in 2"
...
/>
</KCardGrid>
</DocsShowCode>
<!-- eslint-enable -->
<h4>
'1-2-2' grid
<DocsAnchorTarget anchor="#1-2-2-grid" />
</h4>
<p>Displays a grid with 1 card per row on smaller screens, and 2 cards per row on medium and larger screens. <DocsToggleButton contentId="more-1-2-2-grid" showText="Show full definition" hideText="Hide full definition" /></p>
<DocsToggleContent id="more-1-2-2-grid">
<DocsTable>
<tr>
<th></th>
<th>Level 0</th>
<th>Level 1</th>
<th>Level 2</th>
<th>Level 3</th>
<th>Level 4</th>
<th>Level 5</th>
<th>Level 6</th>
<th>Level 7</th>
</tr>
<tr>
<th>Cards per row</th>
<td>1</td>
<td>1</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
</DocsTable>
</DocsToggleContent>
<DocsShow block>
<KCardGrid layout="1-2-2">
<DocsKCard
v-for="i in 3"
:key="i"
:headingLevel="5"
:prependTitle="`(${i})`"
/>
</KCardGrid>
</DocsShow>
<!-- eslint-disable -->
<DocsShowCode language="html">
<KCardGrid layout="1-2-2">
<KCard
v-for="i in 3"
...
/>
</KCardGrid>
</DocsShowCode>
<!-- eslint-enable -->
<h4>
'1-2-3' grid
<DocsAnchorTarget anchor="#1-2-3-grid" />
</h4>
<p>Displays a grid with 1 card per row on smaller screens, 2 cards per row on medium screens, and 3 cards per row on larger screens. <DocsToggleButton contentId="more-1-2-3-grid" showText="Show full definition" hideText="Hide full definition" /></p>
<DocsToggleContent id="more-1-2-3-grid">
<DocsTable>
<tr>
<th></th>
<th>Level 0</th>
<th>Level 1</th>
<th>Level 2</th>
<th>Level 3</th>
<th>Level 4</th>
<th>Level 5</th>
<th>Level 6</th>
<th>Level 7</th>
</tr>
<tr>
<th>Cards per row</th>
<td>1</td>
<td>1</td>
<td>2</td>
<td>2</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
</DocsTable>
</DocsToggleContent>
<DocsShow block>
<KCardGrid layout="1-2-3">
<DocsKCard
v-for="i in 5"
:key="i"
:headingLevel="5"
:prependTitle="`(${i})`"
/>
</KCardGrid>
</DocsShow>
<!-- eslint-disable -->
<DocsShowCode language="html">
<KCardGrid layout="1-2-3">
<KCard
v-for="i in 5"
...
/>
</KCardGrid>
</DocsShowCode>
<!-- eslint-enable -->
<h3>
Layout customization
<DocsAnchorTarget anchor="#layout-customization" />
</h3>
<p>Base layouts can be customized or even completely overriden. Refer to <code>useKCardGrid</code> (TBD).</p>
<h3>
Card height, content tolerance and alignment
<DocsAnchorTarget anchor="#card-height-and-alignment" />
</h3>
<p>Cards displayed in <code>KCardGrid</code> stretch vertically to fit their content, making a grid row height match its tallest card.</p>
<p><em>Setting height on cards is discouraged. Instead, manage height bottom-up, for example by setting height on card sections, using text truncation, or other ways to limit its inner content.</em> Such approaches ensure content tolerance, prevent from unexpected overflows or excessive height, and keep vertical alignment of card sections consistent on a grid row. This is especially important when dealing with unknown lenghts or amounts of content displayed in cards. Consider:</p>
<DocsShow language="html">
<KCardGrid layout="1-2-3">
<DocsKCard
:headingLevel="4"
preserveAboveTitle
>
<template #aboveTitle>
<div :style="{ height: '24px' }">
<KLabeledIcon icon="readSolid" label="Read" />
</div>
</template>
<template #title>
<div :style="{ height: '52px' }">
<KTextTruncator
:maxLines="2"
text="(1) Learn everything about hummingbirds: their habitats, feeding patterns, and stunning flight abilities"
/>
</div>
</template>
<template #belowTitle>
<KTextTruncator
:maxLines="4"
text="Short description"
/>
</template>
<template #footer>
<div class="pills" :style="{ 'color': $themeTokens.annotation }">
<span
v-for="(pill, i) in slicedPills"
:key="i"
:style="{ 'background-color': $themePalette.grey.v_50 }"
>
{{ pill }}
</span>
</div>
</template>
</DocsKCard>
<DocsKCard
:headingLevel="4"
preserveAboveTitle
>
<template #aboveTitle>
<div :style="{ height: '24px' }">
<KLabeledIcon icon="readSolid" label="Read" />
</div>
</template>
<template #title>
<div :style="{ height: '52px' }">
<KTextTruncator
:maxLines="2"
text="(2) Short title"
/>
</div>
</template>
<template #belowTitle>
<KTextTruncator
:maxLines="4"
text="Discover how hummingbirds play a big role in nature despite their small size. Find out more about their beauty, how they help plants grow, and where they live. "
/>
</template>
<template #footer>
<div></div>
</template>
</DocsKCard>
<DocsKCard
:headingLevel="4"
preserveAboveTitle
>
<template #aboveTitle>
<div :style="{ height: '24px' }"></div>
</template>
<template #title>
<div :style="{ height: '52px' }">
<KTextTruncator
:maxLines="2"
text="(3) Learn everything about hummingbirds: their habitats, feeding patterns, and stunning flight abilities"
/>
</div>
</template>
<template #belowTitle>
<KTextTruncator
:maxLines="4"
text="Discover how hummingbirds play a big role in nature despite their small size. Find out more about their beauty, how they help plants grow, and where they live. "
/>
</template>
<template #footer>
<div class="pills" :style="{ 'color': $themeTokens.annotation }">
<span
v-for="(pill, i) in slicedPills"
:key="i"
:style="{ 'background-color': $themePalette.grey.v_50 }"
>
{{ pill }}
</span>
</div>
</template>
</DocsKCard>
</KCardGrid>
</DocsShow>
<!-- eslint-disable -->
<DocsShowCode language="html">
<KCardGrid ...>
<KCard
...
preserveAboveTitle
>
<template #aboveTitle>
<div :style="{ height: '24px' }">
...
</div>
</template>
<template #title>
<div :style="{ height: '52px' }">
<KTextTruncator
:maxLines="2"
:text="..."
/>
</div>
</template>
<template #belowTitle>
<KTextTruncator
:maxLines="4"
:text="..."
/>
</template>
<template #footer>
<span v-for="pill in slicedPills">
...
</span>
</template>
</KCard>
</KCardGrid>
</DocsShowCode>
<!-- eslint-enable -->
<!-- eslint-disable -->
<DocsShowCode language="javascript">
export default {
...
computed: {
slicedPills() {
return pills.slice(0, 2);
},
},
};
</DocsShowCode>
<!-- eslint-enable -->
<p>Here, <code>KCard</code> has the following adjustments related to its visual output in the grid:</p>
<ul>
<li>Height is set on its <code>aboveTitle</code> slot content, and its <code>preserveAboveTitle</code> prop keeps the slot area even without content. This results in consistent alignment of all cards' titles on a grid row.</li>
<li>Similarly, height is set on its <code>title</code> slot, and the title is truncated.</li>
<li>Its <code>belowTitle</code> slot's content is truncated.</li>
<li>The number of pills in its <code>footer</code> slot is limited to a reasonable amount.</li>
</ul>
<p><code>KCard</code> offers other <code>preserve...</code> props corresponding to its slots.</p>
<h3>
Fine-tuning responsiveness
<DocsAnchorTarget anchor="#fine-tuning-responsiveness" />
</h3>
<p>Grid configuration can be combined with <code>KCard</code>'s settings to further improve responsive experience. A common pattern is switching <code>KCard</code>'s horizontal orientation to vertical for smaller screens to organize content more effectively in limited space:</p>
<DocsShow block>
<KCardGrid layout="1-2-2">
<DocsKCard
v-for="i in 2"
:key="i"
:headingLevel="4"
:orientation="windowBreakpoint < 4 ? 'vertical' : 'horizontal'"
:prependTitle="`(${i})`"
/>
</KCardGrid>
</DocsShow>
<!-- eslint-disable -->
<DocsShowCode language="javascript">
import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow';
export default {
setup() {
const { windowBreakpoint } = useKResponsiveWindow();
return { windowBreakpoint };
},
};
</DocsShowCode>
<!-- eslint-enable -->
<!-- eslint-disable -->
<DocsShowCode language="html">
<KCardGrid layout="1-2-2">
<KCard
v-for="i in 2"
:orientation="windowBreakpoint < 4 ? 'vertical' : 'horizontal'"
...
/>
</KCardGrid>
</DocsShowCode>
<!-- eslint-enable -->
<p>This technique also works for adjusting <code>KCard</code> slots content. In the following example, some metadata pills are hidden on smaller screens:</p>
<DocsShow block>
<KCardGrid layout="1-2-2">
<DocsKCard
v-for="i in 2"
:key="i"
:headingLevel="4"
:prependTitle="`(${i})`"
>
<template #footer>
<div class="pills" :style="{ 'color': $themeTokens.annotation }">
<span
:style="{ 'background-color': $themePalette.grey.v_50 }"
>
<KIcon icon="readSolid" :style="{ fontSize: '13px', position: 'relative', top: '3px' }" />
Read
</span>
<span
:style="{ 'background-color': $themePalette.grey.v_50 }"
>
Short Activity
</span>
<template v-if="windowBreakpoint > 3">
<span
:style="{ 'background-color': $themePalette.grey.v_50 }"
>
Biology
</span>
<span
:style="{ 'background-color': $themePalette.grey.v_50 }"
>
Ecology
</span>
</template>
</div>
</template>
</DocsKCard>
</KCardGrid>
</DocsShow>
<!-- eslint-disable -->
<DocsShowCode language="html">
<KCardGrid layout="1-2-2">
<KCard
v-for="i in 2"
...
>
<template #footer>
<span ...>Read</span>
<span ...>Short Activity</span>
<template v-if="windowBreakpoint > 3">
<span ...>Biology</span>
<span ...>Ecology</span>
</template>
</template>
</KCard>
</KCardGrid>
</DocsShowCode>
<!-- eslint-enable -->
<h3>
Loading state
<DocsAnchorTarget anchor="#loading-state" />
</h3>
<p>When cards are loading, <code>KCardGrid</code> displays skeleton cards...(TBD)</p>
</DocsPageSection>
<DocsPageSection title="Related" anchor="#related">
<ul>
<li>
<DocsLibraryLink component="KCard" /> is a component for use within <code>KCardGrid</code>
</li>
<li>
<DocsLibraryLink component="useKResponsiveWindow" /> can be used to detect the current window breakpoint for <DocsInternalLink text="fine-tuning responsiveness" href="#fine-tuning-responsiveness" />
</li>
</ul>
</DocsPageSection>
</DocsPageTemplate>
</template>
<script>
import useKResponsiveWindow from '../../lib/composables/useKResponsiveWindow';
import DocsKCard from '../pages-components/DocsKCard';
export default {
components: {
DocsKCard,
},
setup() {
const { windowBreakpoint } = useKResponsiveWindow();
return { windowBreakpoint };
},
data() {
return {};
},
computed: {
slicedPills() {
return ['Short Activity', 'Biology', 'Ecology', 'Ornithology'].slice(0, 2);
},
},
};
</script>
<style lang="scss" scoped>
.pills {
margin-left: -4px;
span {
display: inline-block;
padding: 4px 8px;
margin: 4px;
border-radius: 4px;
}
}
</style>