Class: Primer::OpenProject::DangerConfirmationDialog

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/danger_confirmation_dialog.rb,
app/components/primer/open_project/danger_confirmation_dialog/form_wrapper.rb,
app/components/primer/open_project/danger_confirmation_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, **system_arguments) ⇒ DangerConfirmationDialog

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.

Parameters:

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

    Allows the dialog to submit a form. Pass EITHER the ‘builder:` option to this hash

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

    The id of the dialog.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/components/primer/open_project/danger_confirmation_dialog.rb', line 67

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

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

  @dialog = Primer::Alpha::Dialog.new(title: @system_arguments[: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_confirmation_dialog.rb', line 11

def dialog_id
  @dialog_id
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


90
91
92
93
94
95
# File 'app/components/primer/open_project/danger_confirmation_dialog.rb', line 90

def render?
  raise ArgumentError, "DangerConfirmationDialog requires a confirmation_message" unless confirmation_message?
  raise ArgumentError, "DangerConfirmationDialog requires a confirmation_check_box" unless confirmation_check_box?

  confirmation_message? && confirmation_check_box?
end