Class: Scarpe::WebviewAlert

Inherits:
WebviewWidget show all
Defined in:
lib/scarpe/wv/alert.rb

Constant Summary

Constants included from Shoes::Log

Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG

Instance Attribute Summary

Attributes inherited from WebviewWidget

#children, #parent, #shoes_linkable_id

Attributes inherited from Shoes::Linkable

#linkable_id

Instance Method Summary collapse

Methods inherited from WebviewWidget

#add_child, #bind, #destroy_self, display_class_for, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #rgb_to_hex, #set_parent, #style, #to_html

Methods included from Shoes::Log

configure_logger, #log_init, logger

Methods inherited from Shoes::Linkable

#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_shoes_event

Constructor Details

#initialize(properties) ⇒ WebviewAlert

Returns a new instance of WebviewAlert.



5
6
7
8
9
10
11
# File 'lib/scarpe/wv/alert.rb', line 5

def initialize(properties)
  super

  bind("click") do
    send_self_event(event_name: "click")
  end
end

Instance Method Details

#button_styleObject (protected)



62
63
64
# File 'lib/scarpe/wv/alert.rb', line 62

def button_style
  {}
end

#elementObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/scarpe/wv/alert.rb', line 13

def element
  onclick = handler_js_code("click")

  HTML.render do |h|
    h.div(id: html_id, style: overlay_style) do
      h.div(style: modal_style) do
        h.div(style: text_style) { @text }
        h.button(style: button_style, onclick: onclick) { "OK" }
      end
    end
  end
end


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/scarpe/wv/alert.rb', line 45

def modal_style
  {
    "min-width": "200px",
    "min-height": "50px",
    padding: "10px",
    display: "flex",
    background: "#fefefe",
    "flex-direction": "column",
    "justify-content": "space-between",
    "border-radius": "9px",
  }
end

#overlay_styleObject (protected)

If the whole widget is hidden, the parent style adds display:none



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scarpe/wv/alert.rb', line 29

def overlay_style
  {
    position: "fixed",
    top: "0",
    left: "0",
    width: "100%",
    height: "100%",
    overflow: "auto",
    "z-index": "1",
    background: "rgba(0,0,0,0.4)",
    display: "flex",
    "align-items": "center",
    "justify-content": "center",
  }.merge(style)
end

#text_styleObject (protected)



58
59
60
# File 'lib/scarpe/wv/alert.rb', line 58

def text_style
  {}
end