forked from FrontendMatter/material-design-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader-layout.js
More file actions
81 lines (70 loc) · 1.85 KB
/
Copy pathheader-layout.js
File metadata and controls
81 lines (70 loc) · 1.85 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
import { handler } from 'dom-factory'
/**
* A wrapper element that positions a Header and other content.
* @param {HTMLElement} element
* @return {Object}
*/
export const headerLayoutComponent = () => ({
/**
* Public properties.
* @type {Object}
*/
properties: {
/**
* If true, defines it's own scrolling region, otherwise uses the document scroll.
* @type {Object}
*/
hasScrollingRegion: {
type: Boolean,
reflectToAttribute: true
}
},
/**
* Property change observers.
* @type {Array}
*/
observers: [
'_updateScroller(hasScrollingRegion)',
'_updateContentPosition(hasScrollingRegion, header.fixed, header.condenses)'
],
/**
* The header layout content wrapper HTMLElement
* @return {HTMLElement}
*/
get contentContainer () {
return this.element.querySelector(':scope > .mdk-header-layout__content')
},
/**
* A reference to the header component
* @return {Object}
*/
get header () {
const headerNode = this.element.querySelector(':scope > .mdk-header')
if (headerNode) {
return headerNode.mdkHeader
}
},
_updateScroller () {
this.header.scrollTargetSelector = this.hasScrollingRegion ? this.contentContainer : null
},
_updateContentPosition () {
const headerHeight = this.header.element.offsetHeight
let containerStyle = this.contentContainer.style
if (this.header.fixed && !this.header.willCondense() && this.hasScrollingRegion) {
containerStyle.marginTop = `${ headerHeight }px`
containerStyle.paddingTop = ''
}
else {
containerStyle.paddingTop = `${ headerHeight }px`
containerStyle.marginTop = ''
}
},
/**
* Initialize component
*/
init () {
this._updateScroller()
this._updateContentPosition()
}
})
handler.register('mdk-header-layout', headerLayoutComponent)