1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-25 14:59:26 +01:00
Files
dozzle/assets/composable/drawer.ts
2024-09-18 17:27:46 -07:00

30 lines
917 B
TypeScript

import SideDrawer from "@/components/common/SideDrawer.vue";
import { Component } from "vue";
export type DrawerWidth = "md" | "xl" | "lg";
export const drawerContext = Symbol("drawer") as InjectionKey<
(c: Component, p: Record<string, any>, s?: DrawerWidth) => void
>;
export const createDrawer = (drawer: Ref<InstanceType<typeof SideDrawer>>) => {
const component = shallowRef<Component | null>(null);
const properties = shallowRef<Record<string, any>>({});
const width = ref<DrawerWidth>("md");
const showDrawer = (c: Component, p: Record<string, any>, w: DrawerWidth = "md") => {
component.value = c;
properties.value = p;
width.value = w;
drawer.value?.open();
};
provide(drawerContext, showDrawer);
return { component, properties, showDrawer, width };
};
export const useDrawer = () =>
inject(drawerContext, () => {
console.error("No drawer context provided");
});