Class: TurboOverlay::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_overlay/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/turbo_overlay/configuration.rb', line 139

def initialize
  @stack_id = "turbo_overlay_stack"
  @allowed_click_outside_selectors = []

  @modal = ModalConfig.new(variant: :modal)

  @drawer = DrawerConfig.new(
    variant:  :drawer,
    position: :right
  )

  @popover = PopoverConfig.new(
    variant:   :popover,
    position:  :bottom,
    align:     :start,
    offset:    4,
    auto_flip: true
  )

  @confirm = ConfirmConfig.new(style: :modal)

  @hint = HintConfig.new(
    variant:       :hint,
    show_delay_ms: 250,
    hide_delay_ms: 120
  )
end

Instance Attribute Details

#allowed_click_outside_selectorsObject

CSS selectors whose clicks should not dismiss an open overlay. The list is consulted by the JS dismissal guard for backdrop clicks (modal/drawer) and outside-clicks (popover). Use this for body-appended widgets — flatpickr calendars, Select2 dropdowns, Tippy tooltips, Tom Select — that render their UI as siblings of the overlay in ‘<body>` and would otherwise read as outside-the-dialog clicks.

This is developer config, not request data: never populate from user input. Entries are interpreted as CSS selectors and matched against any element in the DOM.



115
116
117
# File 'lib/turbo_overlay/configuration.rb', line 115

def allowed_click_outside_selectors
  @allowed_click_outside_selectors
end

#stack_idObject

DOM id of the host-page stack container that receives appended overlays. Emit it in your application layout via ‘<%= overlay_stack_tag %>`.



102
103
104
# File 'lib/turbo_overlay/configuration.rb', line 102

def stack_id
  @stack_id
end

Instance Method Details

#confirm {|@confirm| ... } ⇒ Object

Confirm-prompt config. Controls how ‘data-turbo-confirm` renders.

TurboOverlay.configure do |c|
  c.confirm do |cf|
    cf.style = :popover    # default :modal
  end
end

Yields:



208
209
210
211
# File 'lib/turbo_overlay/configuration.rb', line 208

def confirm
  yield @confirm if block_given?
  @confirm
end

#drawer {|@drawer| ... } ⇒ Object

Drawer config. Same shape as modal, plus a ‘position` attribute (`:left`, `:right`, `:top`, `:bottom`).

TurboOverlay.configure do |c|
  c.drawer do |d|
    d.position = :left
  end
end

Yields:



182
183
184
185
# File 'lib/turbo_overlay/configuration.rb', line 182

def drawer
  yield @drawer if block_given?
  @drawer
end

#hint {|@hint| ... } ⇒ Object

Hint config. Hover-triggered preview overlays.

TurboOverlay.configure do |c|
  c.hint do |h|
    h.show_delay_ms = 400
    h.enabled       = false   # turn the feature off entirely
  end
end

Yields:



221
222
223
224
# File 'lib/turbo_overlay/configuration.rb', line 221

def hint
  yield @hint if block_given?
  @hint
end

Modal config. With a block, yields the type config for setters; without a block, returns it for direct access.

Yields:



169
170
171
172
# File 'lib/turbo_overlay/configuration.rb', line 169

def modal
  yield @modal if block_given?
  @modal
end

#popover {|@popover| ... } ⇒ Object

Popover config. Anchored to the trigger element. Same shape as modal, plus ‘position`, `align`, `offset`, and `auto_flip`.

TurboOverlay.configure do |c|
  c.popover do |p|
    p.position = :top
    p.align    = :center
  end
end

Yields:



196
197
198
199
# File 'lib/turbo_overlay/configuration.rb', line 196

def popover
  yield @popover if block_given?
  @popover
end