Skip to content

Commit

Permalink
Add menu, card and message components
Browse files Browse the repository at this point in the history
  • Loading branch information
iwdt committed Dec 8, 2024
1 parent 2fd5fd4 commit 82e6526
Show file tree
Hide file tree
Showing 29 changed files with 683 additions and 11 deletions.
27 changes: 27 additions & 0 deletions app/components/bulma/components/card/footer/form_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Bulma
module Components
module Card
module Footer
class FormComponent < ItemComponent
def initialize(name = nil, options = nil, **html_attributes)
@name = name
@options = options

super(**html_attributes)
end

def call
html_options = root_attributes(:item)

if content?
html_options = @options.merge(html_options) if @options.is_a?(Hash)
return button_to(@name, html_options) { content }
end

button_to(@name, @options, html_options)
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions app/components/bulma/components/card/footer/link_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Bulma
module Components
module Card
module Footer
class LinkComponent < ItemComponent
def initialize(name = nil, options = nil, **html_attributes)
@name = name
@options = options

super(**html_attributes)
end

def call
html_options = root_attributes(:item)

if content?
html_options = @options.merge(html_options) if @options.is_a?(Hash)
return link_to(@name, html_options) { content }
end

link_to(@name, @options, html_options)
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions app/components/bulma/components/card/footer/mail_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Bulma
module Components
module Card
module Footer
class MailComponent < ItemComponent
def initialize(email_address = nil, name = nil, **html_attributes)
@email_address = email_address
@name = name

super(**html_attributes)
end

def call
html_options = root_attributes(:item)

if content?
html_options = @name.merge(html_options) if @name.is_a?(Hash)
return mail_to(@email_address, html_options) { content }
end

mail_to(@email_address, @name, html_options)
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions app/components/bulma/components/card/footer/phone_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Bulma
module Components
module Card
module Footer
class PhoneComponent < ItemComponent
def initialize(phone_number = nil, name = nil, **html_attributes)
@phone_number = phone_number
@name = name

super(**html_attributes)
end

def call
html_options = root_attributes(:item)

if content?
html_options = @name.merge(html_options) if @name.is_a?(Hash)
return phone_to(@phone_number, html_options) { content }
end

phone_to(@phone_number, @name, html_options)
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions app/components/bulma/components/card/footer/sms_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Bulma
module Components
module Card
module Footer
class SmsComponent < ItemComponent
def initialize(phone_number = nil, name = nil, **html_attributes)
@phone_number = phone_number
@name = name

super(**html_attributes)
end

def call
html_options = root_attributes(:item)

if content?
html_options = @name.merge(html_options) if @name.is_a?(Hash)
return sms_to(@phone_number, html_options) { content }
end

sms_to(@phone_number, @name, html_options)
end
end
end
end
end
end
40 changes: 36 additions & 4 deletions app/components/bulma/components/card/footer_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ module Bulma
module Components
module Card
class FooterComponent < ApplicationComponent
# @dynamic card_footer_items, with_card_footer_item
renders_many :card_footer_items, Footer::ItemComponent
# @dynamic card_footer_items, with_card_footer_item_tag, with_card_footer_item_link_to, with_card_footer_item_button_to, with_card_footer_item_sms_to, with_card_footer_item_phone_to, with_card_footer_item_mail_to
renders_many :card_footer_items, types: {
tag: Footer::ItemComponent,
link_to: Footer::LinkComponent,
button_to: Footer::FormComponent,
sms_to: Footer::SmsComponent,
phone_to: Footer::PhoneComponent,
mail_to: Footer::MailComponent
}

self.root_tag = :footer

Expand All @@ -15,9 +22,34 @@ def call
content_tag(root_tag, safe_join([*card_footer_items, content]), **root_attributes)
end

private :with_card_footer_item
private :with_card_footer_item_tag
def item(**html_attributes, &block)
with_card_footer_item(**html_attributes, &block)
with_card_footer_item_tag(**html_attributes, &block)
end

