bs5 0.0.26 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/bs5/carousel/caption_component.html.erb +3 -0
  3. data/app/components/bs5/carousel/caption_component.rb +8 -0
  4. data/app/components/bs5/carousel/item_component.html.erb +4 -0
  5. data/app/components/bs5/carousel/item_component.rb +74 -0
  6. data/app/components/bs5/carousel_component.html.erb +30 -0
  7. data/app/components/bs5/carousel_component.rb +60 -0
  8. data/app/components/bs5/modal/body_component.html.erb +3 -0
  9. data/app/components/bs5/modal/body_component.rb +8 -0
  10. data/app/components/bs5/modal/controller_component.html.erb +1 -0
  11. data/app/components/bs5/modal/controller_component.rb +40 -0
  12. data/app/components/bs5/modal/footer_component.html.erb +4 -0
  13. data/app/components/bs5/modal/footer_component.rb +8 -0
  14. data/app/components/bs5/modal/header_component.html.erb +4 -0
  15. data/app/components/bs5/modal/header_component.rb +18 -0
  16. data/app/components/bs5/modal_component.html.erb +11 -0
  17. data/app/components/bs5/modal_component.rb +80 -0
  18. data/app/components/bs5/nav/item_component.html.erb +1 -0
  19. data/app/components/bs5/nav/item_component.rb +80 -0
  20. data/app/components/bs5/nav_component.html.erb +7 -0
  21. data/app/components/bs5/nav_component.rb +47 -0
  22. data/app/components/bs5/progress/bar_component.html.erb +1 -0
  23. data/app/components/bs5/progress/bar_component.rb +60 -0
  24. data/app/components/bs5/progress_component.html.erb +9 -0
  25. data/app/components/bs5/progress_component.rb +15 -0
  26. data/app/components/bs5/tabs/item_component.html.erb +3 -0
  27. data/app/components/bs5/tabs/item_component.rb +48 -0
  28. data/app/components/bs5/tabs/link_component.html.erb +1 -0
  29. data/app/components/bs5/tabs/link_component.rb +27 -0
  30. data/app/components/bs5/tabs_component.html.erb +16 -0
  31. data/app/components/bs5/tabs_component.rb +63 -0
  32. data/app/helpers/bs5/components_helper.rb +6 -3
  33. data/app/views/bs5/examples/carousel/_dark_variant.html.erb +2 -0
  34. data/app/views/bs5/examples/carousel/_examples.html.erb +13 -0
  35. data/app/views/bs5/examples/carousel/dark_variant/snippet1.html.erb +25 -0
  36. data/app/views/bs5/examples/carousel/examples/snippet1.html.erb +13 -0
  37. data/app/views/bs5/examples/carousel/examples/snippet2.html.erb +13 -0
  38. data/app/views/bs5/examples/carousel/examples/snippet3.html.erb +13 -0
  39. data/app/views/bs5/examples/carousel/examples/snippet4.html.erb +25 -0
  40. data/app/views/bs5/examples/carousel/examples/snippet5.html.erb +13 -0
  41. data/app/views/bs5/examples/carousel/examples/snippet6.html.erb +13 -0
  42. data/app/views/bs5/examples/modal/_examples.html.erb +9 -0
  43. data/app/views/bs5/examples/modal/_fullscreen.html.erb +2 -0
  44. data/app/views/bs5/examples/modal/_optional_sizes.html.erb +2 -0
  45. data/app/views/bs5/examples/modal/examples/snippet1.html.erb +12 -0
  46. data/app/views/bs5/examples/modal/examples/snippet2.html.erb +12 -0
  47. data/app/views/bs5/examples/modal/examples/snippet3.html.erb +14 -0
  48. data/app/views/bs5/examples/modal/examples/snippet4.html.erb +12 -0
  49. data/app/views/bs5/examples/modal/fullscreen/snippet1.html.erb +55 -0
  50. data/app/views/bs5/examples/modal/optional_sizes/snippet1.html.erb +23 -0
  51. data/app/views/bs5/examples/navs_and_tabs/_base_nav.html.erb +2 -0
  52. data/app/views/bs5/examples/navs_and_tabs/_dropdowns.html.erb +5 -0
  53. data/app/views/bs5/examples/navs_and_tabs/_flex_utils.html.erb +2 -0
  54. data/app/views/bs5/examples/navs_and_tabs/_styles.html.erb +15 -0
  55. data/app/views/bs5/examples/navs_and_tabs/_tabs.html.erb +4 -0
  56. data/app/views/bs5/examples/navs_and_tabs/base_nav/snippet1.html.erb +6 -0
  57. data/app/views/bs5/examples/navs_and_tabs/dropdowns/snippet1.html.erb +14 -0
  58. data/app/views/bs5/examples/navs_and_tabs/dropdowns/snippet2.html.erb +14 -0
  59. data/app/views/bs5/examples/navs_and_tabs/flex_utils/snippet1.html.erb +6 -0
  60. data/app/views/bs5/examples/navs_and_tabs/styles/snippet1.html.erb +6 -0
  61. data/app/views/bs5/examples/navs_and_tabs/styles/snippet2.html.erb +6 -0
  62. data/app/views/bs5/examples/navs_and_tabs/styles/snippet3.html.erb +6 -0
  63. data/app/views/bs5/examples/navs_and_tabs/styles/snippet4.html.erb +6 -0
  64. data/app/views/bs5/examples/navs_and_tabs/styles/snippet5.html.erb +6 -0
  65. data/app/views/bs5/examples/navs_and_tabs/styles/snippet6.html.erb +6 -0
  66. data/app/views/bs5/examples/navs_and_tabs/styles/snippet7.html.erb +6 -0
  67. data/app/views/bs5/examples/navs_and_tabs/styles/snippet8.html.erb +6 -0
  68. data/app/views/bs5/examples/navs_and_tabs/styles/snippet9.html.erb +6 -0
  69. data/app/views/bs5/examples/navs_and_tabs/tabs/snippet1.html.erb +11 -0
  70. data/app/views/bs5/examples/navs_and_tabs/tabs/snippet2.html.erb +11 -0
  71. data/app/views/bs5/examples/navs_and_tabs/tabs/snippet3.html.erb +11 -0
  72. data/app/views/bs5/examples/progress/_animated.html.erb +2 -0
  73. data/app/views/bs5/examples/progress/_backgrounds.html.erb +2 -0
  74. data/app/views/bs5/examples/progress/_examples.html.erb +2 -0
  75. data/app/views/bs5/examples/progress/_labels.html.erb +2 -0
  76. data/app/views/bs5/examples/progress/_multiple_bars.html.erb +2 -0
  77. data/app/views/bs5/examples/progress/_striped.html.erb +2 -0
  78. data/app/views/bs5/examples/progress/animated/snippet1.html.erb +13 -0
  79. data/app/views/bs5/examples/progress/backgrounds/snippet1.html.erb +13 -0
  80. data/app/views/bs5/examples/progress/examples/snippet1.html.erb +17 -0
  81. data/app/views/bs5/examples/progress/labels/snippet1.html.erb +5 -0
  82. data/app/views/bs5/examples/progress/multiple_bars/snippet1.html.erb +5 -0
  83. data/app/views/bs5/examples/progress/striped/snippet1.html.erb +13 -0
  84. data/app/views/bs5/pages/carousel.html.erb +3 -0
  85. data/app/views/bs5/pages/modal.html.erb +4 -0
  86. data/app/views/bs5/pages/navs_and_tabs.html.erb +6 -0
  87. data/app/views/bs5/pages/progress.html.erb +7 -0
  88. data/app/views/layouts/bs5/pages.html.erb +4 -0
  89. data/lib/bs5/version.rb +1 -1
  90. metadata +95 -16
