/** * Copyright (c) HashiCorp, Inc. * SPDX-License-Identifier: BUSL-1.1 */ import Component from '@glimmer/component'; import { action } from '@ember/object'; import { assert } from '@ember/debug'; import { tracked } from '@glimmer/tracking'; /** * @module ConfirmAction * ConfirmAction is a button that opens a modal containing a confirmation message with confirm or cancel action. * Splattributes are spread to the button element to apply styling directly without adding extra args. * * * @example // in dropdown // in toolbar * ``` * * @param {Function} onConfirmAction - The action to take upon confirming. * @param {String} [confirmTitle=Are you sure?] - The title to display in the confirmation modal. * @param {String} [confirmMessage=You will not be able to recover it later.] - The message to display when confirming. * @param {Boolean} isInDropdown - If true styles for dropdowns, button color is 'critical', and renders inside `
  • ` elements via ` component expects @onConfirmAction arg to be a function', typeof this.args.onConfirmAction === 'function' ); assert(`@buttonText is required for ConfirmAction components`, this.args.buttonText); } get confirmMessage() { return this.args.confirmMessage || 'You will not be able to recover it later.'; } get modalColor() { if (this.args.disabledMessage) return 'neutral'; return this.args.modalColor || 'critical'; } @action async onConfirm() { await this.args.onConfirmAction(); // close modal after destructive operation this.showConfirmModal = false; } }