Skip to content

Commit b866e13

Browse files
authored
feat: support multiple slots in Bouncer component (#38)
1 parent f8e73cb commit b866e13

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

playground/app/app.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,14 @@ const editableProduct = ref<Product>({
8686
<p>I cannot delete a product.</p>
8787
</template>
8888
</Bouncer>
89+
90+
<Bouncer
91+
v-slot="{ can }"
92+
:ability="deleteProduct"
93+
:args="[product]"
94+
as="p"
95+
>
96+
Can I delete the product ? {{ can ? 'Yes' : 'No' }}
97+
</Bouncer>
8998
</div>
9099
</template>

src/runtime/components/Bouncer.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ async function resolve() {
3232
:as="props.as"
3333
>
3434
<slot
35-
v-if="can"
36-
name="can"
37-
/>
38-
<slot
39-
v-else
40-
name="cannot"
35+
v-if="$slots.default"
36+
:can
4137
/>
38+
<template v-else>
39+
<slot
40+
v-if="can"
41+
name="can"
42+
/>
43+
<slot
44+
v-else
45+
name="cannot"
46+
/>
47+
</template>
4248
</Primitive>
4349
</template>

0 commit comments

Comments
 (0)