Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(QIntersection): allow HTML tag to be used for wrapper element #6386

Merged
merged 6 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/assets/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ const components = [
},
{
name: 'Intersection',
badge: 'update',
path: 'intersection'
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/vue-components/intersection.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ related:

The QIntersection component is essentially a wrapper over the [Intersection directive](/vue-directives/intersection) with the added benefit that it handles the state by itself (does not requires you to add it and handle it manually) and can optionally have a show/hide transition as well.

The main benefit of using QIntersection is, however, that the DOM tree is freed up of hidden nodes thus using the minimum possible RAM memory and making the page feel very snappy.
The main benefit of using QIntersection is, however, that the DOM tree is freed up of hidden nodes thus using the minimum possible RAM memory and making the page feel very snappy. As well, you can specify the `tag` property for the wrapper element to match your own needs, thus eliminating yet another DOM node.

Under the covers, it uses the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).

Expand Down
51 changes: 51 additions & 0 deletions ui/dev/src/pages/components/intersection2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div class="q-pa-md">
<div>
<q-toggle v-model="visible" label="Visible" />
<q-toggle v-model="once" label="Once" />
<q-select v-model="transition" :options="['', 'fade', 'scale', 'flip-right']" style="min-width: 250px" />
</div>
<div class="row justify-center q-gutter-sm" v-if="visible">
<q-intersection
v-for="index in 600"
:key="index"
:once="once"
:transition="transition"
:tag="tags[index % 2]"
class="int-example-item flex flex-center"
>
<q-card class="q-ma-sm">
<img src="https://cdn.quasar.dev/img/mountains.jpg">

<q-card-section>
<div class="text-h6">
Card #{{ index }}
</div>
<div class="text-subtitle2">
by John Doe
</div>
</q-card-section>
</q-card>
</q-intersection>
</div>
</div>
</template>

<script>
export default {
data () {
return {
visible: true,
once: false,
transition: 'scale',
tags: ['div', 'blockquote']
}
}
}
</script>

<style lang="sass">
.int-example-item
height: 290px
width: 290px
</style>
55 changes: 55 additions & 0 deletions ui/dev/src/pages/components/intersection3.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<div class="q-pa-md">
<div>
<q-toggle v-model="visible" label="Visible" />
<q-toggle v-model="once" label="Once" />
<q-select v-model="transition" :options="['', 'fade', 'scale', 'flip-right']" style="min-width: 250px" />
</div>
<table v-if="visible">
<tr
v-for="index in 10"
:key="index"
>
<q-intersection
v-for="i in 4"
:key="index * 10 + i"
:once="once"
:transition="transition"
tag="td"
class="int-example-item"
>
<q-card class="q-ma-sm">
<img src="https://cdn.quasar.dev/img/mountains.jpg">

<q-card-section>
<div class="text-h6">
Card #{{ index }}
</div>
<div class="text-subtitle2">
by John Doe
</div>
</q-card-section>
</q-card>
</q-intersection>
</tr>
</table>
</div>
</template>

<script>
export default {
data () {
return {
visible: true,
once: false,
transition: 'scale'
}
}
}
</script>

<style lang="sass">
.int-example-item
height: 290px
width: 290px
</style>
5 changes: 4 additions & 1 deletion ui/src/components/intersection/QIntersection.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Vue from 'vue'

import Intersection from '../../directives/Intersection.js'
import TagMixin from '../../mixins/tag.js'
import { slot } from '../../utils/slot.js'

export default Vue.extend({
name: 'QIntersection',

mixins: [ TagMixin ],

directives: {
Intersection
},
Expand Down Expand Up @@ -57,7 +60,7 @@ export default Vue.extend({
? [ h('div', { key: 'content' }, slot(this, 'default')) ]
: void 0

return h('div', {
return h(this.tag, {
staticClass: 'q-intersection',
on: this.$listeners,
directives: this.disable === true ? null : [{
Expand Down
7 changes: 7 additions & 0 deletions ui/src/components/intersection/QIntersection.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"mixins": [ "mixins/tag" ],

"meta": {
"docsUrl": "https://v1.quasar.dev/vue-components/intersection"
},
Expand All @@ -8,6 +10,11 @@
},

"props": {
"tag": {
"examples": [ "div", "span", "blockquote" ],
"addedIn": "v1.9.3"
},

"once": {
"type": "Boolean",
"desc": "Get triggered only once",
Expand Down