deno.land / x / nano_jsx@v0.1.0 / ui / appBar.ts

نووسراو ببینە
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
import { Component } from '../component.ts'import { h } from '../core.ts'import { boxShadow, zIndex } from './_config.ts'
const classes = { container: 'appBar_container', scrollingDown: 'appBar_scrolling_down'}
interface AppBarProps { maxWidth?: number autoHide?: boolean autoMerge?: boolean background?: string color?: string}
export class AppBar extends Component<AppBarProps> { curr_scrollY: number = 0 last_scrollY: number = 0 curr_scrollingState = 'none' last_scrollingState = 'none' container: HTMLElement
calcScrollPosition() { this.curr_scrollY = window.scrollY
if (this.curr_scrollY > this.last_scrollY) { this.curr_scrollingState = 'down' } else if (this.curr_scrollY < this.last_scrollY) { this.curr_scrollingState = 'up' }
this.last_scrollY = this.curr_scrollY }
scroll() { this.calcScrollPosition()
if (this.curr_scrollY < 1) { this.container.classList.remove('appBar_scrolling_down') } else if (this.last_scrollingState !== this.curr_scrollingState) { this.last_scrollingState = this.curr_scrollingState
if (this.curr_scrollingState === 'down') this.container.classList.add('appBar_scrolling_down') else this.container.classList.remove('appBar_scrolling_down') } }
merge() { this.calcScrollPosition()
if (this.curr_scrollY <= 1) { this.container.classList.add('appBar_merged') } else { this.container.classList.remove('appBar_merged') } }
didMount() { this.curr_scrollY = this.last_scrollY = window.scrollY
if (this.props.autoHide) window.addEventListener('scroll', () => this.scroll()) if (this.props.autoMerge) window.addEventListener('scroll', () => this.merge()) }
didUnmount() { if (this.props.autoHide) window.removeEventListener('scroll', this.scroll) if (this.props.autoMerge) window.removeEventListener('scroll', () => this.merge()) }
render() { const { background = '#6200EE', color = 'white' } = this.props
const styles = ` .appBar_container { background: ${background}; color: ${color}; font-weight: 500;
z-index: ${zIndex.bar}
position: fixed; top: 0; left: 0; min-height: 24px; width: 100vw;

${boxShadow}
transition: top 0.2s, -webkit-box-shadow 0.5s, -moz-box-shadow 0.5s, box-shadow 0.5s; }
.appBar_container.appBar_scrolling_down { top: -56px; }
.appBar_container.appBar_merged { -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; }
.appBar_container .toolbar_container { display: flex; justify-content: space-between; }
.appBar_container .toolbar_container, .appBar_container .tabs_container { margin: 0 auto; ${this.props.maxWidth ? `max-width: ${this.props.maxWidth}px;` : ''} }
.appBar_container .toolbar_container .toolbar_left, .appBar_container .toolbar_container .toolbar_right { display: flex; align-items: center; }
.appBar_container .toolbar_container .toolbar_left { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appBar_container .toolbar_title { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } `
document.head.appendChild(h('style', {}, styles))
const mergedClass = this.props.autoMerge ? 'appBar_merged' : ''
// @ts-ignore this.container = h('div', { class: `${classes.container} ${mergedClass}` }, this.props.children)
return this.container }}
nano_jsx

Version Info

Tagged at
8 months ago