forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridMasonry.vue
More file actions
152 lines (133 loc) · 3.15 KB
/
GridMasonry.vue
File metadata and controls
152 lines (133 loc) · 3.15 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
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
<template>
<div class="q-pa-md">
<q-table
grid
:card-container-class="cardContainerClass"
title="Treats"
:rows="rows"
:columns="columns"
row-key="name"
:filter="filter"
hide-header
v-model:pagination="pagination"
:rows-per-page-options="rowsPerPageOptions"
>
<template v-slot:top-right>
<q-input borderless dense debounce="300" v-model="filter" placeholder="Search">
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
</template>
<template v-slot:item="props">
<div class="q-pa-xs col-xs-12 col-sm-6 col-md-4">
<q-card>
<q-card-section class="text-center">
Calories for
<br>
<strong>{{ props.row.name }}</strong>
</q-card-section>
<q-separator />
<q-card-section class="flex flex-center" :style="{ fontSize: props.row.calories + 'px' }">
<div>{{ props.row.calories }} g</div>
</q-card-section>
</q-card>
</div>
</template>
</q-table>
</div>
</template>
<script>
import { useQuasar } from 'quasar'
import { ref, computed, watch } from 'vue'
const deserts = [
'Frozen Yogurt',
'Ice cream sandwich',
'Eclair',
'Cupcake',
'Gingerbread',
'Jelly bean',
'Lollipop',
'Honeycomb',
'Donut',
'KitKat'
]
const rows = []
deserts.forEach(name => {
for (let i = 0; i < 24; i++) {
rows.push({ name: name + ' (' + i + ')', calories: 20 + Math.ceil(50 * Math.random()) })
}
})
rows.sort(() => (-1 + Math.floor(3 * Math.random())))
export default {
setup () {
const $q = useQuasar()
function getItemsPerPage () {
if ($q.screen.lt.sm) {
return 3
}
if ($q.screen.lt.md) {
return 6
}
return 9
}
const filter = ref('')
const pagination = ref({
page: 1,
rowsPerPage: getItemsPerPage()
})
watch(() => $q.screen.name, () => {
pagination.value.rowsPerPage = getItemsPerPage()
})
return {
rows,
filter,
pagination,
columns: [
{ name: 'name', label: 'Name', field: 'name' },
{ name: 'calories', label: 'Calories (g)', field: 'calories' }
],
cardContainerClass: computed(() => {
return $q.screen.gt.xs
? 'grid-masonry grid-masonry--' + ($q.screen.gt.sm ? '3' : '2')
: null
}),
rowsPerPageOptions: computed(() => {
return $q.screen.gt.xs
? $q.screen.gt.sm ? [ 3, 6, 9 ] : [ 3, 6 ]
: [3]
})
}
}
}
</script>
<style lang="sass">
.grid-masonry
flex-direction: column
height: 700px
&--2
> div
&:nth-child(2n + 1)
order: 1
&:nth-child(2n)
order: 2
&:before
content: ''
flex: 1 0 100% !important
width: 0 !important
order: 1
&--3
> div
&:nth-child(3n + 1)
order: 1
&:nth-child(3n + 2)
order: 2
&:nth-child(3n)
order: 3
&:before,
&:after
content: ''
flex: 1 0 100% !important
width: 0 !important
order: 2
</style>