Skip to content

Commit 77f5154

Browse files
committed
Refactored Fab component.
Set default data for FAB props. Make it work with different instance in same page.
1 parent 8b2f914 commit 77f5154

File tree

2 files changed

+75
-15
lines changed

2 files changed

+75
-15
lines changed

demo/App.vue

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,31 @@
33
<img width="400px" src="./assets/logo.png">
44
<h1></h1>
55
<h2>Floating Action Button</h2>
6-
<fab :styles="fabStyles"
6+
<fab
7+
:actions="fabActions"
8+
@cache="cache"
9+
@alertMe="alert"
10+
></fab>
11+
<fab :styles="{
12+
bgColor: '#d11014',
13+
position:'bottom-left'
14+
}"
15+
:actions="fabActions"
16+
@cache="cache"
17+
@alertMe="alert"
18+
></fab>
19+
<fab :styles="{
20+
bgColor: '#119912',
21+
position:'top-left'
22+
}"
23+
:actions="fabActions"
24+
@cache="cache"
25+
@alertMe="alert"
26+
></fab>
27+
<fab :styles="{
28+
bgColor: '#102499',
29+
position:'top-right'
30+
}"
731
:actions="fabActions"
832
@cache="cache"
933
@alertMe="alert"

src/FAB.vue

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
2-
<div class="fab-wrapper" v-on-clickaway="away" :style="[pos, {zIndex: styles.zIndex}]" >
3-
<div class="actions-container" :style="listPos">
2+
<div :id="styles.position + '-wrapper'" class="fab-wrapper" v-on-clickaway="away"
3+
:style="[pos, {zIndex: styles.zIndex}]">
4+
<div :id="styles.position + '-action'" class="actions-container" :style="listPos">
45
<transition name="fab-actions-appear"
56
:enter-active-class="transitionEnter"
67
:leave-active-class="transitionLeave"
@@ -32,7 +33,17 @@
3233
pos: {}
3334
}
3435
},
35-
props: ['styles', 'actions'],
36+
props: {
37+
styles: {
38+
default: () => {
39+
return {
40+
bgColor: '#333333',
41+
position: 'bottom-right'
42+
}
43+
}
44+
},
45+
actions: {}
46+
},
3647
computed: {
3748
listPos() {
3849
let mask = {};
@@ -109,9 +120,9 @@
109120
},
110121
moveTransition() {
111122
if (this.styles.position === 'top-right' || this.styles.position === 'top-left') {
112-
let wrapper = document.getElementsByClassName('fab-wrapper');
113-
let el = document.getElementsByClassName('actions-container');
114-
wrapper[0].appendChild(el[0]);
123+
let wrapper = document.getElementById(this.styles.position + '-wrapper');
124+
let el = document.getElementById(this.styles.position + '-action');
125+
wrapper.appendChild(el);
115126
}
116127
}
117128
},
@@ -193,34 +204,59 @@
193204
}
194205
195206
/* Rules for sizing the icon. */
196-
.material-icons.md-18 { font-size: 18px; }
197-
.material-icons.md-24 { font-size: 24px; }
198-
.material-icons.md-36 { font-size: 36px; }
199-
.material-icons.md-48 { font-size: 48px; }
207+
.material-icons.md-18 {
208+
font-size: 18px;
209+
}
210+
211+
.material-icons.md-24 {
212+
font-size: 24px;
213+
}
214+
215+
.material-icons.md-36 {
216+
font-size: 36px;
217+
}
218+
219+
.material-icons.md-48 {
220+
font-size: 48px;
221+
}
200222
201223
/* Rules for using icons as black on a light background. */
202-
.material-icons.md-dark { color: rgba(0, 0, 0, 0.54); }
203-
.material-icons.md-dark.md-inactive { color: rgba(0, 0, 0, 0.26); }
224+
.material-icons.md-dark {
225+
color: rgba(0, 0, 0, 0.54);
226+
}
227+
228+
.material-icons.md-dark.md-inactive {
229+
color: rgba(0, 0, 0, 0.26);
230+
}
204231
205232
/* Rules for using icons as white on a dark background. */
206-
.material-icons.md-light { color: rgba(255, 255, 255, 1); }
207-
.material-icons.md-light.md-inactive { color: rgba(255, 255, 255, 0.3); }
233+
.material-icons.md-light {
234+
color: rgba(255, 255, 255, 1);
235+
}
236+
237+
.material-icons.md-light.md-inactive {
238+
color: rgba(255, 255, 255, 0.3);
239+
}
208240
209241
@media screen and (max-width: 768px) {
210242
.fab-list {
211243
margin: 2vh 1.8vw;
212244
}
245+
213246
.fab-list li {
214247
width: 40px;
215248
height: 40px;
216249
}
250+
217251
.fab-list li i {
218252
font-size: 24px !important;
219253
}
254+
220255
.fab {
221256
width: 55px;
222257
height: 55px;
223258
}
259+
224260
.fab i {
225261
font-size: 34px !important;
226262
}

0 commit comments

Comments
 (0)