pinafore/routes/_components/virtualList/VirtualListHeader.html

61 lines
1.6 KiB
HTML
Raw Normal View History

<div class="virtual-list-header {shown ? 'shown' : ''} {fadedIn ? 'faded-in' : ''}"
2018-02-12 04:15:21 +01:00
ref:node >
<svelte:component this={component} {virtualProps} />
2018-02-12 04:15:21 +01:00
</div>
<style>
.virtual-list-header {
position: absolute;
top: 0;
width: 100%;
opacity: 0;
z-index: 10;
2018-02-12 07:50:20 +01:00
transition: none;
display: none;
2018-02-12 04:15:21 +01:00
}
.virtual-list-header.shown {
display: block;
2018-02-12 07:50:20 +01:00
transition: opacity 0.333s linear;
2018-02-12 04:15:21 +01:00
}
.virtual-list-header.faded-in {
opacity: 1;
}
2018-02-12 04:15:21 +01:00
</style>
<script>
import { virtualListStore } from './virtualListStore'
import { doubleRAF } from '../../_utils/doubleRAF'
import { mark, stop } from '../../_utils/marks'
import { observe } from 'svelte-extras'
2018-02-12 04:15:21 +01:00
export default {
2018-04-20 06:38:01 +02:00
oncreate () {
this.observe('shown', shown => {
if (shown) {
this.doCalculateHeight()
doubleRAF(() => this.set({ fadedIn: true })) // animate in
} else {
this.set({ fadedIn: false })
}
}, { init: false })
2018-02-12 04:15:21 +01:00
},
data: () => ({
fadedIn: false
}),
2018-02-12 04:15:21 +01:00
store: () => virtualListStore,
methods: {
observe,
2018-04-20 06:38:01 +02:00
doCalculateHeight () {
let { heightCalculated } = this.get()
if (heightCalculated) { // only need to calculate once, it never changes
return
}
this.set({ heightCalculated: true })
requestAnimationFrame(() => {
mark('VirtualListHeader gBCR')
let rect = this.refs.node.getBoundingClientRect()
stop('VirtualListHeader gBCR')
this.store.setForRealm({ headerHeight: rect.height })
})
}
}
2018-02-12 04:15:21 +01:00
}
</script>