|
1 | 1 | <script> |
2 | | -import MdAppSideDrawer from './MdAppSideDrawer' |
3 | | -import MdAppInternalDrawer from './MdAppInternalDrawer' |
| 2 | + import MdAppSideDrawer from './MdAppSideDrawer' |
| 3 | + import MdAppInternalDrawer from './MdAppInternalDrawer' |
4 | 4 |
|
5 | | -const componentTypes = [ |
6 | | - 'md-app-toolbar', |
7 | | - 'md-app-drawer', |
8 | | - 'md-app-content' |
9 | | -] |
| 5 | + const componentTypes = [ |
| 6 | + 'md-app-toolbar', |
| 7 | + 'md-app-drawer', |
| 8 | + 'md-app-content' |
| 9 | + ] |
10 | 10 |
|
11 | | -function buildSlots (children, context, functionalContext, options) { |
12 | | - let slots = [] |
| 11 | + function buildSlots (children, context, functionalContext, options) { |
| 12 | + let slots = [] |
13 | 13 |
|
14 | | - if (children) { |
15 | | - children.forEach(child => { |
16 | | - const opts = child.componentOptions |
| 14 | + if (children) { |
| 15 | + children.forEach(child => { |
| 16 | + const opts = child.componentOptions |
17 | 17 |
|
18 | | - if (opts && componentTypes.includes(opts.tag)) { |
19 | | - child.data.slot = opts.tag |
20 | | - child.data.provide = options.Ctor.options.provide |
21 | | - child.context = context |
22 | | - child.functionalContext = functionalContext |
| 18 | + if (opts && componentTypes.includes(opts.tag)) { |
| 19 | + child.data.slot = opts.tag |
| 20 | + child.data.provide = options.Ctor.options.provide |
| 21 | + child.context = context |
| 22 | + child.functionalContext = functionalContext |
23 | 23 |
|
24 | | - slots.push(child) |
25 | | - } |
26 | | - }) |
27 | | - } |
| 24 | + slots.push(child) |
| 25 | + } |
| 26 | + }) |
| 27 | + } |
28 | 28 |
|
29 | | - return slots |
30 | | -} |
| 29 | + return slots |
| 30 | + } |
31 | 31 |
|
32 | | -function getDrawer (children) { |
33 | | - const drawerVnode = children.filter(child => { |
34 | | - return child.componentOptions.tag === 'md-app-drawer' |
35 | | - }) |
| 32 | + function getDrawer (children) { |
| 33 | + const drawerVnode = children.filter(child => { |
| 34 | + return child.componentOptions.tag === 'md-app-drawer' |
| 35 | + }) |
36 | 36 |
|
37 | | - return drawerVnode && drawerVnode[0] |
38 | | -} |
| 37 | + return drawerVnode && drawerVnode[0] |
| 38 | + } |
39 | 39 |
|
40 | | -function hasInternalDrawer (attrs) { |
41 | | - const mdPermanent = attrs && attrs['md-permanent'] |
| 40 | + function hasInternalDrawer (attrs) { |
| 41 | + const mdPermanent = attrs && attrs['md-permanent'] |
42 | 42 |
|
43 | | - return mdPermanent && (mdPermanent === 'clipped' || mdPermanent === 'card') |
44 | | -} |
| 43 | + return mdPermanent && (mdPermanent === 'clipped' || mdPermanent === 'card') |
| 44 | + } |
45 | 45 |
|
46 | | -export default { |
47 | | - name: 'MdApp', |
48 | | - functional: true, |
49 | | - render (createElement, { children, props }) { |
50 | | - let appComponent = MdAppSideDrawer |
51 | | - const { context, functionalContext, componentOptions } = createElement(appComponent) |
52 | | - const slots = buildSlots(children, context, functionalContext, componentOptions) |
53 | | - const drawer = getDrawer(slots) |
| 46 | + export default { |
| 47 | + name: 'MdApp', |
| 48 | + functional: true, |
| 49 | + render (createElement, { children, props }) { |
| 50 | + let appComponent = MdAppSideDrawer |
| 51 | + const { context, functionalContext, componentOptions } = createElement(appComponent) |
| 52 | + const slots = buildSlots(children, context, functionalContext, componentOptions) |
| 53 | + const drawer = getDrawer(slots) |
| 54 | +
|
| 55 | + if (drawer && hasInternalDrawer(drawer.data.attrs)) { |
| 56 | + appComponent = MdAppInternalDrawer |
| 57 | + } |
54 | 58 |
|
55 | | - if (drawer && hasInternalDrawer(drawer.data.attrs)) { |
56 | | - appComponent = MdAppInternalDrawer |
| 59 | + return createElement(appComponent, { |
| 60 | + attrs: props |
| 61 | + }, slots) |
57 | 62 | } |
58 | | -
|
59 | | - return createElement(appComponent, { |
60 | | - attrs: props |
61 | | - }, slots) |
62 | 63 | } |
63 | | -} |
64 | 64 | </script> |
65 | 65 |
|
66 | 66 | <style lang="scss"> |
|
0 commit comments