railsboot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +45 -0
  4. data/Rakefile +14 -0
  5. data/app/assets/config/railsboot_manifest.js +1 -0
  6. data/app/assets/stylesheets/railsboot/application.css +15 -0
  7. data/app/components/railsboot/accordion/item_component.html.erb +10 -0
  8. data/app/components/railsboot/accordion/item_component.rb +21 -0
  9. data/app/components/railsboot/accordion_component.html.erb +5 -0
  10. data/app/components/railsboot/accordion_component.rb +15 -0
  11. data/app/components/railsboot/alert_component.html.erb +4 -0
  12. data/app/components/railsboot/alert_component.rb +21 -0
  13. data/app/components/railsboot/badge_component.html.erb +3 -0
  14. data/app/components/railsboot/badge_component.rb +15 -0
  15. data/app/components/railsboot/base_component.html.erb +3 -0
  16. data/app/components/railsboot/base_component.rb +6 -0
  17. data/app/components/railsboot/breadcrumb/item_component.html.erb +11 -0
  18. data/app/components/railsboot/breadcrumb/item_component.rb +21 -0
  19. data/app/components/railsboot/breadcrumb_component.html.erb +7 -0
  20. data/app/components/railsboot/breadcrumb_component.rb +25 -0
  21. data/app/components/railsboot/button/button_component.rb +5 -0
  22. data/app/components/railsboot/button/input_component.rb +5 -0
  23. data/app/components/railsboot/button/link_component.rb +5 -0
  24. data/app/components/railsboot/button_component.html.erb +21 -0
  25. data/app/components/railsboot/button_component.rb +49 -0
  26. data/app/components/railsboot/button_group_component.html.erb +3 -0
  27. data/app/components/railsboot/button_group_component.rb +24 -0
  28. data/app/components/railsboot/card/body_component.rb +14 -0
  29. data/app/components/railsboot/card/footer_component.rb +14 -0
  30. data/app/components/railsboot/card/header_component.rb +14 -0
  31. data/app/components/railsboot/card_component.html.erb +11 -0
  32. data/app/components/railsboot/card_component.rb +17 -0
  33. data/app/components/railsboot/carousel/item_component.html.erb +3 -0
  34. data/app/components/railsboot/carousel/item_component.rb +14 -0
  35. data/app/components/railsboot/carousel_component.html.erb +15 -0
  36. data/app/components/railsboot/carousel_component.rb +14 -0
  37. data/app/components/railsboot/close_button_component.html.erb +1 -0
  38. data/app/components/railsboot/close_button_component.rb +18 -0
  39. data/app/components/railsboot/component.rb +23 -0
  40. data/app/components/railsboot/dropdown/action_component.html.erb +5 -0
  41. data/app/components/railsboot/dropdown/action_component.rb +31 -0
  42. data/app/components/railsboot/dropdown/divider_component.html.erb +3 -0
  43. data/app/components/railsboot/dropdown/divider_component.rb +10 -0
  44. data/app/components/railsboot/dropdown/header_component.html.erb +3 -0
  45. data/app/components/railsboot/dropdown/header_component.rb +11 -0
  46. data/app/components/railsboot/dropdown/link_component.html.erb +3 -0
  47. data/app/components/railsboot/dropdown/link_component.rb +23 -0
  48. data/app/components/railsboot/dropdown_component.html.erb +9 -0
  49. data/app/components/railsboot/dropdown_component.rb +18 -0
  50. data/app/components/railsboot/heading_component.html.erb +3 -0
  51. data/app/components/railsboot/heading_component.rb +21 -0
  52. data/app/components/railsboot/list_group/item_component.rb +28 -0
  53. data/app/components/railsboot/list_group_component.html.erb +5 -0
  54. data/app/components/railsboot/list_group_component.rb +14 -0
  55. data/app/components/railsboot/modal/body_component.rb +14 -0
  56. data/app/components/railsboot/modal/footer_component.rb +14 -0
  57. data/app/components/railsboot/modal/header_component.html.erb +4 -0
  58. data/app/components/railsboot/modal/header_component.rb +10 -0
  59. data/app/components/railsboot/modal_component.html.erb +9 -0
  60. data/app/components/railsboot/modal_component.rb +27 -0
  61. data/app/components/railsboot/nav/item_component.html.erb +19 -0
  62. data/app/components/railsboot/nav/item_component.rb +32 -0
  63. data/app/components/railsboot/nav_component.html.erb +5 -0
  64. data/app/components/railsboot/nav_component.rb +23 -0
  65. data/app/components/railsboot/navbar/brand_component.rb +16 -0
  66. data/app/components/railsboot/navbar/nav_component.html.erb +5 -0
  67. data/app/components/railsboot/navbar/nav_component.rb +14 -0
  68. data/app/components/railsboot/navbar/toggler_component.html.erb +3 -0
  69. data/app/components/railsboot/navbar/toggler_component.rb +22 -0
  70. data/app/components/railsboot/navbar_component.html.erb +3 -0
  71. data/app/components/railsboot/navbar_component.rb +15 -0
  72. data/app/components/railsboot/offcanvas/body_component.rb +15 -0
  73. data/app/components/railsboot/offcanvas/header_component.html.erb +5 -0
  74. data/app/components/railsboot/offcanvas/header_component.rb +11 -0
  75. data/app/components/railsboot/offcanvas_component.html.erb +4 -0
  76. data/app/components/railsboot/offcanvas_component.rb +25 -0
  77. data/app/components/railsboot/pagination_component.html.erb +1 -0
  78. data/app/components/railsboot/pagination_component.rb +9 -0
  79. data/app/components/railsboot/progress_component.html.erb +3 -0
  80. data/app/components/railsboot/progress_component.rb +34 -0
  81. data/app/components/railsboot/spinner_component.html.erb +3 -0
  82. data/app/components/railsboot/spinner_component.rb +23 -0
  83. data/app/components/railsboot/table/body_component.html.erb +9 -0
  84. data/app/components/railsboot/table/body_component.rb +7 -0
  85. data/app/components/railsboot/table/cell_component.rb +13 -0
  86. data/app/components/railsboot/table/head_component.html.erb +9 -0
  87. data/app/components/railsboot/table/head_component.rb +7 -0
  88. data/app/components/railsboot/table/row_component.html.erb +9 -0
  89. data/app/components/railsboot/table/row_component.rb +7 -0
  90. data/app/components/railsboot/table_component.html.erb +9 -0
  91. data/app/components/railsboot/table_component.rb +14 -0
  92. data/app/components/railsboot/toast/body_component.rb +15 -0
  93. data/app/components/railsboot/toast/header_component.rb +17 -0
  94. data/app/components/railsboot/toast_component.html.erb +4 -0
  95. data/app/components/railsboot/toast_component.rb +21 -0
  96. data/app/helpers/railsboot/view_components_helper.rb +34 -0
  97. data/config/routes.rb +2 -0
  98. data/lib/railsboot/engine.rb +20 -0
  99. data/lib/railsboot/version.rb +3 -0
  100. data/lib/railsboot.rb +9 -0
  101. data/lib/tasks/railsboot_tasks.rake +4 -0
  102. metadata +196 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e03b1033fe356b40d6f9e1d7b39e739240186dc66781d5d4d1c843bf341466dc
