Skip to content

Commit eee3a01

Browse files
author
Jeff
committed
abstract component names: Toggle and Target
1 parent 44ccb77 commit eee3a01

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

src/Dev.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<template>
22
<section class="d-flex justify-content-center align-items-center">
3-
<dropdown class="dropdown" tag="nav">
3+
<toggle class="dropdown" tag="nav">
44
<button class="btn btn-primary">Drop it Down</button>
55

6-
<dropdown-menu class="dropdown-menu show">
6+
<target class="dropdown-menu show">
77
<li class="dropdown-item">Whats up!</li>
8-
</dropdown-menu>
9-
</dropdown>
8+
</target>
9+
</toggle>
1010
</section>
1111
</template>
1212

1313
<script>
14-
import Dropdown from './Dropdown';
15-
import DropdownMenu from './DropdownMenu';
14+
import Toggle from './components/Toggle';
15+
import Target from './components/Target';
1616
1717
export default {
18-
components: {Dropdown, DropdownMenu},
18+
components: {Toggle, Target},
1919
};
2020
</script>
2121

src/DropdownMenu.vue renamed to src/components/Target.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
export default {
3-
name: 'dropdown-menu',
3+
name: 'target',
44
props: {
55
tag: {
66
type: String,
@@ -9,15 +9,15 @@ export default {
99
display: {
1010
type: String,
1111
default: 'block',
12-
}
12+
},
1313
},
1414
data: () => ({
1515
active: false,
1616
}),
1717
render (h) {
1818
return h(this.tag, {
1919
style: {
20-
display: this.active ? this.display : 'none',
20+
display: this.active ? 'block' : 'none',
2121
},
2222
}, this.$slots.default);
2323
},

src/Dropdown.vue renamed to src/components/Toggle.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<script>
22
export default {
3-
name: 'dropdown',
3+
name: 'toggle',
44
props: {
55
tag: {
66
type: String,
77
default: 'div',
88
},
99
},
1010
data: () => ({
11-
dropdown: null,
11+
target: null,
1212
}),
1313
computed: {
1414
active () {
15-
return this.dropdown ? this.dropdown.active : false;
15+
return this.target ? this.target.active : false;
1616
},
1717
},
1818
watch: {
@@ -32,21 +32,17 @@ export default {
3232
}, this.$slots.default);
3333
},
3434
mounted () {
35-
this.dropdown = this.$children.find(child => {
36-
return child.$options.name === 'dropdown-menu';
35+
this.target = this.$children.find(child => {
36+
return child.$options.name === 'target';
3737
});
3838
},
3939
methods: {
40-
toggle() {
41-
return this.dropdown.toggle();
40+
toggle () {
41+
return this.target.toggle();
4242
},
4343
clickAway (event) {
44-
if (!this.dropdown.active) {
45-
return false;
46-
}
47-
4844
if (!event.composedPath().includes(this.$el)) {
49-
this.dropdown.toggle(false);
45+
this.target.toggle(false);
5046
}
5147
},
5248
},

0 commit comments

Comments
 (0)