@molecule/app-danger-zone-vue

Feature · danger-zone · App (browser) · v1.1.2 · Apache-2.0

DangerZoneSection + ConfirmDialog for destructive actions (delete account, reset, revoke)

npm install @molecule/app-danger-zone-vue

npm · Source on GitHub

How it works

@molecule/app-danger-zone-vue is a ready-made danger-zone feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { createApp, defineComponent, h, ref } from 'vue'
import { ConfirmDialog, DangerZoneSection } from '@molecule/app-danger-zone-vue'

const App = defineComponent({
  setup() {
    const confirmOpen = ref(false)
    return () => [
      h(DangerZoneSection, {
        title: 'Delete account',
        description: 'This permanently removes your account and all data.',
        actionLabel: 'Delete account',
        onAction: () => {
          confirmOpen.value = true
        },
      }),
      h(ConfirmDialog, {
        open: confirmOpen.value,
        onClose: () => {
          confirmOpen.value = false
        },
        title: 'Delete account?',
        description: 'This action cannot be undone.',
        confirmLabel: 'Delete',
        onConfirm: handleDelete,
      }),
    ]
  },
})

createApp(App).mount('#app')

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

Vue destructive-action primitives.

Exports <DangerZoneSection> — Card with title/description/button for delete/reset/revoke — and <ConfirmDialog>, the standalone "Are you sure?" modal. It is the Vue counterpart of @molecule/app-danger-zone-react: the same props and the same DOM for the same input, so an app can switch framework by changing only the package name in its imports.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { createApp, defineComponent, h, ref } from 'vue'
import { ConfirmDialog, DangerZoneSection } from '@molecule/app-danger-zone-vue'

const App = defineComponent({
  setup() {
    const confirmOpen = ref(false)
    return () => [
      h(DangerZoneSection, {
        title: 'Delete account',
        description: 'This permanently removes your account and all data.',
        actionLabel: 'Delete account',
        onAction: () => {
          confirmOpen.value = true
        },
      }),
      h(ConfirmDialog, {
        open: confirmOpen.value,
        onClose: () => {
          confirmOpen.value = false
        },
        title: 'Delete account?',
        description: 'This action cannot be undone.',
        confirmLabel: 'Delete',
        onConfirm: handleDelete,
      }),
    ]
  },
})

createApp(App).mount('#app')

Type

feature

Installation

npm install @molecule/app-danger-zone-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

ConfirmDialogProps

Props accepted by ConfirmDialog — the same props @molecule/app-danger-zone-react accepts. Node-valued props (title, description, confirmLabel, cancelLabel) take a Vue VNodeChild (or a string) instead of a React node.

interface ConfirmDialogProps {
  /** Whether the dialog is open. */
  open: boolean
  /** Called when the dialog should close (escape, backdrop, cancel). */
  onClose: (event?: unknown) => void
  /** Title. */
  title?: VNodeChild
  /** Body / warning text. */
  description?: VNodeChild
  /** Confirm-button label (e.g. "Delete"). */
  confirmLabel?: VNodeChild
  /** Cancel-button label. */
  cancelLabel?: VNodeChild
  /** Called when the user confirms. */
  onConfirm: () => void | Promise<void>
  /** Is the confirm action destructive? Defaults to true. */
  destructive?: boolean
  /** Extra body content between description and footer. */
  children?: VNodeChild
  /**
   * Disables both buttons. Set it yourself while your `onConfirm` promise is
   * pending — the dialog does not track it and does not auto-close.
   */
  loading?: boolean
}

DangerZoneSectionProps

Props accepted by the DangerZoneSection component.

interface DangerZoneSectionProps {
  /** Section title. */
  title?: VNodeChild
  /** Explanation of the destructive action. */
  description?: VNodeChild
  /** Label on the action button (e.g. "Delete account"). */
  actionLabel?: VNodeChild
  /** Called when the button is clicked. */
  onAction?: (event: MouseEvent) => void
  /** When true, the button disables and shows a loading label. */
  loading?: boolean
  /** When true, the button is disabled without loading. */
  disabled?: boolean
  /** Additional content between description and button (e.g. a confirm-text input). */
  children?: VNodeChild
  /** Extra classes on the Card. */
  className?: string
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
}

Constants

DangerZoneSection

Card-wrapped section for destructive actions — delete account, reset data, revoke access. Uses the error/danger accent color and puts the action on the right. While loading is true the button disables and shows a loading glyph.

const DangerZoneSection: DefineComponent<
  ExtractPropTypes<{
    title: null
    description: null
    actionLabel: null
    loading: { type: PropType<boolean | undefined>; default: boolean }
    disabled: { type: PropType<boolean | undefined>; default: boolean }
    className: StringConstructor
    dataMolId: StringConstructor
  }>,
  () => VNode,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  'action'[],
  'action',
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      title: null
      description: null
      actionLabel: null
      loading: { type: PropType<boolean | undefined>; default: boolean }
      disabled: { type: PropType<boolean | undefined>; default: boolean }
      className: StringConstructor
      dataMolId: StringConstructor
    }>
  > &
    Readonly<{ onAction?: ((...args: any[]) => any) | undefined }>,
  { loading: boolean | undefined; disabled: boolean | undefined },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (DangerZoneSectionProps).

Returns: The section component.

ConfirmDialog

Are-you-sure-style confirmation modal for destructive actions: a title, a description, optional extra body content and a cancel/confirm footer.

Does NOT track onConfirm's promise and does NOT close itself on confirm (set loading while the action runs, then close yourself).

const ConfirmDialog: DefineComponent<
  ExtractPropTypes<{
    open: { type: PropType<ConfirmDialogProps['open']>; required: true }
    title: Prop<VNodeChild>
    description: Prop<VNodeChild>
    confirmLabel: Prop<VNodeChild>
    cancelLabel: Prop<VNodeChild>
    destructive: { type: PropType<ConfirmDialogProps['destructive']>; default: boolean }
    loading: { type: PropType<ConfirmDialogProps['loading']>; default: boolean }
  }>,
  () => VNode<RendererNode, RendererElement, { [key: string]: any }>,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  { close: (_event?: MouseEvent) => true; confirm: () => true },
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      open: { type: PropType<ConfirmDialogProps['open']>; required: true }
      title: Prop<VNodeChild>
      description: Prop<VNodeChild>
      confirmLabel: Prop<VNodeChild>
      cancelLabel: Prop<VNodeChild>
      destructive: { type: PropType<ConfirmDialogProps['destructive']>; default: boolean }
      loading: { type: PropType<ConfirmDialogProps['loading']>; default: boolean }
    }>
  > &
    Readonly<{
      onClose?: ((_event?: MouseEvent | undefined) => any) | undefined
      onConfirm?: (() => any) | undefined
    }>,
  { destructive: boolean | undefined; loading: boolean | undefined },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (open/onClose/title/description/ confirmLabel/cancelLabel/onConfirm/destructive/loading).

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui
  • @molecule/app-ui-vue
  • @molecule/app-vue
  • vue

<ConfirmDialog> does NOT track onConfirm's promise and does NOT close itself on confirm: set loading yourself while the action runs, then call onClose() when it settles — otherwise users can double-fire the destructive action or be left staring at an open dialog. Cancel/Confirm fall back to the confirm.* i18n keys (companion bond: @molecule/app-locales-danger-zone); pass confirmLabel/cancelLabel for action-specific wording ("Delete", "Revoke"). destructive (default true) only switches the confirm button color.

Translations

Translation strings are provided by @molecule/app-locales-danger-zone.