-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: collapse desktop header in scrolling (#288)
EMP-1003 --------- Co-authored-by: Guillermo Cacheda <cachedacodes@gmail.com>
- Loading branch information
1 parent
1e9f821
commit 979ff84
Showing
8 changed files
with
173 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<template> | ||
<div | ||
class="x-collapse-height" | ||
:class="{ | ||
'x-collapse-height--is-collapsed': isCollapsed | ||
}" | ||
> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { defineComponent } from 'vue'; | ||
export default defineComponent({ | ||
props: { | ||
isCollapsed: { | ||
type: Boolean | ||
} | ||
} | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.x-collapse-height { | ||
display: grid; | ||
grid-template-rows: 1fr; | ||
overflow: hidden; | ||
transition: grid-template-rows 0.35s; | ||
& > * { | ||
min-height: 0; | ||
transition: visibility 0.35s; | ||
visibility: visible; | ||
} | ||
&--is-collapsed { | ||
grid-template-rows: 0fr; | ||
& > * { | ||
visibility: hidden; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<template> | ||
<CollapseHeightAnimation :isCollapsed="hasScrolledPastThreshold"> | ||
<MaxDesktopWidthItem> | ||
<DesktopSearchboxAlign> | ||
<div class="x-layout-item" :class="{ 'x-grid x-grid-cols-6': !isFullPredictive }"> | ||
<LocationProvider location="predictive_layer"> | ||
<RelatedTags v-if="$x.relatedTags.length > 0" class="x-pb-24" /> | ||
</LocationProvider> | ||
</div> | ||
</DesktopSearchboxAlign> | ||
|
||
<div v-if="!$x.redirections.length && hasSearched"> | ||
<DesktopToolbar /> | ||
</div> | ||
<div v-if="$x.totalResults > 0 && hasSearched && $x.selectedFilters.length"> | ||
<SelectedFilters class="x-py-16" /> | ||
</div> | ||
</MaxDesktopWidthItem> | ||
</CollapseHeightAnimation> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
import { LocationProvider } from '@empathyco/x-components'; | ||
import RelatedTags from '../search/related-tags.vue'; | ||
import CollapseHeightAnimation from '../collapse-height-animation.vue'; | ||
import IsScrollingUp from '../has-scroll-past-threshold.mixin'; | ||
import MaxDesktopWidthItem from '../max-desktop-width-item.vue'; | ||
import DesktopSearchboxAlign from './desktop-searchbox-align.vue'; | ||
import DesktopToolbar from './desktop-toolbar.vue'; | ||
export default defineComponent({ | ||
components: { | ||
MaxDesktopWidthItem, | ||
LocationProvider, | ||
RelatedTags, | ||
CollapseHeightAnimation, | ||
DesktopToolbar, | ||
DesktopSearchboxAlign, | ||
SelectedFilters: () => import('../search').then(m => m.SelectedFilters) | ||
}, | ||
mixins: [IsScrollingUp], | ||
props: { | ||
hasSearched: { | ||
type: Boolean | ||
}, | ||
isFullPredictive: { | ||
type: Boolean | ||
} | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<div> | ||
<DesktopHeaderFullPredictive /> | ||
|
||
<DesktopSubHeader :hasSearched="hasSearched" :isFullPredictive="true" class="x-layout-item" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { defineComponent } from 'vue'; | ||
import HasSearchedMixin from '../has-searched.mixin.ts'; | ||
import DesktopHeaderFullPredictive from './desktop-header-full-predictive.vue'; | ||
import DesktopSubHeader from './desktop-sub-header.vue'; | ||
export default defineComponent({ | ||
components: { DesktopSubHeader, DesktopHeaderFullPredictive }, | ||
mixins: [HasSearchedMixin] | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { State } from '@empathyco/x-components'; | ||
import Vue from 'vue'; | ||
import Component from 'vue-class-component'; | ||
import { Dictionary } from '@empathyco/x-utils'; | ||
import { ScrollComponentState } from '@empathyco/x-components/scroll'; | ||
import { Watch } from 'vue-property-decorator'; | ||
@Component | ||
export default class IsScrollingUp extends Vue { | ||
protected hasScrolledPastThresholdFlag = false; | ||
protected scrollOffset = 200; | ||
|
||
@State('scroll', 'data') | ||
public scrollPositionsMap!: Dictionary<ScrollComponentState>; | ||
protected get mainScrollPosition(): number { | ||
return this.scrollPositionsMap['main-scroll']?.position; | ||
} | ||
|
||
@Watch('mainScrollPosition', { deep: true }) | ||
updateHasScrolledPastThreshold(): void { | ||
// TODO change this implementation when the scroll module is fixed. Task EMP-1049 | ||
const mainScrollData = this.scrollPositionsMap['main-scroll']; | ||
|
||
if (mainScrollData?.hasReachedStart) { | ||
this.hasScrolledPastThresholdFlag = false; | ||
return; | ||
} | ||
|
||
if (mainScrollData?.hasAlmostReachedEnd) { | ||
this.hasScrolledPastThresholdFlag = true; | ||
return; | ||
} | ||
|
||
const isScrollingUp = mainScrollData?.direction === 'UP'; | ||
if (isScrollingUp || this.mainScrollPosition < this.scrollOffset) { | ||
this.hasScrolledPastThresholdFlag = false; | ||
} else if (!isScrollingUp && this.mainScrollPosition > this.scrollOffset) { | ||
this.hasScrolledPastThresholdFlag = true; | ||
} | ||
} | ||
|
||
/** | ||
* Checks the direction and the position of the scroll. | ||
* | ||
* @returns True if the user is scrolling up and has scrolled more than | ||
* the defined scrollOffset. | ||
*/ | ||
protected get hasScrolledPastThreshold(): boolean { | ||
return this.hasScrolledPastThresholdFlag; | ||
} | ||
} |