Class: Primer::OpenProject::DangerDialog

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/danger_dialog.rb,
app/components/primer/open_project/danger_dialog/form_wrapper.rb,
app/components/primer/open_project/danger_dialog/confirmation_check_box.rb

Overview

A pre-configured dialog for destructive/“potentially dangerous” actions

Defined Under Namespace

Classes: ConfirmationCheckBox, FormWrapper

Constant Summary

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(form_arguments: {}, id: self.class.generate_id, title:, confirm_button_text: nil, cancel_button_text: nil, **system_arguments) ⇒ DangerDialog

Returns a new instance of DangerDialog.

Parameters:

  • form_arguments (Hash) (defaults to: {})

    Allows the dialog to submit a form. Pass EITHER the ‘builder:` option to this hash to reuse an existing Rails form, or `action:` if you prefer the component to render the form tag itself. `builder:` should be an instance of `ActionView::Helpers::FormBuilder`, which is created by the standard Rails `#form_with` and `#form_for` helpers. The `name:` option is the desired name of the field that will be included in the params sent to the server on form submission.

  • id (String) (defaults to: self.class.generate_id)

    The id of the dialog.

  • title (String)

    The title of the dialog. Although visually hidden, a label is rendered for assistive technologies.

  • confirm_button_text (String) (defaults to: nil)

    The text of the confirm button. Will default to ‘I18n.t(“button_delete”)`, or `I18n.t(“button_delete_permanently”)` if `confirmation_check_box` slot has been passed to the component.

  • cancel_button_text (String) (defaults to: nil)

    The text of the cancel button. Will default to ‘I18n.t(“button_cancel”)`.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/components/primer/open_project/danger_dialog.rb', line 70

def initialize(
  form_arguments: {},
  id: self.class.generate_id,
  title:,
  confirm_button_text: nil,
  cancel_button_text: nil,
  **system_arguments
)
  @check_box_name = form_arguments.delete(:name) || "confirm_dangerous_action"
  @form_wrapper = FormWrapper.new(**form_arguments)
  @dialog_id = id.to_s

  @confirm_button_text = confirm_button_text
  @cancel_button_text = cancel_button_text

  @system_arguments = system_arguments
  @system_arguments[:id] = @dialog_id
  @system_arguments[:classes] = class_names(
    system_arguments[:classes],
    "DangerDialog"
  )

  @dialog = Primer::Alpha::Dialog.new(title: title, subtitle: nil, visually_hide_title: true, **@system_arguments)
end

Instance Attribute Details

#dialog_idObject (readonly)

The dialog’s ID value.



11
12
13
# File 'app/components/primer/open_project/danger_dialog.rb', line 11

def dialog_id
  @dialog_id
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


99
100
101
102
103
# File 'app/components/primer/open_project/danger_dialog.rb', line 99

def render?
  raise ArgumentError, "DangerDialog requires a confirmation_message" unless confirmation_message?

  confirmation_message?
end