|
9 | 9 | -->
|
10 | 10 |
|
11 | 11 | <template>
|
12 |
| - <div class="TopicsLinkCardGrid"> |
13 |
| - <Row :columns="{ |
14 |
| - large: compactCards ? 3 : 2, |
15 |
| - medium: 2, |
16 |
| - }"> |
17 |
| - <Column |
18 |
| - v-for="item in items" |
19 |
| - :key="item.title" |
20 |
| - > |
21 |
| - <TopicsLinkCardGridItem :item="item" :compact="compactCards" /> |
22 |
| - </Column> |
23 |
| - </Row> |
24 |
| - </div> |
| 12 | + <Pager |
| 13 | + :aria-label="$t('links-grid.label')" |
| 14 | + :class="['TopicsLinkCardGrid', topicStyle]" |
| 15 | + :pages="pages" |
| 16 | + > |
| 17 | + <template #page="{ page }"> |
| 18 | + <Row :columns="{ |
| 19 | + large: compactCards ? 3 : 2, |
| 20 | + medium: 2, |
| 21 | + }"> |
| 22 | + <Column |
| 23 | + v-for="item in page" |
| 24 | + :key="item.title" |
| 25 | + > |
| 26 | + <TopicsLinkCardGridItem :item="item" :compact="compactCards" /> |
| 27 | + </Column> |
| 28 | + </Row> |
| 29 | + </template> |
| 30 | + <BreakpointEmitter @change="handleBreakpointChange" /> |
| 31 | + </Pager> |
25 | 32 | </template>
|
26 | 33 |
|
27 | 34 | <script>
|
28 |
| -import Row from 'docc-render/components/ContentNode/Row.vue'; |
| 35 | +import BreakpointEmitter from 'docc-render/components/BreakpointEmitter.vue'; |
29 | 36 | import Column from 'docc-render/components/ContentNode/Column.vue';
|
| 37 | +import Pager from 'docc-render/components/Pager.vue'; |
| 38 | +import Row from 'docc-render/components/ContentNode/Row.vue'; |
30 | 39 | import { TopicSectionsStyle } from 'docc-render/constants/TopicSectionsStyle';
|
| 40 | +import { BreakpointName } from 'docc-render/utils/breakpoints'; |
| 41 | +import { page } from 'docc-render/utils/arrays'; |
31 | 42 | import TopicsLinkCardGridItem from './TopicsLinkCardGridItem.vue';
|
32 | 43 |
|
33 | 44 | export default {
|
34 | 45 | name: 'TopicsLinkCardGrid',
|
35 |
| - components: { TopicsLinkCardGridItem, Column, Row }, |
| 46 | + components: { |
| 47 | + BreakpointEmitter, |
| 48 | + Column, |
| 49 | + Pager, |
| 50 | + Row, |
| 51 | + TopicsLinkCardGridItem, |
| 52 | + }, |
| 53 | + data: () => ({ |
| 54 | + breakpoint: BreakpointName.large, |
| 55 | + }), |
36 | 56 | props: {
|
37 | 57 | items: {
|
38 | 58 | type: Array,
|
39 | 59 | required: true,
|
40 | 60 | },
|
| 61 | + pageSize: { |
| 62 | + type: Number, |
| 63 | + required: false, |
| 64 | + }, |
41 | 65 | topicStyle: {
|
42 | 66 | type: String,
|
43 | 67 | default: TopicSectionsStyle.compactGrid,
|
44 | 68 | validator: v => v === TopicSectionsStyle.compactGrid || v === TopicSectionsStyle.detailedGrid,
|
45 | 69 | },
|
| 70 | + usePager: { |
| 71 | + type: Boolean, |
| 72 | + default: false, |
| 73 | + }, |
46 | 74 | },
|
47 | 75 | computed: {
|
48 | 76 | compactCards: ({ topicStyle }) => topicStyle === TopicSectionsStyle.compactGrid,
|
| 77 | + defaultPageSize: ({ |
| 78 | + breakpoint, |
| 79 | + items, |
| 80 | + topicStyle, |
| 81 | + usePager, |
| 82 | + }) => (usePager ? { |
| 83 | + [TopicSectionsStyle.compactGrid]: { |
| 84 | + [BreakpointName.large]: 6, |
| 85 | + [BreakpointName.medium]: 4, |
| 86 | + [BreakpointName.small]: 1, |
| 87 | + }, |
| 88 | + [TopicSectionsStyle.detailedGrid]: { |
| 89 | + [BreakpointName.large]: 4, |
| 90 | + [BreakpointName.medium]: 2, |
| 91 | + [BreakpointName.small]: 1, |
| 92 | + }, |
| 93 | + }[topicStyle][breakpoint] : ( |
| 94 | + items.length |
| 95 | + )), |
| 96 | + pages: ({ |
| 97 | + items, |
| 98 | + defaultPageSize, |
| 99 | + pageSize, |
| 100 | + }) => page(items, (pageSize || defaultPageSize)), |
| 101 | + }, |
| 102 | + methods: { |
| 103 | + handleBreakpointChange(breakpoint) { |
| 104 | + this.breakpoint = breakpoint; |
| 105 | + }, |
49 | 106 | },
|
50 | 107 | };
|
51 | 108 | </script>
|
0 commit comments