Skip to content

Commit 26f06dd

Browse files
committed
Add Container component and integrate with ButtonApp
Introduced a new reusable Container component with named slots (header, default, and footer) to enhance layout flexibility. Updated ButtonApp to use Container and refactored the template structure for better organization. Included a counter functionality in the Container for dynamic data binding.
1 parent 28baf0a commit 26f06dd

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/components/ButtonApp.vue

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<script setup>
22
33
import MyButton from "./MyButton.vue";
4+
import Container from "./Container.vue";
45
5-
function clickHandler(){
6+
function clickHandler() {
67
alert("You click me");
78
}
89
</script>
910

1011
<template>
11-
<MyButton class="button" @click="clickHandler" name="Eko" contoh="Kurniawan"/>
12+
<Container title="Contoh Button">
13+
<template #header="attributes">
14+
<h1>Button App {{attributes.counter}}</h1>
15+
</template>
16+
<template v-slot:default="attributes">
17+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci asperiores cumque eius, fuga illum inventore maxime nobis nostrum perferendis quaerat sed similique sunt. Beatae explicabo magnam optio. Autem, debitis, enim!</p>
18+
<MyButton class="button" @click="clickHandler" :name="attributes.counter" contoh="Kurniawan"/>
19+
</template>
20+
<template #footer>
21+
<p>Copyright 2024 @ProgrammerZamanNow</p>
22+
</template>
23+
</Container>
1224
</template>
1325

1426
<style scoped>

src/components/Container.vue

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script setup>
2+
import {ref, useSlots} from "vue";
3+
4+
const slots = useSlots();
5+
const counter = ref(0);
6+
</script>
7+
8+
<template>
9+
<div v-if="slots.header">
10+
<slot name="header" :counter="counter">
11+
<h1>Default Header</h1>
12+
</slot>
13+
</div>
14+
<div v-if="slots.default">
15+
<slot name="default" :counter="counter">
16+
<p>Anda belum mengisi content nya</p>
17+
</slot>
18+
</div>
19+
<div v-if="slots.footer">
20+
<slot name="footer" :counter="counter">
21+
<p>Default Footer</p>
22+
</slot>
23+
</div>
24+
<div>
25+
<button @click="counter++">Increment Counter</button>
26+
</div>
27+
</template>
28+
29+
<style scoped>
30+
31+
</style>

0 commit comments

Comments
 (0)