Skip to content

Commit 3cdc571

Browse files
committed
refactor: bouncer
1 parent c7f3881 commit 3cdc571

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

eslint.config.mjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// @ts-check
22
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'
33

4-
// Run `npx @eslint/config-inspector` to inspect the resolved config interactively
54
export default createConfigForNuxt({
65
features: {
7-
// Rules for module authors
86
tooling: true,
9-
// Rules for formatting
107
stylistic: true,
118
},
129
dirs: {
@@ -15,6 +12,7 @@ export default createConfigForNuxt({
1512
],
1613
},
1714
}).overrideRules({
15+
'@typescript-eslint/no-empty-object-type': 'off',
1816
'@typescript-eslint/no-explicit-any': 'off',
1917
'vue/multi-word-component-names': ['error', {
2018
ignores: ['Can', 'Cannot', 'Bouncer'],

src/runtime/components/Bouncer.vue

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
<script lang="ts" setup generic="Ability extends BouncerAbility<any>">
1+
<script lang="ts">
22
import type { Component } from 'vue'
33
import type { BouncerAbility, BouncerArgs } from '../../utils'
44
import { Primitive } from './Primitive'
55
import { allows, ref, watchEffect } from '#imports'
66
7-
const props = defineProps<{
7+
export interface BouncerProps {
88
ability: Ability | Ability[]
99
args?: BouncerArgs<Ability> | BouncerArgs<Ability>[]
1010
as?: string | Component
11-
}>()
11+
}
12+
export interface BouncerEmits {}
13+
export interface BouncerSlots {
14+
default?: (props?: { can: boolean }) => any
15+
can?: (props?: object) => any
16+
cannot?: (props?: object) => any
17+
}
18+
</script>
19+
20+
<script lang="ts" setup generic="Ability extends BouncerAbility<any>">
21+
const props = defineProps<BouncerProps>()
22+
defineEmits<BouncerEmits>()
23+
const slots = defineSlots<BouncerSlots>()
1224
1325
const can = ref(await resolve())
1426
@@ -31,10 +43,11 @@ async function resolve() {
3143
<Primitive
3244
:as="props.as"
3345
>
34-
<slot
35-
v-if="$slots.default"
36-
:can
37-
/>
46+
<template v-if="slots.default">
47+
<slot
48+
:can
49+
/>
50+
</template>
3851
<template v-else>
3952
<slot
4053
v-if="can"

src/types/module.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
21
export interface ModuleOptions {}

test/fixtures/components/app/app.vue

+16
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ const cannot = defineAbility(() => {
8484
</div>
8585
</Cannot>
8686

87+
<Bouncer :ability="can">
88+
<div data-testid="bouncer-default-visible">
89+
Bouncer Default Visible
90+
</div>
91+
<template #can>
92+
<div data-testid="bouncer-default-can-invisible">
93+
Bouncer Can Invisible
94+
</div>
95+
</template>
96+
<template #cannot>
97+
<div data-testid="bouncer-default-cannot-invisible">
98+
Bouncer Cannot Invisible
99+
</div>
100+
</template>
101+
</Bouncer>
102+
87103
<Bouncer
88104
:ability="can"
89105
>

0 commit comments

Comments
 (0)