Class: Polaris::ModalComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/modal_component.rb

Constant Summary

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(title:, open: false, sectioned: true, scrollable: true, large: false, small: false, limit_height: false, dialog_arguments: {}, **system_arguments) ⇒ ModalComponent

Returns a new instance of ModalComponent.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/components/polaris/modal_component.rb', line 17

def initialize(
  title:,
  open: false,
  sectioned: true,
  scrollable: true,
  large: false,
  small: false,
  limit_height: false,
  dialog_arguments: {},
  **system_arguments
)
  @title = title
  @open = open
  @sectioned = sectioned
  @scrollable = scrollable
  @large = large
  @small = small
  @limit_height = limit_height
  @dialog_arguments = dialog_arguments
  @system_arguments = system_arguments
  @close_button_arguments = {
    tag: "button",
    type: "button",
    classes: "Polaris-Modal-CloseButton",
    aria: {label: "Close"}
  }
end

Instance Method Details

#close_button_argumentsObject



75
76
77
78
79
# File 'app/components/polaris/modal_component.rb', line 75

def close_button_arguments
  @close_button_arguments.deep_merge({
    data: {action: "polaris-modal#close"}
  })
end

#dialog_argumentsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/components/polaris/modal_component.rb', line 61

def dialog_arguments
  @dialog_arguments.tap do |opts|
    opts[:tag] = "div"
    opts[:role] = "dialog"
    opts[:aria] ||= {}
    opts[:aria][:modal] = "true"
    opts[:tabindex] = "-1"
    opts[:classes] = class_names(
      @dialog_arguments[:classes],
      "Polaris-Modal-Dialog"
    )
  end
end


81
82
83
84
85
86
87
88
# File 'app/components/polaris/modal_component.rb', line 81

def modal_classes
  class_names(
    "Polaris-Modal-Dialog__Modal",
    "Polaris-Modal-Dialog--sizeLarge": @large,
    "Polaris-Modal-Dialog--sizeSmall": @small,
    "Polaris-Modal-Dialog--limitHeight": @limit_height
  )
end

#render_footer?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/components/polaris/modal_component.rb', line 90

def render_footer?
  primary_action.present? || secondary_actions.any?
end

#system_argumentsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/components/polaris/modal_component.rb', line 45

def system_arguments
  @system_arguments.tap do |opts|
    opts[:tag] = "div"
    opts[:data] ||= {}
    prepend_option(opts[:data], :controller, "polaris-modal")
    opts[:data][:polaris_modal_open_value] = @open
    opts[:data][:polaris_modal_hidden_class] = "Polaris--hidden"
    opts[:data][:polaris_modal_backdrop_class] = "Polaris-Backdrop"
    opts[:classes] = class_names(
      @system_arguments[:classes],
      "Polaris-Modal-Dialog__Container",
      "Polaris--hidden"
    )
  end
end