@@ -0,0 +1,7 @@
1
+ <% if items.any? %>
2
+ <nav class="<%= component_class %>">
3
+ <% items.each do |item| %>
4
+ <%= item %>
5
+ <% end %>
6
+ </nav>
7
+ <% end %>
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class NavComponent < ViewComponent::Base
5
+ include ViewComponent::SlotableV2
6
+
7
+ renders_many :items, Bs5::Nav::ItemComponent
8
+
9
+ def initialize(options = {})
10
+ @options = options.symbolize_keys
11
+ extract_options
12
+ end
13
+
14
+ private
15
+
16
+ def extract_options
17
+ @style = @options.delete(:style)
18
+ @space = @options.delete(:space)
19
+ end
20
+
21
+ def component_class
22
+ class_names = Array(@options[:class])
23
+ class_names << ['nav']
24
+ class_names << style_class
25
+ class_names << space_class
26
+ class_names.join(' ')
27
+ end
28
+
29
+ def style_class
30
+ return unless style?
31
+
32
+ ["nav-#{@style}"]
33
+ end
34
+
35
+ def space_class
36
+ return unless space?
37
+
38
+ ["nav-#{@space}"]
39
+ end
40
+
41
+ %i[style space].each do |name|
42
+ define_method("#{name}?") do
43
+ !!instance_variable_get("@#{name}")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1 @@
1
+ <div class="<%= bar_class %>" role="progressbar" style="width: <%= value %>%" aria-valuenow="<%= value %>" aria-valuemin="0" aria-valuemax="100"><%= label %></div>
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ module Progress
5
+ class BarComponent < ViewComponent::Base
6
+ attr_reader :value, :color
7
+
8
+ def initialize(value, label: nil, color: nil, striped: false, animated: false)
9
+ @value = value
10
+ @label = label
11
+ @color = color
12
+ @striped = striped
13
+ @animated = animated
14
+ end
15
+
16
+ def label
17
+ return unless @label
18
+
19
+ case @label
20
+ when String
21
+ @label
22
+ else
23
+ "#{value}%"
24
+ end
25
+ end
26
+
27
+ def bar_class
28
+ class_names = %w[progress-bar]
29
+ class_names << contextual_class
30
+ class_names << striped_class
31
+ class_names << animated_class
32
+ class_names.flatten.uniq.join(' ')
33
+ end
34
+
35
+ def contextual_class
36
+ return unless color?
37
+
38
+ "bg-#{color}"
39
+ end
40
+
41
+ def striped_class
42
+ return unless striped?
43
+
44
+ 'progress-bar-striped'
45
+ end
46
+
47
+ def animated_class
48
+ return unless animated?
49
+
50
+ %w[progress-bar-striped progress-bar-animated]
51
+ end
52
+
53
+ %i[color striped animated].each do |name|
54
+ define_method("#{name}?") do
55
+ !!instance_variable_get("@#{name}")
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ <div class="progress">
2
+ <% if bars.any? %>
3
+ <% bars.each do |bar| %>
4
+ <%= bar %>
5
+ <% end %>
6
+ <% else %>
7
+ <%= render Bs5::Progress::BarComponent.new(value, options) %>
8
+ <% end %>
9
+ </div>
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class ProgressComponent < ViewComponent::Base
5
+ include ViewComponent::SlotableV2
6
+ renders_many :bars, Bs5::Progress::BarComponent
7
+
8
+ attr_reader :value, :options
9
+
10
+ def initialize(value = nil, options = {})
11
+ @options = options.symbolize_keys
12
+ @value = value
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ <div class="<%= component_class %>" id="<%= pane_id %>" role="tabpanel" aria-labelledby="<%= tab_id %>">
2
+ <%= content %>
3
+ </div>
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ module Tabs
5
+ class ItemComponent < ViewComponent::Base
6
+ attr_reader :title, :options
7
+ attr_accessor :style
8
+
9
+ def initialize(title, options = {})
10
+ @title = title
11
+ @options = options.symbolize_keys
12
+ extract_options
13
+ end
14
+
15
+ def tab_id
16
+ "nav-#{object_id}-tab"
17
+ end
18
+
19
+ def pane_id
20
+ "nav-#{object_id}"
21
+ end
22
+
23
+ %i[active].each do |name|
24
+ define_method("#{name}?") do
25
+ !!instance_variable_get("@#{name}")
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def extract_options
32
+ @active = @options.delete(:active)
33
+ end
34
+
35
+ def component_class
36
+ class_names = %w[tab-pane fade]
37
+ class_names << active_class
38
+ class_names.join(' ')
39
+ end
40
+
41
+ def active_class
42
+ return unless active?
43
+
44
+ %w[show active]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ <%= link_to item.title, "##{item.pane_id}", class: component_class, id: item.tab_id, role: :tab, data: { bs_toggle: item.style }, aria: { controls: item.pane_id, selected: item.active? } %>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ module Tabs
5
+ class LinkComponent < ViewComponent::Base
6
+ attr_reader :item
7
+
8
+ def initialize(item)
9
+ @item = item
10
+ end
11
+
12
+ def component_class
13
+ class_names = ['nav-link']
14
+
15
+ class_names << active_class
16
+
17
+ class_names.compact.join(' ')
18
+ end
19
+
20
+ def active_class
21
+ return unless item.active?
22
+
23
+ %w[active]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ <% if items.any? %>
2
+ <%= vertical_container do %>
3
+ <nav>
4
+ <div class="<%= tablist_class %>" role="tablist">
5
+ <% items.each do |item| %>
6
+ <%= render Bs5::Tabs::LinkComponent.new(item) %>
7
+ <% end %>
8
+ </div>
9
+ </nav>
10
+ <div class="tab-content">
11
+ <% items.each do |item| %>
12
+ <%= item %>
13
+ <% end %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class TabsComponent < ViewComponent::Base
5
+ include ViewComponent::SlotableV2
6
+
7
+ renders_many :items, Bs5::Tabs::ItemComponent
8
+
9
+ def initialize(options = {})
10
+ @options = options.symbolize_keys
11
+ extract_options
12
+ end
13
+
14
+ def before_render
15
+ items.each { |item| item.style = item_style }
16
+ end
17
+
18
+ private
19
+
20
+ def extract_options
21
+ @style = @options.delete(:style) || :pills
22
+ @vertical = @options.delete(:vertical)
23
+ end
24
+
25
+ def vertical_container(&block)
26
+ if vertical?
27
+ tag.div(class: 'd-flex align-items-start') do
28
+ capture(&block)
29
+ end
30
+ else
31
+ capture(&block)
32
+ end
33
+ end
34
+
35
+ def tablist_class
36
+ class_names = Array(@options[:class])
37
+ class_names << %w[nav]
38
+ class_names << style_class
39
+ class_names << vertical_class
40
+ class_names.join(' ')
41
+ end
42
+
43
+ def style_class
44
+ ["nav-#{@style}"]
45
+ end
46
+
47
+ def vertical_class
48
+ return unless vertical?
49
+
50
+ ['flex-column']
51
+ end
52
+
53
+ %i[vertical].each do |name|
54
+ define_method("#{name}?") do
55
+ !!instance_variable_get("@#{name}")
56
+ end
57
+ end
58
+
59
+ def item_style
60
+ @style.to_s.singularize
61
+ end
62
+ end
63
+ end
@@ -2,12 +2,15 @@
2
2
 
