Skip to content

Commit 02ef571

Browse files
committed
feat(ui): add popover component
1 parent 3b4881a commit 02ef571

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script setup lang="ts">
2+
import type { PopoverRootEmits, PopoverRootProps } from 'radix-vue'
3+
import { PopoverRoot, useForwardPropsEmits } from 'radix-vue'
4+
5+
const props = defineProps<PopoverRootProps>()
6+
const emits = defineEmits<PopoverRootEmits>()
7+
8+
const forwarded = useForwardPropsEmits(props, emits)
9+
</script>
10+
11+
<template>
12+
<PopoverRoot v-bind="forwarded">
13+
<slot />
14+
</PopoverRoot>
15+
</template>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script setup lang="ts">
2+
import type { PopoverContentEmits, PopoverContentProps } from 'radix-vue'
3+
import type { HTMLAttributes } from 'vue'
4+
import { cn } from '@/lib/utils'
5+
import {
6+
PopoverContent,
7+
8+
PopoverPortal,
9+
useForwardPropsEmits,
10+
} from 'radix-vue'
11+
import { computed } from 'vue'
12+
13+
defineOptions({
14+
inheritAttrs: false,
15+
})
16+
17+
const props = withDefaults(
18+
defineProps<PopoverContentProps & { class?: HTMLAttributes['class'] }>(),
19+
{
20+
align: 'center',
21+
sideOffset: 4,
22+
},
23+
)
24+
const emits = defineEmits<PopoverContentEmits>()
25+
26+
const delegatedProps = computed(() => {
27+
const { class: _, ...delegated } = props
28+
29+
return delegated
30+
})
31+
32+
const forwarded = useForwardPropsEmits(delegatedProps, emits)
33+
</script>
34+
35+
<template>
36+
<PopoverPortal>
37+
<PopoverContent
38+
v-bind="{ ...forwarded, ...$attrs }"
39+
:class="
40+
cn(
41+
'z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
42+
props.class,
43+
)
44+
"
45+
>
46+
<slot />
47+
</PopoverContent>
48+
</PopoverPortal>
49+
</template>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script setup lang="ts">
2+
import type { PopoverTriggerProps } from 'radix-vue'
3+
import { PopoverTrigger } from 'radix-vue'
4+
5+
const props = defineProps<PopoverTriggerProps>()
6+
</script>
7+
8+
<template>
9+
<PopoverTrigger v-bind="props">
10+
<slot />
11+
</PopoverTrigger>
12+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as Popover } from './Popover.vue'
2+
export { default as PopoverContent } from './PopoverContent.vue'
3+
export { default as PopoverTrigger } from './PopoverTrigger.vue'

unraid-ui/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ export {
155155
type ButtonProps,
156156
};
157157
export { Toaster } from '@/components/common/toast';
158+
export * from '@/components/common/popover';

0 commit comments

Comments
 (0)