Class: RubyNative::Helper::NavbarMenuBuilder
- Inherits:
-
Object
- Object
- RubyNative::Helper::NavbarMenuBuilder
- Defined in:
- lib/ruby_native/helper.rb
Instance Method Summary collapse
-
#initialize(context) ⇒ NavbarMenuBuilder
constructor
A new instance of NavbarMenuBuilder.
- #item(title, href: nil, click: nil, icon: nil, icons: nil, selected: false, action: nil) ⇒ Object
-
#share_item(title = "Share", url: nil, icon: "square.and.arrow.up", icons: { android: "share" }, selected: false) ⇒ Object
Adds a share entry to a navbar button's dropdown menu.
- #to_html ⇒ Object
Constructor Details
#initialize(context) ⇒ NavbarMenuBuilder
Returns a new instance of NavbarMenuBuilder.
348 349 350 351 |
# File 'lib/ruby_native/helper.rb', line 348 def initialize(context) @context = context @items = [] end |
Instance Method Details
#item(title, href: nil, click: nil, icon: nil, icons: nil, selected: false, action: nil) ⇒ Object
353 354 355 356 357 358 359 360 361 362 |
# File 'lib/ruby_native/helper.rb', line 353 def item(title, href: nil, click: nil, icon: nil, icons: nil, selected: false, action: nil) resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: @context.try(:native_platform)) data = { native_menu_item: "", native_title: title } data[:native_href] = href if href data[:native_click] = click if click data[:native_icon] = resolved if resolved data[:native_selected] = "" if selected data[:native_action] = RubyNative::Helper.validate_action(action) if action add(@context.tag.div(data: data)) end |
#share_item(title = "Share", url: nil, icon: "square.and.arrow.up", icons: { android: "share" }, selected: false) ⇒ Object
Adds a share entry to a navbar button's dropdown menu. Selecting it
opens the platform share sheet for url: (defaults to the current
page on the web side). Icons follow the same icon:/icons: rules
as the other menu items.
368 369 370 371 372 373 374 375 |
# File 'lib/ruby_native/helper.rb', line 368 def share_item(title = "Share", url: nil, icon: "square.and.arrow.up", icons: { android: "share" }, selected: false) resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: @context.try(:native_platform)) data = { native_menu_item: "", native_title: title, native_share: "" } data[:native_share_url] = url if url data[:native_icon] = resolved if resolved data[:native_selected] = "" if selected add(@context.tag.div(data: data)) end |
#to_html ⇒ Object
377 378 379 |
# File 'lib/ruby_native/helper.rb', line 377 def to_html @context.safe_join(@items) end |