private :with_card_footer_item_link_to
def link_to(name = nil, options = nil, **html_options, &block)
with_card_footer_item_link_to(name, options, **html_options, &block)
end

private :with_card_footer_item_button_to
def button_to(name = nil, options = nil, **html_options, &block)
with_card_footer_item_button_to(name, options, **html_options, &block)
end

private :with_card_footer_item_mail_to
def mail_to(email_address, name = nil, **html_options, &block)
with_card_footer_item_mail_to(email_address, name, **html_options, &block)
end

private :with_card_footer_item_phone_to
def phone_to(phone_number, name = nil, **html_options, &block)
with_card_footer_item_phone_to(phone_number, name, **html_options, &block)
end

private :with_card_footer_item_sms_to
def sms_to(phone_number, name = nil, **html_options, &block)
with_card_footer_item_sms_to(phone_number, name, **html_options, &block)
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions app/components/bulma/components/menu/label_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Bulma
module Components
module Menu
class LabelComponent < ApplicationComponent
self.root_tag = :p

style do
base { "menu-label" }
end

def initialize(text = nil, **html_attributes)
@text = text

super(**html_attributes)
end

def call
content_tag(root_tag, safe_join([@text, content]), **root_attributes)
end
end
end
end
end
23 changes: 23 additions & 0 deletions app/components/bulma/components/menu/list/item_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Bulma
module Components
module Menu
module List
class ItemComponent < ApplicationComponent
self.root_tag = :li

# @dynamic submenu, with_submenu
renders_one :submenu, ListComponent

def call
content_tag(root_tag, safe_join([content, submenu]), **root_attributes)
end

private :with_submenu
def list(**html_attributes, &block)
with_submenu(**html_attributes, &block)
end
end
end
end
end
end
23 changes: 23 additions & 0 deletions app/components/bulma/components/menu/list/list_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Bulma
module Components
module Menu
module List
class ListComponent < ApplicationComponent
self.root_tag = :ul

# @dynamic list_items, with_list_item
renders_many :list_items, ItemComponent

def call
content_tag(root_tag, safe_join([content, *list_items]), **root_attributes)
end

private :with_list_item
def item(**html_attributes, &block)
with_list_item(**html_attributes, &block)
end
end
end
end
end
end
25 changes: 25 additions & 0 deletions app/components/bulma/components/menu/list_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Bulma
module Components
module Menu
class ListComponent < ApplicationComponent
# @dynamic list_items, with_list_item
renders_many :list_items, List::ItemComponent

self.root_tag = :ul

style do
base { "menu-list" }
end

def call
content_tag(root_tag, safe_join([content, *list_items]), **root_attributes)
end

private :with_list_item
def item(**html_attributes, &block)
with_list_item(**html_attributes, &block)
end
end
end
end
end
31 changes: 31 additions & 0 deletions app/components/bulma/components/menu_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Bulma
module Components
class MenuComponent < ApplicationComponent
self.root_tag = :aside

# @dynamic menu_elements, with_menu_element_label, with_menu_element_list
renders_many :menu_elements, types: {
label: Menu::LabelComponent,
list: Menu::ListComponent
}

style do
base { "menu" }
end

def call
content_tag(root_tag, safe_join([*menu_elements, content]), **root_attributes)
end

private :with_menu_element_label
def label(text = nil, **html_attributes, &block)
with_menu_element_label(text, **html_attributes, &block)
end

private :with_menu_element_list
def list(**html_attributes, &block)
with_menu_element_list(**html_attributes, &block)
end
end
end
end
11 changes: 11 additions & 0 deletions app/components/bulma/components/message/header_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Bulma
module Components
module Message
class HeaderComponent < ApplicationComponent
style do
base { "message-header" }
end
end
end
end
end
Loading

0 comments on commit 82e6526

Please sign in to comment.