3
3
  module Bs5
4
4
  module ComponentsHelper
5
- COMPONENTS = %w[accordion alert badge breadcrumb button_group button_tag button_to button_toolbar close_button
6
- dropdown list_group spinner toast toast_container].freeze
5
+ COMPONENTS = %w[accordion alert badge breadcrumb button_group button_tag button_to button_toolbar
6
+ carousel close_button
7
+ dropdown list_group modal nav spinner
8
+ progress
9
+ tabs toast toast_container].freeze
7
10
 
8
11
  COMPONENTS.each do |name|
9
12
  define_method("bs5_#{name}") do |*args, &block|
10
- clazz = "Bs5::#{name.classify}Component".constantize
13
+ clazz = "Bs5::#{name.camelize}Component".constantize
11
14
  render_component(clazz, *args, &block)
12
15
  end
13
16
  end
@@ -0,0 +1,2 @@
1
+ <h2>Dark variant</h2>
2
+ <%= bs5_example(snippet: 'carousel/dark_variant/snippet1') %>
@@ -0,0 +1,13 @@
1
+ <h2>Examples</h2>
2
+ <h3>Slides only</h3>
3
+ <%= bs5_example(snippet: 'carousel/examples/snippet1') %>
4
+ <h3>With controls</h3>
5
+ <%= bs5_example(snippet: 'carousel/examples/snippet2') %>
6
+ <h3>With indicators</h3>
7
+ <%= bs5_example(snippet: 'carousel/examples/snippet3') %>
8
+ <h3>With captions</h3>
9
+ <%= bs5_example(snippet: 'carousel/examples/snippet4') %>
10
+ <h3>Crossfade</h3>
11
+ <%= bs5_example(snippet: 'carousel/examples/snippet5') %>
12
+ <h3>Individual <code>.carousel-item</code> interval</h3>
13
+ <%= bs5_example(snippet: 'carousel/examples/snippet6') %>
@@ -0,0 +1,25 @@
1
+ <%= bs5_carousel(controls: true, indicators: true, dark: true) do |c| %>
2
+ <% c.item do |i| %>
3
+ <%= image_tag 'https://picsum.photos/id/131/800/400?grayscale' %>
4
+ <%= i.caption do %>
5
+ <h5>First slide label</h5>
6
+ <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <% c.item do |i| %>
11
+ <%= image_tag 'https://picsum.photos/id/383/800/400?grayscale' %>
12
+ <%= i.caption do %>
13
+ <h5>Second slide label</h5>
14
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
15
+ <% end %>
16
+ <% end %>
17
+
18
+ <% c.item do |i| %>
19
+ <%= image_tag 'https://picsum.photos/id/130/800/400' %>
20
+ <%= i.caption do %>
21
+ <h5>Third slide label</h5>
22
+ <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
23
+ <% end %>
24
+ <% end %>
25
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= bs5_carousel do |c| %>
2
+ <% c.item do %>
3
+ <%= image_tag 'https://picsum.photos/800/400?random=1' %>
4
+ <% end %>
5
+
6
+ <% c.item do %>
7
+ <%= image_tag 'https://picsum.photos/800/400?random=2' %>
8
+ <% end %>
9
+
10
+ <% c.item do %>
11
+ <%= image_tag 'https://picsum.photos/800/400?random=3' %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= bs5_carousel(controls: true) do |c| %>
2
+ <% c.item do %>
3
+ <%= image_tag 'https://picsum.photos/800/400?random=1' %>
4
+ <% end %>
5
+
6
+ <% c.item do %>
7
+ <%= image_tag 'https://picsum.photos/800/400?random=2' %>
8
+ <% end %>
9
+
10
+ <% c.item do %>
11
+ <%= image_tag 'https://picsum.photos/800/400?random=3' %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= bs5_carousel(controls: true, indicators: true) do |c| %>
2
+ <% c.item do %>
3
+ <%= image_tag 'https://picsum.photos/800/400?random=1' %>
4
+ <% end %>
5
+
6
+ <% c.item do %>
7
+ <%= image_tag 'https://picsum.photos/800/400?random=2' %>
8
+ <% end %>
9
+
10
+ <% c.item do %>
11
+ <%= image_tag 'https://picsum.photos/800/400?random=3' %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <%= bs5_carousel(controls: true, indicators: true) do |c| %>
2
+ <% c.item do |i| %>
3
+ <%= image_tag 'https://picsum.photos/id/1042/800/400?blur=2' %>
4
+ <%= i.caption do %>
5
+ <h5>First slide label</h5>
6
+ <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <% c.item do |i| %>
11
+ <%= image_tag 'https://picsum.photos/id/195/800/400?blur=2' %>
12
+ <%= i.caption do %>
13
+ <h5>Second slide label</h5>
14
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
15
+ <% end %>
16
+ <% end %>
17
+
18
+ <% c.item do |i| %>
19
+ <%= image_tag 'https://picsum.photos/id/960/800/400?blur=2' %>
20
+ <%= i.caption do %>
21
+ <h5>Third slide label</h5>
22
+ <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
23
+ <% end %>
24
+ <% end %>
25
+ <% end %>