deno.land / x / nano_jsx@v0.1.0 / ui / navigation.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
147
148
149
150
151
152
153
154
155
import { h } from '../core.ts'import { Component } from '../component.ts'import { boxShadow, zIndex } from './_config.ts'import { Icon } from './icon.ts'
interface NavigationProps { parentId?: string children?: Component<any>[] onClick?: (e: { id: string; label: string; component: NavigationAction; navigate: boolean }) => void}
interface ActionProps { id?: string label: string active?: boolean icon?: any link?: string onClick?: (e: { id: string; label: string; component: NavigationAction; navigate: boolean }) => void}
const classes = { label: 'bottom_navigation_label', action: 'bottom_navigation_action', idPrefix: 'bottom_navigation_action_id-', inactive: 'bottom_navigation_action_inactive', initialActive: 'bottom_navigation_label_initial_active'}
export class NavigationAction extends Component<ActionProps> { willMount() { this.id = this.props.id ?? this.props.label.toLowerCase().replace(/\s/gm, '-').replace(/[-]+/gm, '-') }
render() { const label = h('span', { class: classes.label }, this.props.label)
const actionClasses = [classes.action] if (this.props.active) actionClasses.push(classes.initialActive) else actionClasses.push(classes.inactive)
return h( 'div', { id: `${classes.idPrefix}${this.id}`, class: actionClasses.join(' '), onClick: () => { if (this.props.link) window.location.href = this.props.link this.props.onClick?.({ navigate: !!this.props.link, id: this.id, label: this.props.label, component: this }) } }, this.props.icon ? h(Icon, { size: 22, style: 'margin-bottom: 2px;', src: this.props.icon }) : null, label ) }}
export class Navigation extends Component<NavigationProps> { didMount() { const children = this.props.children as Component<ActionProps>[]
children.forEach(c => { c.props.onClick = e => { if (e.navigate) return const elements = document.querySelectorAll(`[id^="${classes.idPrefix}"]`) elements.forEach(el => { if (el.id === `${classes.idPrefix}${e.id}`) el.classList.remove(classes.inactive) else el.classList.add(classes.inactive) }) this.props.onClick?.(e) } }) }
render() { const colors = { active: '#6204EE', inactive: '#00000070' }
const styles = ` #bottom_navigation_container {
background-color: white; position: fixed; bottom: 0; left: 0; width: 100vw; min-height: 56px;
z-index: ${zIndex.navigation}
display: flex; justify-content: center; ${boxShadow} }
#bottom_navigation_container .bottom_navigation_label { transition: font-size 0.2s; }
#bottom_navigation_container .bottom_navigation_label_initial_active .bottom_navigation_label{ animation-name: bottom_navigation_label_fontsize; animation-duration: 0.2s; }
@keyframes bottom_navigation_label_fontsize { from {font-size: 12px;} to {font-size: 14px;} }
#bottom_navigation_container .bottom_navigation_action { color: ${colors.active}; font-size: 14px;
min-width: 80px; max-width: 168px; flex-grow: 1;
display: flex; flex-direction: column; justify-content: center; align-items: center;
cursor: pointer; }
#bottom_navigation_container .bottom_navigation_action_inactive{ color: ${colors.inactive}; font-size: 12px; }
#bottom_navigation_container .bottom_navigation_action_inactive i { background-color: ${colors.inactive} } `
document.head.appendChild(h('style', {}, styles))
const { parentId, children } = this.props
const navigation = h('div', { id: 'bottom_navigation_container' }, children)
if (parentId) { const parent = document.getElementById(parentId) if (parent) { parent.appendChild(navigation) return } }
return navigation }}
nano_jsx

Version Info

Tagged at
8 months ago