-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
MdApp.vue
243 lines (198 loc) · 5.58 KB
/
MdApp.vue
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<script>
import Vue from 'vue'
import MdAppSideDrawer from './MdAppSideDrawer'
import MdAppInternalDrawer from './MdAppInternalDrawer'
import MdDrawerRightPrevious from '../MdDrawer/MdDrawerRightPrevious';
const componentTypes = [
'md-app-toolbar',
'md-app-drawer',
'md-app-content'
]
function isValidChild (componentOptions) {
return componentOptions && componentTypes.includes(componentOptions.tag)
}
function isRightDrawer ({ mdRight }) {
return mdRight === '' || !!mdRight
}
function createRightDrawer (isMdRight) {
if (isMdRight) {
const drawerRightPrevious = createElement(MdDrawerRightPrevious, { props: {...child.data.attrs}})
drawerRightPrevious.data.slot = 'md-app-drawer-right-previous'
slots.push(drawerRightPrevious)
}
}
function shouldRenderSlot (data, componentOptions) {
return (data && componentTypes.includes(data.slot)) || isValidChild(componentOptions)
}
function generateAttrKeys (attrs) {
return JSON.stringify({
'persistent': attrs && attrs['md-persistent'],
'permanent': attrs && attrs['md-permanent']
})
}
function buildSlots (children, context, functionalContext, options, createElement) {
let slots = []
let hasDrawer = false
if (children) {
children.forEach(child => {
/* eslint-enable */
const data = child.data
const componentOptions = child.componentOptions
if (shouldRenderSlot(data, componentOptions)) {
child.data.slot = data.slot || componentOptions.tag
if (componentOptions.tag === 'md-app-drawer') {
const isRight = isRightDrawer(componentOptions.propsData)
if (hasDrawer) {
Vue.util.warn(`There shouldn't be more than one drawer in a MdApp at one time.`)
return
}
hasDrawer = true
child.data.slot += `-${isRight ? 'right' : 'left'}`
child.key = generateAttrKeys(data.attrs)
createRightDrawer(isRight)
}
child.data.provide = options.Ctor.options.provide
child.context = context
child.functionalContext = functionalContext
slots.push(child)
}
})
}
return slots
}
function getDrawers (children) {
const drawerVnodes = children.filter(child => {
return child.componentOptions.tag === 'md-app-drawer'
})
return drawerVnodes.length ? drawerVnodes : []
}
function hasInternalDrawer (attrs) {
const mdPermanent = attrs && attrs['md-permanent']
return mdPermanent && (mdPermanent === 'clipped' || mdPermanent === 'card')
}
export default {
name: 'MdApp',
functional: true,
render (createElement, { children, props, data }) {
let appComponent = MdAppSideDrawer
const { context, functionalContext, componentOptions } = createElement(appComponent)
const slots = buildSlots(children, context, functionalContext, componentOptions, createElement)
const drawers = getDrawers(slots)
drawers.forEach(drawer => {
if (drawer && hasInternalDrawer(drawer.data.attrs)) {
appComponent = MdAppInternalDrawer
}
})
const staticClass = {}
if (data.staticClass) {
data.staticClass.split(/\s+/).forEach(name => {
if (name.length === 0) return
staticClass[name] = true
})
}
return createElement(appComponent, {
attrs: props,
class: {...staticClass, ...data.class},
style: {...data.staticStyle, ...data.style},
}, slots)
}
}
</script>
<style lang="scss">
@import "~components/MdAnimation/variables";
@import "~components/MdLayout/mixins";
.md-app {
display: flex;
overflow: hidden;
position: relative;
&.md-fixed {
.md-app-scroller {
overflow: auto;
}
}
&.md-reveal,
&.md-fixed-last,
&.md-overlap,
&.md-flexible {
transform: translate3d(0, 0, 0);
.md-app-toolbar {
position: absolute;
top: 0;
}
}
&.md-flexible,
&.md-overlap {
.md-app-toolbar {
min-height: 0;
}
}
&.md-flexible {
.md-toolbar-row {
&:first-child {
z-index: 2;
}
&:last-child {
position: fixed;
bottom: 0;
z-index: 1;
}
}
.md-display-1 {
position: fixed;
}
}
&.md-overlap {
.md-app-toolbar {
z-index: 1;
}
.md-app-content {
margin: -64px 24px 24px;
position: relative;
z-index: 2;
@include md-layout-small {
margin: -64px 16px 16px;
}
@include md-layout-xsmall {
margin: -64px 8px 8px;
}
}
}
}
.md-app-drawer {
&.md-permanent-card + .md-app-scroller .md-content {
@include md-layout-small-and-up {
padding-left: 0;
padding-right: 0;
border-left: none;
border-right: none;
}
}
}
.md-app-content {
padding: 16px;
@include md-layout-small-and-up {
border-left: 1px solid transparent;
border-right: 1px solid transparent;
}
> p {
&:first-child {
margin-top: 0;
}
&:last-child {
margin-bottom: 0;
}
}
}
.md-app-container {
flex: 1;
display: flex;
overflow: auto;
transform: translate3D(0, 0, 0);
transition: padding-left .4s $md-transition-default-timing,
padding-right .4s $md-transition-default-timing;
will-change: padding-left, padding-right;
}
.md-app-scroller {
flex: 1;
}
</style>