feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
inject,
|
||||
reactive,
|
||||
ref,
|
||||
shallowRef,
|
||||
useId,
|
||||
type InjectionKey,
|
||||
type Ref,
|
||||
} from "vue";
|
||||
import type { OverlayState } from "../../composables/useOverlayState";
|
||||
export interface PopoverContext {
|
||||
state: OverlayState;
|
||||
contentId: Ref<string>;
|
||||
triggerId: string;
|
||||
contentNonModal: Ref<boolean | undefined>;
|
||||
titles: Map<symbol, string>;
|
||||
dialogAttrs: Ref<Record<string, unknown>>;
|
||||
}
|
||||
export const popoverKey: InjectionKey<PopoverContext> = Symbol("hv-popover");
|
||||
export function usePopover() {
|
||||
const ctx = inject(popoverKey);
|
||||
if (!ctx) throw new Error("Popover parts require Popover.");
|
||||
return ctx;
|
||||
}
|
||||
export function createPopoverContext(state: OverlayState): PopoverContext {
|
||||
const id = "hv-popover-" + useId();
|
||||
return {
|
||||
state,
|
||||
contentId: ref(id + "-content"),
|
||||
triggerId: id + "-trigger",
|
||||
contentNonModal: ref(undefined),
|
||||
titles: reactive(new Map()),
|
||||
dialogAttrs: shallowRef({}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user