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
| <template>
| <div
| :class="wrapClasses"
| :style="wrapStyles">
| <span v-show="showZeroTrigger" @click="toggleCollapse" :class="zeroWidthTriggerClasses">
| <i class="ivu-icon ivu-icon-ios-menu"></i>
| </span>
| <div :class="childClasses">
| <slot></slot>
| </div>
| <slot name="trigger">
| <div v-show="showBottomTrigger" :class="triggerClasses" @click="toggleCollapse" :style="{width: siderWidth + 'px'}">
| <i :class="triggerIconClasses"></i>
| </div>
| </slot>
| </div>
| </template>
| <script>
| import { on, off } from '../../utils/dom';
| import { oneOf, dimensionMap, setMatchMedia } from '../../utils/assist';
| const prefixCls = 'ivu-layout-sider';
| setMatchMedia();
| export default {
| name: 'Sider',
| props: {
| value: { // if it's collpased now
| type: Boolean,
| default: false
| },
| width: {
| type: [Number, String],
| default: 200
| },
| collapsedWidth: {
| type: [Number, String],
| default: 64
| },
| hideTrigger: {
| type: Boolean,
| default: false
| },
| breakpoint: {
| type: String,
| validator (val) {
| return oneOf(val, ['xs', 'sm', 'md', 'lg', 'xl', 'xxl']);
| }
| },
| collapsible: {
| type: Boolean,
| default: false
| },
| defaultCollapsed: {
| type: Boolean,
| default: false
| },
| reverseArrow: {
| type: Boolean,
| default: false
| }
| },
| data () {
| return {
| prefixCls: prefixCls,
| mediaMatched: false
| };
| },
| computed: {
| wrapClasses () {
| return [
| `${prefixCls}`,
| this.siderWidth ? '' : `${prefixCls}-zero-width`,
| this.value ? `${prefixCls}-collapsed` : ''
| ];
| },
| wrapStyles () {
| return {
| width: `${this.siderWidth}px`,
| minWidth: `${this.siderWidth}px`,
| maxWidth: `${this.siderWidth}px`,
| flex: `0 0 ${this.siderWidth}px`
| };
| },
| triggerClasses () {
| return [
| `${prefixCls}-trigger`,
| this.value ? `${prefixCls}-trigger-collapsed` : '',
| ];
| },
| childClasses () {
| return `${this.prefixCls}-children`;
| },
| zeroWidthTriggerClasses () {
| return [
| `${prefixCls}-zero-width-trigger`,
| this.reverseArrow ? `${prefixCls}-zero-width-trigger-left` : ''
| ];
| },
| triggerIconClasses () {
| return [
| 'ivu-icon',
| `ivu-icon-ios-arrow-${this.reverseArrow ? 'forward' : 'back'}`,
| `${prefixCls}-trigger-icon`,
| ];
| },
| siderWidth () {
| return this.collapsible ? (this.value ? (this.mediaMatched ? 0 : parseInt(this.collapsedWidth)) : parseInt(this.width)) : this.width;
| },
| showZeroTrigger () {
| return this.collapsible ? (this.mediaMatched && !this.hideTrigger || (parseInt(this.collapsedWidth) === 0) && this.value && !this.hideTrigger) : false;
| },
| showBottomTrigger () {
| return this.collapsible ? !this.mediaMatched && !this.hideTrigger : false;
| }
| },
| methods: {
| toggleCollapse () {
| let value = this.collapsible ? !this.value : false;
| this.$emit('input', value);
| },
| matchMedia () {
| let matchMedia;
| if (window.matchMedia) {
| matchMedia = window.matchMedia;
| }
| let mediaMatched = this.mediaMatched;
| this.mediaMatched = matchMedia(`(max-width: ${dimensionMap[this.breakpoint]})`).matches;
|
| if (this.mediaMatched !== mediaMatched) {
| this.$emit('input', this.mediaMatched);
| }
| },
| onWindowResize () {
| this.matchMedia();
| }
| },
| watch: {
| value (stat) {
| this.$emit('on-collapse', stat);
| }
| },
| mounted () {
| if (this.defaultCollapsed) {
| this.$emit('input', this.defaultCollapsed);
| }
| if (this.breakpoint !== undefined) {
| on(window, 'resize', this.onWindowResize);
| this.matchMedia();
| }
| },
| beforeDestroy () {
| if (this.breakpoint !== undefined) {
| off(window, 'resize', this.onWindowResize);
| }
| }
| };
| </script>
|
|