Class: CommonComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ApplicationHelper, Pagy::Frontend
Defined in:
app/components/common_component.rb

Overview

Common component

Instance Method Summary collapse

Methods included from ApplicationHelper

#fas_icon, #l_date, #l_long, #l_time, #notifications, #notify, #notify_status, #t_enum

Instance Method Details

#icon(fas, **opts) ⇒ String

Make an html structure for a bulma/awesome icon

Example: icon(‘fas fa-home’) ‘<span class=“icon”><i class=“fas fa-home”></i></span>`

Parameters:

  • fa (String)

    class for icon, example: “fas fa-home”

  • opts (Hash)

    to generate content

Options Hash (**opts):

  • :class (String)

    style other “span.icon” class

Returns:

  • (String)

    bulma / awesome icon structure



18
19
20
# File 'app/components/common_component.rb', line 18

def icon(fas, **opts)
   :span, tag.i(class: fas), class: [ "icon", opts[:class] ]
end

#icon_text(fas, text, **opts) ⇒ String

Make an html structure for a bulma/awesome text-icon

Example: icon(‘fas fa-home’, ‘text’) ‘<span class=“text-icon”><span class=“icon”><i class=“fas fa-home”></i></span><span>text</span></span>`

Parameters:

  • fa (String)

    class for icon, example: “fas fa-home”

  • text (String)

    for the icon

  • opts (Hash)

    to generate content

Options Hash (**opts):

  • :class (String)

    style other “span.icon-text” class

  • :icon_class (String)

    style other “span.icon” class

Returns:

  • (String)

    bulma / awesome text-icon structure



34
35
36
37
38
39
40
# File 'app/components/common_component.rb', line 34

def icon_text(fas, text, **opts)
  (
    :span,
    icon(fas, class: opts[:icon_class]) + (:span, text),
    class: [ "icon-text", opts[:class] ]
  )
end

#level(ary) ⇒ Object



57
58
59
# File 'app/components/common_component.rb', line 57

def level(ary)
  tag.div(safe_join(ary.map { |e| level_item(*e) }), class: "level infobox")
end

#level_item(head, body) ⇒ Object



53
54
55
# File 'app/components/common_component.rb', line 53

def level_item(head, body)
  tag.div tag.div(tag.p(head, class: "heading") + tag.p(body, class: "title is-6")), class: "level-item"
end

#pagy(data) ⇒ Object

make html structure for pagination with pagy



43
44
45
# File 'app/components/common_component.rb', line 43

def pagy(data)
  tag.div pagy_bulma_nav(data).html_safe, data: { controller: "pagy-initializer" }
end

#turbo_yield(body, **opts) ⇒ Object

Shortkut, Make a turbo frame with id yield



48
49
50
51
# File 'app/components/common_component.rb', line 48

def turbo_yield(body, **opts)
  options = { id: "yield" }.merge(**opts)
  tag.turbo_frame body, **options
end