Method: Primer::Alpha::Dialog#initialize

Defined in:
app/components/primer/alpha/dialog.rb

#initialize(title:, subtitle: nil, size: DEFAULT_SIZE, position: DEFAULT_POSITION, position_narrow: DEFAULT_POSITION_NARROW, visually_hide_title: false, id: self.class.generate_id, disable_scroll: true, **system_arguments) ⇒ Dialog

Returns a new instance of Dialog.

Parameters:

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

    The id of the dialog.

  • title (String)

    Describes the content of the dialog.

  • subtitle (String) (defaults to: nil)

    Provides additional context for the dialog, also setting the ‘aria-describedby` attribute.

  • size (Symbol) (defaults to: DEFAULT_SIZE)

    The size of the dialog. <%= one_of(Primer::Alpha::Dialog::SIZE_OPTIONS) %>

  • position (Symbol) (defaults to: DEFAULT_POSITION)

    The position of the dialog. <%= one_of(Primer::Alpha::Dialog::POSITION_OPTIONS) %>

  • position_narrow (Symbol) (defaults to: DEFAULT_POSITION_NARROW)

    The position of the dialog when narrow. <%= one_of(Primer::Alpha::Dialog::POSITION_NARROW_OPTIONS) %>

  • visually_hide_title (Boolean) (defaults to: false)

    If true will hide the heading title, while still making it available to Screen Readers.

  • disable_scroll (Boolean) (defaults to: true)

    When true, disables scrolling the page when the dialog is open.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>

[View source]

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/components/primer/alpha/dialog.rb', line 109

def initialize(
  title:,
  subtitle: nil,
  size: DEFAULT_SIZE,
  position: DEFAULT_POSITION,
  position_narrow: DEFAULT_POSITION_NARROW,
  visually_hide_title: false,
  id: self.class.generate_id,
  disable_scroll: true,
  **system_arguments
)
  @system_arguments = deny_tag_argument(**system_arguments)

  @id = id.to_s
  @title = title
  @subtitle = subtitle
  @size = size
  @position = position
  @position_narrow = position_narrow
  @visually_hide_title = visually_hide_title
  @disable_scroll = disable_scroll

  @system_arguments[:tag] = "dialog"
  @system_arguments[:id] = @id
  @system_arguments[:aria] = { modal: true }
  @system_arguments[:aria] = merge_aria(
    @system_arguments, {
      aria: {
        labelledby: labelledby,
        describedby: "#{@id}-description"
      }
    }
  )
  @system_arguments[:classes] = class_names(
    "Overlay",
    "Overlay-whenNarrow",
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)],
    "Overlay--motion-scaleFade",
    POSITION_MAPPINGS[fetch_or_fallback(POSITION_OPTIONS, @position, DEFAULT_POSITION)],
    POSITION_NARROW_MAPPINGS[fetch_or_fallback(POSITION_NARROW_MAPPINGS, @position_narrow, DEFAULT_POSITION_NARROW)],
    system_arguments[:classes],
    "Overlay--disableScroll" => @disable_scroll
  )
end