From d9416e81f870ea4cc733c0701999580d665c1bf2 Mon Sep 17 00:00:00 2001 From: zernonia <59365435+zernonia@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:10:31 +0800 Subject: [PATCH] feat: popover (#6) * feat: add popover demo * chore: rename parseEmit, fix tsconfig baseURL missing --- packages/shadcn-vue/src/App.vue | 5 +- .../shadcn-vue/src/components/ui/Popover.ts | 29 ++++++++ .../src/components/ui/PopoverDemo.vue | 67 +++++++++++++++++++ packages/shadcn-vue/src/utils.ts | 2 +- packages/shadcn-vue/tsconfig.json | 1 + 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 packages/shadcn-vue/src/components/ui/Popover.ts create mode 100644 packages/shadcn-vue/src/components/ui/PopoverDemo.vue diff --git a/packages/shadcn-vue/src/App.vue b/packages/shadcn-vue/src/App.vue index e2f833c8..89d0308b 100644 --- a/packages/shadcn-vue/src/App.vue +++ b/packages/shadcn-vue/src/App.vue @@ -1,9 +1,12 @@ diff --git a/packages/shadcn-vue/src/components/ui/Popover.ts b/packages/shadcn-vue/src/components/ui/Popover.ts new file mode 100644 index 00000000..14eb19fc --- /dev/null +++ b/packages/shadcn-vue/src/components/ui/Popover.ts @@ -0,0 +1,29 @@ +import { defineComponent, h } from 'vue' +import { + type PopoverContentEmits, PopoverContent as PopoverContentPrimitive, type PopoverContentProps, + PopoverPortal, + PopoverRoot, + PopoverTrigger as PopoverTriggerPrimitive, +} from 'radix-vue' +import { type ParseEmits, cn } from '@/utils' + +export const Popover = PopoverRoot +export const PopoverTrigger = PopoverTriggerPrimitive + +export const PopoverContent = defineComponent>( + (props, { attrs, slots }) => { + return () => h(PopoverPortal, + () => h(PopoverContentPrimitive, + { + align: 'center', + sideOffset: 20, // set default value + + ...attrs, + ...props, + class: cn('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', attrs.class), + }, slots), + ) + }, { + name: 'PopoverContent', + }, +) diff --git a/packages/shadcn-vue/src/components/ui/PopoverDemo.vue b/packages/shadcn-vue/src/components/ui/PopoverDemo.vue new file mode 100644 index 00000000..3f5de128 --- /dev/null +++ b/packages/shadcn-vue/src/components/ui/PopoverDemo.vue @@ -0,0 +1,67 @@ + + + diff --git a/packages/shadcn-vue/src/utils.ts b/packages/shadcn-vue/src/utils.ts index 195096ee..9b6b5045 100644 --- a/packages/shadcn-vue/src/utils.ts +++ b/packages/shadcn-vue/src/utils.ts @@ -2,7 +2,7 @@ import type { ClassValue } from 'clsx' import { clsx } from 'clsx' import { twMerge } from 'tailwind-merge' -export type ShortEmits> = { +export type ParseEmits> = { [K in keyof T]: (...args: T[K]) => void; } diff --git a/packages/shadcn-vue/tsconfig.json b/packages/shadcn-vue/tsconfig.json index 67ecd6d1..74f5f866 100644 --- a/packages/shadcn-vue/tsconfig.json +++ b/packages/shadcn-vue/tsconfig.json @@ -21,6 +21,7 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, + "baseUrl": "./", "paths": { "@/*": ["src/*"] }