4
+ data.tar.gz: 9855fd58d10806d2c35371e5ffc4b562be2ef39c23b5f7c083e81d93eb57749e
5
+ SHA512:
6
+ metadata.gz: 262471240b239e5fc8af3abe6db458f8734a187d84c8d991a409fbbb8de914a62d24c40af8ec78bb250839bba985a18a46074f70bcfdd04a87358b0747327389
7
+ data.tar.gz: 4c7dc4f046a0bdd71b4802e2327c8d9aff68f1b6937ccb9409f171cc002d57dc9e93365f022411371a892f2e9c43b0fbfb83cd691df12c753d9a47b48e2e57f6
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Daniel Schoppmann
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Railsboot
2
+ Railsboot is an implementation of the famous Bootstrap CSS framework using Rails View Components.
3
+
4
+ ## Preview
5
+ You'll find detailed information on how to use Railsboot on https://railsbootui.com
6
+
7
+ ## Installation
8
+
9
+ Add `railsboot` to your Gemfile and run `bundle install`:
10
+
11
+ ```ruby
12
+ bundle add railsboot && bundle install
13
+ ```
14
+
15
+ Also make ensure that you have correctly setup bootstrap in your Rails app. Otherwise the bootstrap styles and js files will not work.
16
+
17
+ ## Usage
18
+ Each view component can be rendered with either a standard component call
19
+
20
+ ```erb
21
+ <%= render Railsboot::BadgeComponent.new { "My badge"} %>
22
+ ```
23
+
24
+ or with the integrated component helper
25
+
26
+ ```erb
27
+ <%= railsboot_badge { "My badge"} %>
28
+ ```
29
+
30
+ ## Configuration
31
+ Several view components ensure a valid bootstrap theme color scheme, so if you tweaked or enhanced the standard bootstrap volor palette, you should also add this to the gem. Create an initializer (in `config/initializers/railsboot.rb`):
32
+
33
+ ```ruby
34
+ # defaults to ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
35
+ Railsboot.colors = ["primary", "secondary", "my-color"]
36
+ ```
37
+
38
+ ## Development
39
+ Download the source code and run
40
+
41
+ 1. `bundle install` for instaling the dev dependencies
42
+ 2. `bundle exec rake test` for running the test
43
+
44
+ ## License
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+ load "rails/tasks/statistics.rake"
6
+
7
+ require "bundler/gem_tasks"
8
+ require "rake/testtask"
9
+
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << "test"
12
+ t.pattern = "test/**/*_test.rb"
13
+ t.verbose = false
14
+ end
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/railsboot .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,10 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <%= content_tag :h2, class: "accordion-header" do %>
3
+ <%= content_tag :button, header, class: class_names("accordion-button", "collapsed" => !@expanded), type: "button", data: {bs_toggle: "collapse", bs_target: "##{@id}"}, aria: {expanded: @expanded, controls: @id} %>
4
+ <% end %>
5
+ <%= content_tag :div, id: @id, class: class_names("accordion-collapse collapse", "show" => @expanded), data: parent_reference do %>
6
+ <%= content_tag :div, class: "accordion-body" do %>
7
+ <%= body %>
8
+ <% end %>
9
+ <% end %>
10
+ <% end %>
@@ -0,0 +1,21 @@
1
+ class Railsboot::Accordion::ItemComponent < Railsboot::Component
2
+ renders_one :header
3
+ renders_one :body
4
+
5
+ def initialize(id:, parent_id: "", expanded: false, **html_attributes)
6
+ @id = id
7
+ @parent_id = parent_id
8
+ @expanded = expanded
9
+ @html_attributes = html_attributes
10
+
11
+ @html_attributes[:tag] = "div"
12
+ @html_attributes[:class] = class_names(
13
+ "accordion-item",
14
+ html_attributes.delete(:class)
15
+ )
16
+ end
17
+
18
+ def parent_reference
19
+ @parent_id.present? ? {bs_parent: "##{@parent_id}"} : {}
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <% items.each do |item| %>
3
+ <%= item %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,15 @@
1
+ class Railsboot::AccordionComponent < Railsboot::Component
2
+ renders_many :items, Railsboot::Accordion::ItemComponent
3
+
4
+ def initialize(flush: false, **html_attributes)
5
+ @flush = flush
6
+ @html_attributes = html_attributes
7
+
8
+ @html_attributes[:tag] = "div"
9
+ @html_attributes[:class] = class_names(
10
+ "accordion",
11
+ {"accordion-flush" => @flush},
12
+ html_attributes.delete(:class)
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <%= content %>
3
+ <%= render Railsboot::CloseButtonComponent.new(data: {bs_dismiss: "alert"}) if @dismissible %>
4
+ <% end %>
@@ -0,0 +1,21 @@
1
+ class Railsboot::AlertComponent < Railsboot::Component
2
+ def initialize(color: DEFAULT_COLOR, dismissible: false, **html_attributes)
3
+ @color = fetch_or_raise(color, COLORS)
4
+ @dismissible = dismissible
5
+ @html_attributes = html_attributes
6
+
7
+ @html_attributes[:tag] = "div"
8
+ @html_attributes[:class] = class_names(
9
+ "alert",
10
+ "alert-#{@color}",
11
+ {"alert-dismissible fade show" => @dismissible},
12
+ html_attributes.delete(:class)
13
+ )
14
+ end
15
+
16
+ protected
17
+
18
+ def before_render
19
+ @html_attributes["role"] = "alert"
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <% content %>
3
+ <% end %>
@@ -0,0 +1,15 @@
1
+ class Railsboot::BadgeComponent < Railsboot::Component
2
+ def initialize(pill: false, color: DEFAULT_COLOR, **html_attributes)
3
+ @pill = pill
4
+ @color = fetch_or_raise(color, COLORS)
5
+ @html_attributes = html_attributes
6
+
7
+ @html_attributes[:tag] = :span
8
+ @html_attributes[:class] = class_names(
9
+ "badge",
10
+ "bg-#{@color}",
11
+ {"rounded-pill" => @pill},
12
+ html_attributes.delete(:class)
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ <%= content_tag(@tag, **@html_attributes) do %>
2
+ <%= content %>
3
+ <% end %>
@@ -0,0 +1,6 @@
1
+ class Railsboot::BaseComponent < Railsboot::Component
2
+ def initialize(tag:, **html_attributes)
3
+ @tag = tag
4
+ @html_attributes = html_attributes
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <% if @active %>
3
+ <%= @text %>
4
+ <% else %>
5
+ <% if @href.present? %>
6
+ <%= link_to @text, @href %>
7
+ <% else %>
8
+ <%= @text %>
9
+ <% end %>
10
+ <% end %>
11
+ <% end %>
@@ -0,0 +1,21 @@
1
+ class Railsboot::Breadcrumb::ItemComponent < Railsboot::Component
2
+ def initialize(text: "", href: "", active: false, **html_attributes)
3
+ @text = text
4
+ @href = href
5
+ @active = active
6
+ @html_attributes = html_attributes
7
+
8
+ @html_attributes[:tag] = "li"
9
+ @html_attributes[:class] = class_names(
10
+ "breadcrumb-item",
11
+ {"active" => @active},
12
+ html_attributes.delete(:class)
13
+ )
14
+ end
15
+
16
+ protected
17
+
18
+ def before_render
19
+ @html_attributes["aria-current"] = "page" if @active
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <%= render Railsboot::BaseComponent.new(**@wrapper_attributes) do %>
3
+ <% items.each do |item| %>
4
+ <%= item %>
5
+ <% end %>
6
+ <% end %>
7
+ <% end %>
@@ -0,0 +1,25 @@
1
+ class Railsboot::BreadcrumbComponent < Railsboot::Component
2
+ renders_many :items, Railsboot::Breadcrumb::ItemComponent
3
+
4
+ def initialize(wrapper_attributes: {}, **html_attributes)
5
+ @wrapper_attributes = wrapper_attributes
6
+ @html_attributes = html_attributes
7
+
8
+ @html_attributes[:tag] = "nav"
9
+ @html_attributes[:class] = class_names(
10
+ html_attributes.delete(:class)
11
+ ).presence
12
+
13
+ @wrapper_attributes[:tag] = "ol"
14
+ @wrapper_attributes[:class] = class_names(
15
+ "breadcrumb",
16
+ wrapper_attributes.delete(:class)
17
+ )
18
+ end
19
+
20
+ private
21
+
22
+ def before_render
23
+ @html_attributes["aria-label"] = "breadcrumb"
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ class Railsboot::Button::ButtonComponent < Railsboot::ButtonComponent
2
+ def initialize(**html_attributes)
3
+ super(tag: "button", **html_attributes)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Railsboot::Button::InputComponent < Railsboot::ButtonComponent
2
+ def initialize(**html_attributes)
3
+ super(tag: "input", **html_attributes)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Railsboot::Button::LinkComponent < Railsboot::ButtonComponent
2
+ def initialize(**html_attributes)
3
+ super(tag: "a", **html_attributes)
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ <% if button? %>
2
+
3
+ <%= content_tag :button, type: "button", **@html_attributes do %>
4
+ <%= @text.presence || content %>
5
+ <% end %>
6
+
7
+ <% elsif link? %>
8
+
9
+ <%= link_to @href, **@html_attributes do %>
10
+ <%= @text.presence || content %>
11
+ <% end %>
12
+
13
+ <% elsif input? %>
14
+
15
+ <% if @form.present? %>
16
+ <%= @form.submit(**@html_attributes) %>
17
+ <% else %>
18
+ <%= helpers.tag :input, **@html_attributes %>
19
+ <% end %>
20
+
21
+ <% end %>
@@ -0,0 +1,49 @@
1
+ class Railsboot::ButtonComponent < Railsboot::Component
2
+ TAGS = ["button", "a", "input"].freeze
3
+ DEFAULT_TAG = "button".freeze
4
+
5
+ VARIANTS = (COLORS + ["link"]).freeze
6
+ DEFAULT_VARIANT = DEFAULT_COLOR
7
+
8
+ SIZES = ["", "lg", "sm"].freeze
9
+ DEFAULT_SIZE = "".freeze
10
+
11
+ def initialize(text: "", href: "", tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, size: DEFAULT_SIZE, outline: false, form: nil, **html_attributes)
12
+ @tag = fetch_or_raise(tag, TAGS)
13
+ @text = text
14
+ @href = href
15
+ @variant = fetch_or_raise(variant, VARIANTS)
16
+ @outline = outline
17
+ @size = fetch_or_fallback(size, SIZES, DEFAULT_SIZE)
18
+ @form = form
19
+ @html_attributes = html_attributes
20
+
21
+ @html_attributes[:class] = class_names(
22
+ "btn",
23
+ ["btn", ("outline" if @outline), @variant].compact_blank.join("-"),
24
+ {"btn-#{@size}" => @size.present?},
25
+ html_attributes.delete(:class)
26
+ )
27
+ end
28
+
29
+ def button?
30
+ @tag == "button"
31
+ end
32
+
33
+ def link?
34
+ @tag == "a"
35
+ end
36
+
37
+ def input?
38
+ @tag == "input"
39
+ end
40
+
41
+ private
42
+
43
+ def before_render
44
+ if input?
45
+ @html_attributes["type"] = "submit"
46
+ @html_attributes["value"] = @text.presence || content
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ <%= render Railsboot::BaseComponent.new(**@html_attributes) do %>
2
+ <%= content %>
3
+ <% end %>
@@ -0,0 +1,24 @@
1
+ class Railsboot::ButtonGroupComponent < Railsboot::Component
2
+ SIZES = ["", "lg", "sm"].freeze
3
+ DEFAULT_SIZE = "".freeze
4
+
5
+ def initialize(aria_label: "", size: DEFAULT_SIZE, **html_attributes)
6
+ @aria_label = aria_label
7
+ @size = fetch_or_fallback(size, SIZES, DEFAULT_SIZE)
8
+ @html_attributes = html_attributes
9
+
10
+ @html_attributes[:tag] = "div"
11
+ @html_attributes[:class] = class_names(
12
+ "btn-group",
13
+ {"btn-group-#{@size}" => @size.present?},
14
+ html_attributes.delete(:class)
15
+ )
16
+ end
17
+
18
+ protected
19
+
20
+ def before_render
21
+ @html_attributes["role"] = "group"
22
+ @html_attributes["aria-label"] = @aria_label if @aria_label.present?
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class Railsboot::Card::BodyComponent < Railsboot::CardComponent
2
+ def initialize(**html_attributes)
3
+ @html_attributes = html_attributes
4
+
5
+ @html_attributes[:class] = class_names(
6
+ "card-body",
7
+ html_attributes.delete(:class)
8
+ )
9
+ end
10
+
11
+ def call
12
+ render(Railsboot::BaseComponent.new(tag: "div", **@html_attributes)) { content }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class Railsboot::Card::FooterComponent < Railsboot::CardComponent
2
+ def initialize(**html_attributes)
3
+ @html_attributes = html_attributes
4
+
5
+ @html_attributes[:class] = class_names(
6
+ "card-footer",
7
+ html_attributes.delete(:class)
8
+ )
9
+ end
10
+
11
+ def call
12
+ render(Railsboot::BaseComponent.new(tag: "div", **@html_attributes)) { content }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class Railsboot::Card::HeaderComponent < Railsboot::CardComponent
2
+ def initialize(**html_attributes)
3
+ @html_attributes = html_attributes
4
+
5
+ @html_attributes[:class] = class_names(
6
+ "card-header",
7
+ html_attributes.delete(:class)
8
+ )
9
+ end
10
+
11
+ def call
12
+ render(Railsboot::BaseComponent.new(tag: "div", **@html_attributes)) { content }
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ <%= content_tag :div, **@html_attributes do %>
2
+ <%= content %>
3
+ <%= header %>
4
+ <% bodies.each do |body| %>
5
+ <%= body %>
6
+ <% end %>
7
+ <% list_groups.each do |list_group| %>
8
+ <%= list_group %>
9
+ <% end %>
10
+ <%= footer %>
11
+ <% end %>
@@ -0,0 +1,17 @@
1
+ class Railsboot::CardComponent < Railsboot::Component
2
+ renders_one :header, Railsboot::Card::HeaderComponent
3
+ renders_many :bodies, Railsboot::Card::BodyComponent
4
+ renders_many :list_groups, lambda { |**html_attributes|
5
+ Railsboot::ListGroupComponent.new(flush: true, **html_attributes)
6
+ }
7
+ renders_one :footer, Railsboot::Card::FooterComponent
8
+
9
+ def initialize(**html_attributes)
10
+ @html_attributes = html_attributes
11
+
12
+ @html_attributes[:class] = class_names(
13
+ "card",
14
+ html_attributes.delete(:class)
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ <%= content_tag :div, **@html_attributes do %>
2
+ <%= content %>
3
+ <% end %>
@@ -0,0 +1,14 @@
1
+ class Railsboot::Carousel::ItemComponent < Railsboot::Component
2
+ attr_reader :active
3
+
4
+ def initialize(active: false, **html_attributes)
5
+ @active = active
6
+ @html_attributes = html_attributes
7
+
8
+ @html_attributes[:class] = class_names(
9
+ "carousel-item",
10
+ {"active" => @active},
11
+ html_attributes.delete(:class)
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ <%= content_tag :div, **@html_attributes do %>
2
+ <%= content_tag :div, class: "carousel-inner" do %>
3
+ <% items.each do |item| %>
4
+ <%= item %>
5
+ <% end %>
6
+ <% end %>
7
+ <button class="carousel-control-prev" type="button" data-bs-target="#<%= @id %>" data-bs-slide="prev">
8
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
9
+ <span class="visually-hidden">Previous</span>
10
+ </button>
11
+ <button class="carousel-control-next" type="button" data-bs-target="#<%= @id %>" data-bs-slide="next">
12
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
13
+ <span class="visually-hidden">Next</span>
14
+ </button>
15
+ <% end %>
@@ -0,0 +1,14 @@
1
+ class Railsboot::CarouselComponent < Railsboot::Component
2
+ renders_many :items, Railsboot::Carousel::ItemComponent
3
+
4
+ def initialize(id:, **html_attributes)
5
+ @id = id
6
+ @html_attributes = html_attributes
7
+
8
+ @html_attributes[:id] = @id
9
+ @html_attributes[:class] = class_names(
10
+ "carousel",
11
+ "slide"
12
+ )
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ <%= content_tag :button, nil, **@html_attributes %>
@@ -0,0 +1,18 @@
1
+ class Railsboot::CloseButtonComponent < Railsboot::Component
2
+ def initialize(disabled: false, **html_attributes)
3
+ @disabled = disabled
4
+ @html_attributes = html_attributes
5
+
6
+ @html_attributes[:class] = class_names(
7
+ "btn-close",
8
+ html_attributes.delete(:class)
9
+ )
10
+ end
11
+
12
+ private
13
+
14
+ def before_render
15
+ @html_attributes["aria-label"] = "Close"
16
+ @html_attributes["disabled"] = "disabled" if @disabled
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # parent class for all bootstrap related components
2
+ class Railsboot::Component < ViewComponent::Base
3
+ COLORS = Railsboot.colors.freeze
4
+ DEFAULT_COLOR = "primary".freeze
5
+
6
+ protected
7
+
8
+ def fetch_or_raise(argument, constant)
9
+ if argument.present? && constant.include?(argument.to_s)
10
+ argument
11
+ else
12
+ raise ArgumentError, "The `#{argument}: #{argument}` argument is not valid, allowed options are #{constant.join(", ")}."
13
+ end
14
+ end
15
+
16
+ def fetch_or_fallback(argument, constant, fallback)
17
+ if argument.present? && constant.include?(argument.to_s)
18
+ argument
19
+ else
20
+ fallback
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ <% if button? %>
2
+ <%= render Railsboot::Button::ButtonComponent.new(text: @text, variant: @variant, **@html_attributes) %>
3
+ <% else %>
4
+ <%= render Railsboot::Button::LinkComponent.new(text: @text, variant: @variant, **@html_attributes) %>
5
+ <% end %>
@@ -0,0 +1,31 @@
1
+ class Railsboot::Dropdown::ActionComponent < Railsboot::Component
2
+ TYPES = ["button", "link"].freeze
3
+ DEFAULT_TYPE = "button".freeze
4
+
5
+ def initialize(text: "", type: DEFAULT_TYPE, variant: Railsboot::ButtonComponent::DEFAULT_VARIANT, **html_attributes)
6
+ @text = text
7
+ @variant = variant
8
+ @type = fetch_or_raise(type, TYPES)
9
+ @html_attributes = html_attributes
10
+
11
+ @html_attributes[:class] = class_names(
12
+ "dropdown-toggle",
13
+ html_attributes.delete(:class)
14
+ )
15
+ end
16
+
17
+ def button?
18
+ @type == "button"
19
+ end
20
+
21
+ def link?
22
+ @type == "link"
23
+ end
24
+
25
+ private
26
+
27
+ def before_render
28
+ @html_attributes["data-bs-toggle"] = "dropdown"
29
+ @html_attributes["aria-expanded"] = "false"
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ <%= content_tag :li, **@html_attributes do %>
2
+ <hr>
3
+ <% end %>
@@ -0,0 +1,10 @@
1
+ class Railsboot::Dropdown::DividerComponent < Railsboot::Component
2
+ def initialize(**html_attributes)
3
+ @html_attributes = html_attributes
4
+
5
+ @html_attributes[:class] = class_names(
6
+ "dropdown-divider",
7
+ html_attributes.delete(:class)
8
+ )
9
+ end
10
+ end