From 82e6526bd6d85802fc99e5e9c9c4cc4b4e93ebcd Mon Sep 17 00:00:00 2001 From: Ivan Naumov Date: Mon, 9 Dec 2024 01:22:52 +0300 Subject: [PATCH] Add menu, card and message components --- .../components/card/footer/form_component.rb | 27 +++++++ .../components/card/footer/link_component.rb | 27 +++++++ .../components/card/footer/mail_component.rb | 27 +++++++ .../components/card/footer/phone_component.rb | 27 +++++++ .../components/card/footer/sms_component.rb | 27 +++++++ .../bulma/components/card/footer_component.rb | 40 +++++++++-- .../bulma/components/menu/label_component.rb | 23 ++++++ .../components/menu/list/item_component.rb | 23 ++++++ .../components/menu/list/list_component.rb | 23 ++++++ .../bulma/components/menu/list_component.rb | 25 +++++++ .../bulma/components/menu_component.rb | 31 ++++++++ .../components/message/header_component.rb | 11 +++ .../bulma/components/message_component.rb | 68 ++++++++++++++++++ .../components/card/footer/form_component.rbs | 13 ++++ .../components/card/footer/link_component.rbs | 13 ++++ .../components/card/footer/mail_component.rbs | 13 ++++ .../card/footer/phone_component.rbs | 13 ++++ .../components/card/footer/sms_component.rbs | 13 ++++ .../components/card/footer_component.rbs | 12 +++- .../bulma/components/menu/label_component.rbs | 10 +++ .../components/menu/list/item_component.rbs | 16 +++++ .../components/menu/list/list_component.rbs | 16 +++++ .../bulma/components/menu/list_component.rbs | 14 ++++ .../bulma/components/menu_component.rbs | 14 ++++ .../components/message/header_component.rbs | 8 +++ .../bulma/components/message_component.rbs | 20 ++++++ .../bulma/components/card_component_test.rb | 26 +++++-- .../bulma/components/menu_component_test.rb | 42 +++++++++++ .../components/message_component_test.rb | 72 +++++++++++++++++++ 29 files changed, 683 insertions(+), 11 deletions(-) create mode 100644 app/components/bulma/components/card/footer/form_component.rb create mode 100644 app/components/bulma/components/card/footer/link_component.rb create mode 100644 app/components/bulma/components/card/footer/mail_component.rb create mode 100644 app/components/bulma/components/card/footer/phone_component.rb create mode 100644 app/components/bulma/components/card/footer/sms_component.rb create mode 100644 app/components/bulma/components/menu/label_component.rb create mode 100644 app/components/bulma/components/menu/list/item_component.rb create mode 100644 app/components/bulma/components/menu/list/list_component.rb create mode 100644 app/components/bulma/components/menu/list_component.rb create mode 100644 app/components/bulma/components/menu_component.rb create mode 100644 app/components/bulma/components/message/header_component.rb create mode 100644 app/components/bulma/components/message_component.rb create mode 100644 sig/app/components/bulma/components/card/footer/form_component.rbs create mode 100644 sig/app/components/bulma/components/card/footer/link_component.rbs create mode 100644 sig/app/components/bulma/components/card/footer/mail_component.rbs create mode 100644 sig/app/components/bulma/components/card/footer/phone_component.rbs create mode 100644 sig/app/components/bulma/components/card/footer/sms_component.rbs create mode 100644 sig/app/components/bulma/components/menu/label_component.rbs create mode 100644 sig/app/components/bulma/components/menu/list/item_component.rbs create mode 100644 sig/app/components/bulma/components/menu/list/list_component.rbs create mode 100644 sig/app/components/bulma/components/menu/list_component.rbs create mode 100644 sig/app/components/bulma/components/menu_component.rbs create mode 100644 sig/app/components/bulma/components/message/header_component.rbs create mode 100644 sig/app/components/bulma/components/message_component.rbs create mode 100644 test/app/components/bulma/components/menu_component_test.rb create mode 100644 test/app/components/bulma/components/message_component_test.rb diff --git a/app/components/bulma/components/card/footer/form_component.rb b/app/components/bulma/components/card/footer/form_component.rb new file mode 100644 index 0000000..e510b12 --- /dev/null +++ b/app/components/bulma/components/card/footer/form_component.rb @@ -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 diff --git a/app/components/bulma/components/card/footer/link_component.rb b/app/components/bulma/components/card/footer/link_component.rb new file mode 100644 index 0000000..55546b8 --- /dev/null +++ b/app/components/bulma/components/card/footer/link_component.rb @@ -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 diff --git a/app/components/bulma/components/card/footer/mail_component.rb b/app/components/bulma/components/card/footer/mail_component.rb new file mode 100644 index 0000000..2250492 --- /dev/null +++ b/app/components/bulma/components/card/footer/mail_component.rb @@ -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 diff --git a/app/components/bulma/components/card/footer/phone_component.rb b/app/components/bulma/components/card/footer/phone_component.rb new file mode 100644 index 0000000..f475852 --- /dev/null +++ b/app/components/bulma/components/card/footer/phone_component.rb @@ -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 diff --git a/app/components/bulma/components/card/footer/sms_component.rb b/app/components/bulma/components/card/footer/sms_component.rb new file mode 100644 index 0000000..87a8892 --- /dev/null +++ b/app/components/bulma/components/card/footer/sms_component.rb @@ -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 diff --git a/app/components/bulma/components/card/footer_component.rb b/app/components/bulma/components/card/footer_component.rb index 75cc1d6..501d2b7 100644 --- a/app/components/bulma/components/card/footer_component.rb +++ b/app/components/bulma/components/card/footer_component.rb @@ -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 @@ -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 diff --git a/app/components/bulma/components/menu/label_component.rb b/app/components/bulma/components/menu/label_component.rb new file mode 100644 index 0000000..c408116 --- /dev/null +++ b/app/components/bulma/components/menu/label_component.rb @@ -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 diff --git a/app/components/bulma/components/menu/list/item_component.rb b/app/components/bulma/components/menu/list/item_component.rb new file mode 100644 index 0000000..7cbde94 --- /dev/null +++ b/app/components/bulma/components/menu/list/item_component.rb @@ -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 diff --git a/app/components/bulma/components/menu/list/list_component.rb b/app/components/bulma/components/menu/list/list_component.rb new file mode 100644 index 0000000..6f3e14b --- /dev/null +++ b/app/components/bulma/components/menu/list/list_component.rb @@ -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 diff --git a/app/components/bulma/components/menu/list_component.rb b/app/components/bulma/components/menu/list_component.rb new file mode 100644 index 0000000..11287a9 --- /dev/null +++ b/app/components/bulma/components/menu/list_component.rb @@ -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 diff --git a/app/components/bulma/components/menu_component.rb b/app/components/bulma/components/menu_component.rb new file mode 100644 index 0000000..46d65fa --- /dev/null +++ b/app/components/bulma/components/menu_component.rb @@ -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 diff --git a/app/components/bulma/components/message/header_component.rb b/app/components/bulma/components/message/header_component.rb new file mode 100644 index 0000000..c98770f --- /dev/null +++ b/app/components/bulma/components/message/header_component.rb @@ -0,0 +1,11 @@ +module Bulma + module Components + module Message + class HeaderComponent < ApplicationComponent + style do + base { "message-header" } + end + end + end + end +end diff --git a/app/components/bulma/components/message_component.rb b/app/components/bulma/components/message_component.rb new file mode 100644 index 0000000..c89c619 --- /dev/null +++ b/app/components/bulma/components/message_component.rb @@ -0,0 +1,68 @@ +module Bulma + module Components + class MessageComponent < ApplicationComponent + self.root_tag = :article + + # @dynamic message_header, with_message_header + renders_one :message_header, Message::HeaderComponent + + style do + base { "message" } + variants do + # steep:ignore:start + color do + dark { "is-dark" } + link { "is-link" } + primary { "is-primary" } + info { "is-info" } + success { "is-success" } + warning { "is-warning" } + danger { "is-danger" } + end + + size do + small { "is-small" } + normal { "is-normal" } + medium { "is-medium" } + large { "is-large" } + end + # steep:ignore:end + end + end + + style :body do + base { "message-body" } + end + + def initialize(color: nil, size: nil, **html_attributes) + @color = color + @size = size + + super(**html_attributes) + end + + def call + content_tag( + root_tag, + safe_join( + [message_header, message_body] + ), + **root_attributes(color: @color, size: @size) + ) + end + + private :with_message_header + def header(**html_attributes, &block) + with_message_header(**html_attributes, &block) + end + + private + + def message_body + tag.div class: style(:body) do + content + end + end + end + end +end diff --git a/sig/app/components/bulma/components/card/footer/form_component.rbs b/sig/app/components/bulma/components/card/footer/form_component.rbs new file mode 100644 index 0000000..686d709 --- /dev/null +++ b/sig/app/components/bulma/components/card/footer/form_component.rbs @@ -0,0 +1,13 @@ +module Bulma + module Components + module Card + module Footer + class FormComponent < ItemComponent + @name: untyped? + @options: untyped? + def initialize: (?untyped?, ?untyped?, **untyped) -> void + end + end + end + end +end diff --git a/sig/app/components/bulma/components/card/footer/link_component.rbs b/sig/app/components/bulma/components/card/footer/link_component.rbs new file mode 100644 index 0000000..9d0ea55 --- /dev/null +++ b/sig/app/components/bulma/components/card/footer/link_component.rbs @@ -0,0 +1,13 @@ +module Bulma + module Components + module Card + module Footer + class LinkComponent < ItemComponent + @name: untyped? + @options: untyped? + def initialize: (?untyped?, ?untyped?, **untyped) -> void + end + end + end + end +end diff --git a/sig/app/components/bulma/components/card/footer/mail_component.rbs b/sig/app/components/bulma/components/card/footer/mail_component.rbs new file mode 100644 index 0000000..9dad688 --- /dev/null +++ b/sig/app/components/bulma/components/card/footer/mail_component.rbs @@ -0,0 +1,13 @@ +module Bulma + module Components + module Card + module Footer + class MailComponent < ItemComponent + @email_address: untyped? + @name: untyped? + def initialize: (?untyped?, ?untyped?, **untyped) -> void + end + end + end + end +end diff --git a/sig/app/components/bulma/components/card/footer/phone_component.rbs b/sig/app/components/bulma/components/card/footer/phone_component.rbs new file mode 100644 index 0000000..320b3f9 --- /dev/null +++ b/sig/app/components/bulma/components/card/footer/phone_component.rbs @@ -0,0 +1,13 @@ +module Bulma + module Components + module Card + module Footer + class PhoneComponent < ItemComponent + @phone_number: untyped? + @name: untyped? + def initialize: (?untyped?, ?untyped?, **untyped) -> void + end + end + end + end +end diff --git a/sig/app/components/bulma/components/card/footer/sms_component.rbs b/sig/app/components/bulma/components/card/footer/sms_component.rbs new file mode 100644 index 0000000..ad15cb3 --- /dev/null +++ b/sig/app/components/bulma/components/card/footer/sms_component.rbs @@ -0,0 +1,13 @@ +module Bulma + module Components + module Card + module Footer + class SmsComponent < ItemComponent + @phone_number: untyped? + @name: untyped? + def initialize: (?untyped?, ?untyped?, **untyped) -> void + end + end + end + end +end diff --git a/sig/app/components/bulma/components/card/footer_component.rbs b/sig/app/components/bulma/components/card/footer_component.rbs index 7b78f41..8039a98 100644 --- a/sig/app/components/bulma/components/card/footer_component.rbs +++ b/sig/app/components/bulma/components/card/footer_component.rbs @@ -3,11 +3,21 @@ module Bulma module Card class FooterComponent < ApplicationComponent def item: (**untyped html_attributes) ?{ (Footer::ItemComponent component) -> String } -> Footer::ItemComponent + def link_to: (?untyped, ?untyped, **untyped) ?{ (?Footer::LinkComponent component) -> String } -> Footer::LinkComponent + def button_to: (?untyped, ?untyped, **untyped) ?{ (?Footer::FormComponent component) -> String } -> Footer::FormComponent + def mail_to: (untyped, ?untyped, **untyped) ?{ (?Footer::MailComponent component) -> String } -> Footer::MailComponent + def phone_to: (untyped, ?untyped, **untyped) ?{ (?Footer::PhoneComponent component) -> String } -> Footer::PhoneComponent + def sms_to: (untyped, ?untyped, **untyped) ?{ (?Footer::SmsComponent component) -> String } -> Footer::SmsComponent private def card_footer_items: -> Array[Footer::ItemComponent] - def with_card_footer_item: (**untyped html_attributes) ?{ (Footer::ItemComponent component) -> String } -> Footer::ItemComponent + def with_card_footer_item_tag: (**untyped html_attributes) ?{ (Footer::ItemComponent component) -> String } -> Footer::ItemComponent + def with_card_footer_item_link_to: (?untyped, ?untyped, **untyped) ?{ (?Footer::LinkComponent component) -> String } -> Footer::LinkComponent + def with_card_footer_item_button_to: (?untyped, ?untyped, **untyped) ?{ (?Footer::FormComponent component) -> String } -> Footer::FormComponent + def with_card_footer_item_sms_to: (untyped, ?untyped, **untyped) ?{ (?Footer::SmsComponent component) -> String } -> Footer::SmsComponent + def with_card_footer_item_phone_to: (untyped, ?untyped, **untyped) ?{ (?Footer::PhoneComponent component) -> String } -> Footer::PhoneComponent + def with_card_footer_item_mail_to: (untyped, ?untyped, **untyped) ?{ (?Footer::MailComponent component) -> String } -> Footer::MailComponent end end end diff --git a/sig/app/components/bulma/components/menu/label_component.rbs b/sig/app/components/bulma/components/menu/label_component.rbs new file mode 100644 index 0000000..c0f4679 --- /dev/null +++ b/sig/app/components/bulma/components/menu/label_component.rbs @@ -0,0 +1,10 @@ +module Bulma + module Components + module Menu + class LabelComponent < ApplicationComponent + @text: String? + def initialize: (?String? text, **untyped html_options) -> void + end + end + end +end diff --git a/sig/app/components/bulma/components/menu/list/item_component.rbs b/sig/app/components/bulma/components/menu/list/item_component.rbs new file mode 100644 index 0000000..017078c --- /dev/null +++ b/sig/app/components/bulma/components/menu/list/item_component.rbs @@ -0,0 +1,16 @@ +module Bulma + module Components + module Menu + module List + class ItemComponent < ApplicationComponent + def submenu: -> ListComponent + def list: (**untyped html_attributes) -> ListComponent + + private + + def with_submenu: (**untyped html_attributes) -> ListComponent + end + end + end + end +end diff --git a/sig/app/components/bulma/components/menu/list/list_component.rbs b/sig/app/components/bulma/components/menu/list/list_component.rbs new file mode 100644 index 0000000..9d98026 --- /dev/null +++ b/sig/app/components/bulma/components/menu/list/list_component.rbs @@ -0,0 +1,16 @@ +module Bulma + module Components + module Menu + module List + class ListComponent < ApplicationComponent + def item: (**untyped html_options) ?{ (ItemComponent component) -> String } -> ItemComponent + + private + + def list_items: -> Array[ItemComponent] + def with_list_item: (**untyped html_options) ?{ (ItemComponent component) -> String } -> ItemComponent + end + end + end + end +end diff --git a/sig/app/components/bulma/components/menu/list_component.rbs b/sig/app/components/bulma/components/menu/list_component.rbs new file mode 100644 index 0000000..c3910e0 --- /dev/null +++ b/sig/app/components/bulma/components/menu/list_component.rbs @@ -0,0 +1,14 @@ +module Bulma + module Components + module Menu + class ListComponent < ApplicationComponent + def item: (**untyped html_options) ?{ (List::ItemComponent component) -> String } -> List::ItemComponent + + private + + def list_items: -> Array[List::ItemComponent] + def with_list_item: (**untyped html_options) ?{ (List::ItemComponent component) -> String } -> List::ItemComponent + end + end + end +end diff --git a/sig/app/components/bulma/components/menu_component.rbs b/sig/app/components/bulma/components/menu_component.rbs new file mode 100644 index 0000000..5fa1540 --- /dev/null +++ b/sig/app/components/bulma/components/menu_component.rbs @@ -0,0 +1,14 @@ +module Bulma + module Components + class MenuComponent < ApplicationComponent + def label: (?String? text, **untyped html_options) ?{ (Menu::LabelComponent component) -> String } -> Menu::LabelComponent + def list: (**untyped html_options) ?{ (Menu::ListComponent component) -> String } -> Menu::ListComponent + + private + + def menu_elements: -> Array[Menu::LabelComponent | Menu::ListComponent] + def with_menu_element_label: (?String? text, **untyped html_options) ?{ (Menu::LabelComponent component) -> String } -> Menu::LabelComponent + def with_menu_element_list: (**untyped html_options) ?{ (Menu::ListComponent component) -> String } -> Menu::ListComponent + end + end +end diff --git a/sig/app/components/bulma/components/message/header_component.rbs b/sig/app/components/bulma/components/message/header_component.rbs new file mode 100644 index 0000000..e9214d6 --- /dev/null +++ b/sig/app/components/bulma/components/message/header_component.rbs @@ -0,0 +1,8 @@ +module Bulma + module Components + module Message + class HeaderComponent < ApplicationComponent + end + end + end +end diff --git a/sig/app/components/bulma/components/message_component.rbs b/sig/app/components/bulma/components/message_component.rbs new file mode 100644 index 0000000..df28e7f --- /dev/null +++ b/sig/app/components/bulma/components/message_component.rbs @@ -0,0 +1,20 @@ +module Bulma + module Components + class MessageComponent < ApplicationComponent + type color = :dark | :link | :primary | :info | :success | :warning | :danger + type size = :small | :normal | :medium | :large + + @color: color? + @size: size? + def initialize: (?color: color?, ?size: size?, **untyped html_attributes) -> void + + def header: (**untyped html_options) ?{ (Message::HeaderComponent component) -> String } -> Message::HeaderComponent + + private + + def message_body: -> String? + def message_header: -> Message::HeaderComponent + def with_message_header: (**untyped html_options) ?{ (Message::HeaderComponent component) -> String } -> Message::HeaderComponent + end + end +end diff --git a/test/app/components/bulma/components/card_component_test.rb b/test/app/components/bulma/components/card_component_test.rb index 7eb17da..2f73a82 100644 --- a/test/app/components/bulma/components/card_component_test.rb +++ b/test/app/components/bulma/components/card_component_test.rb @@ -31,9 +31,12 @@ def test_render_component end end card.footer do |footer| - footer.item(tag: :a, href: "#") { "Save" } - footer.item(tag: :a, href: "#") { "Edit" } - footer.item(tag: :a, href: "#") { "Delete" } + footer.button_to "It's form tag", "https://rubyonrails.org" + footer.link_to "Ruby on Rails", "https://rubyonrails.org" + footer.sms_to("123456789") { "Sms me" } + footer.phone_to "123456789", "Phone me" + footer.mail_to "example@example.com", "Mail me" + footer.item(tag: :span) { "Just a text" } end end assert_component_rendered @@ -44,9 +47,20 @@ def test_render_component assert_selector(".card>.card-header>button", count: 1, visible: true, class: "card-header-icon") assert_selector(".card>div", count: 1, visible: true, class: "card-content") assert_selector(".card>footer", count: 1, visible: true, class: "card-footer") - assert_selector(".card>.card-footer>a", text: "Save", count: 1, visible: true, class: "card-footer-item") - assert_selector(".card>.card-footer>a", text: "Edit", count: 1, visible: true, class: "card-footer-item") - assert_selector(".card>.card-footer>a", text: "Delete", count: 1, visible: true, class: "card-footer-item") + assert_selector( + ".card>.card-footer>form[action='https://rubyonrails.org'][method='post'].button_to>button[type='submit']", text: "It's form tag", count: 1, visible: true, class: "card-footer-item" + ) + assert_selector( + ".card>.card-footer>a[href='https://rubyonrails.org']", text: "Ruby on Rails", count: 1, visible: true, class: "card-footer-item" + ) + assert_selector(".card>.card-footer>a[href='sms:123456789;']", text: "Sms me", count: 1, visible: true, class: "card-footer-item") + assert_selector(".card>.card-footer>a[href='tel:123456789']", text: "Phone me", count: 1, visible: true, class: "card-footer-item") + assert_selector( + ".card>.card-footer>a[href='mailto:example@example.com']", text: "Mail me", count: 1, visible: true, class: "card-footer-item" + ) + assert_selector( + ".card>.card-footer>span", text: "Just a text", count: 1, visible: true, class: "card-footer-item" + ) end def test_render_without_body diff --git a/test/app/components/bulma/components/menu_component_test.rb b/test/app/components/bulma/components/menu_component_test.rb new file mode 100644 index 0000000..5456eb8 --- /dev/null +++ b/test/app/components/bulma/components/menu_component_test.rb @@ -0,0 +1,42 @@ +require "test_helper" + +module Bulma + module Components + class MenuComponentTest < ViewComponents::TestCase + def test_render_component + component = MenuComponent.new + render_inline(component) do |menu| + menu.label "General" + menu.list do |list| + list.item { link_to "Dashboard", "#" } + list.item { link_to "Customers", "#" } + end + menu.label "Adniminstration" + menu.list do |list| + list.item { link_to "Team settings", "#" } + list.item do |item| + item.list do |list| + list.item { link_to "Members", "#" } + list.item { link_to "Plugins", "#" } + list.item { link_to "Add a member", "#" } + end + + link_to("Manage Your Team", "#", class: "is-active") + end + list.item { link_to "Invitations", "#" } + list.item { link_to "Cloud Storage Environment Settings", "#" } + list.item { link_to "Authentication", "#" } + end + menu.label "Transactions" + menu.list do |list| + list.item { link_to "Payments", "#" } + list.item { link_to "Transfers", "#" } + list.item { link_to "Balance", "#" } + end + end + assert_component_rendered + assert_selector("aside", count: 1, visible: true, class: "menu") + end + end + end +end diff --git a/test/app/components/bulma/components/message_component_test.rb b/test/app/components/bulma/components/message_component_test.rb new file mode 100644 index 0000000..aec62d6 --- /dev/null +++ b/test/app/components/bulma/components/message_component_test.rb @@ -0,0 +1,72 @@ +require "test_helper" + +module Bulma + module Components + class MessageComponentTest < ViewComponents::TestCase + def test_render_component + component = MessageComponent.new + render_inline(component) do |message| + message.header do + safe_join([ + tag.p("Hello world"), + render(Elements::DeleteComponent.new(aria: {label: "delete"})) + ]) + end + + <<~HTML.html_safe + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Pellentesque risus mi, tempus quis placerat ut, porta nec + nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus + diam, et dictum felis venenatis efficitur. Aenean ac + eleifend lacus, in mollis lectus. Donec sodales, arcu et + sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi magna a + neque. Donec dui urna, vehicula et sem eget, facilisis sodales sem. + HTML + end + assert_component_rendered + assert_selector("article", count: 1, visible: true, class: "message") + assert_selector(".message>div", count: 1, visible: true, class: "message-header") + assert_selector(".message>div", count: 1, visible: true, class: "message-body") + end + + def test_without_content + component = MessageComponent.new + render_inline(component) do |message| + message.header do + safe_join([ + tag.p("Hello world"), + render(Elements::DeleteComponent.new(aria: {label: "delete"})) + ]) + end + end + assert_component_rendered + end + + def test_render_without_header + component = MessageComponent.new + render_inline(component) do |message| + tag.strong "Some content" + end + assert_component_rendered + end + + def test_color_variants + %i[dark link primary info success warning danger].each do |color| + component = MessageComponent.new(color: color).with_content("Some content") + render_inline(component) + assert_component_rendered + assert_selector("article.message", count: 1, visible: true, class: "is-#{color}") + end + end + + def test_size_variants + %i[small normal medium large].each do |size| + component = MessageComponent.new(size: size).with_content("Some content") + render_inline(component) + assert_component_rendered + assert_selector("article.message", count: 1, visible: true, class: "is-#{size}") + end + end + end + end +end