useDialog.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import {
  3. closeOverlayContainer,
  4. getOpenedOverlayContainers,
  5. getOverlayContainerMeta,
  6. isOverlayContainerOpened,
  7. openOverlayContainer,
  8. useOverlayContainer,
  9. type OverlayContainerOptions,
  10. } from '#desktop/composables/useOverlayContainer.ts'
  11. const OVERLAY_CONTAINER_TYPE = 'dialog'
  12. export const getOpenedDialogs = () =>
  13. getOpenedOverlayContainers(OVERLAY_CONTAINER_TYPE)
  14. export const isDialogOpened = (name?: string) =>
  15. isOverlayContainerOpened(OVERLAY_CONTAINER_TYPE, name)
  16. export const getDialogMeta = () => {
  17. const overlayContainerMeta = getOverlayContainerMeta(OVERLAY_CONTAINER_TYPE)
  18. return {
  19. dialogsOptions: overlayContainerMeta.options,
  20. openedDialogs: overlayContainerMeta.opened,
  21. }
  22. }
  23. export const openDialog = async (
  24. name: string,
  25. props: Record<string, unknown>,
  26. ) => openOverlayContainer(OVERLAY_CONTAINER_TYPE, name, props)
  27. export const closeDialog = async (name: string) =>
  28. closeOverlayContainer(OVERLAY_CONTAINER_TYPE, name)
  29. export const useDialog = (options: OverlayContainerOptions) => {
  30. return useOverlayContainer(OVERLAY_CONTAINER_TYPE, options)
  31. }