bootstrap4_rails_components 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +362 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/config/bootstrap4_rails_components_manifest.js +3 -0
  6. data/app/assets/javascripts/bootstrap4_rails_components/application.js +8 -0
  7. data/app/assets/javascripts/bootstrap4_rails_components/vendor/tooltips.js +42 -0
  8. data/app/assets/stylesheets/bootstrap4_rails_components/bootstrap/application.scss +2 -0
  9. data/app/controllers/bootstrap4_rails_components/application_controller.rb +5 -0
  10. data/app/helpers/bootstrap4_rails_components/application_helper.rb +38 -0
  11. data/app/models/bootstrap4_rails_components/application_record.rb +5 -0
  12. data/config/initializers/web_app_manifest.rb +3 -0
  13. data/config/locales/en.yml +63 -0
  14. data/config/routes.rb +2 -0
  15. data/config/spring.rb +1 -0
  16. data/lib/bootstrap4_rails_components.rb +75 -0
  17. data/lib/bootstrap4_rails_components/bootstrap/components/alert.rb +52 -0
  18. data/lib/bootstrap4_rails_components/bootstrap/components/badge.rb +39 -0
  19. data/lib/bootstrap4_rails_components/bootstrap/components/base.rb +151 -0
  20. data/lib/bootstrap4_rails_components/bootstrap/components/breadcrumb.rb +23 -0
  21. data/lib/bootstrap4_rails_components/bootstrap/components/breadcrumb_item.rb +28 -0
  22. data/lib/bootstrap4_rails_components/bootstrap/components/button.rb +74 -0
  23. data/lib/bootstrap4_rails_components/bootstrap/components/button_group.rb +36 -0
  24. data/lib/bootstrap4_rails_components/bootstrap/components/button_toolbar.rb +21 -0
  25. data/lib/bootstrap4_rails_components/bootstrap/components/card.rb +81 -0
  26. data/lib/bootstrap4_rails_components/bootstrap/components/card_body.rb +15 -0
  27. data/lib/bootstrap4_rails_components/bootstrap/components/card_footer.rb +15 -0
  28. data/lib/bootstrap4_rails_components/bootstrap/components/card_header.rb +35 -0
  29. data/lib/bootstrap4_rails_components/bootstrap/components/card_image.rb +33 -0
  30. data/lib/bootstrap4_rails_components/bootstrap/components/card_image_overlay.rb +46 -0
  31. data/lib/bootstrap4_rails_components/bootstrap/components/carousel.rb +57 -0
  32. data/lib/bootstrap4_rails_components/bootstrap/components/carousel_caption.rb +34 -0
  33. data/lib/bootstrap4_rails_components/bootstrap/components/carousel_control.rb +73 -0
  34. data/lib/bootstrap4_rails_components/bootstrap/components/carousel_indicators.rb +54 -0
  35. data/lib/bootstrap4_rails_components/bootstrap/components/carousel_item.rb +49 -0
  36. data/lib/bootstrap4_rails_components/bootstrap/components/collapse.rb +32 -0
  37. data/lib/bootstrap4_rails_components/bootstrap/components/dropdown.rb +51 -0
  38. data/lib/bootstrap4_rails_components/bootstrap/components/dropdown_divider.rb +19 -0
  39. data/lib/bootstrap4_rails_components/bootstrap/components/dropdown_header.rb +23 -0
  40. data/lib/bootstrap4_rails_components/bootstrap/components/dropdown_item.rb +41 -0
  41. data/lib/bootstrap4_rails_components/bootstrap/components/dropdown_menu.rb +32 -0
  42. data/lib/bootstrap4_rails_components/bootstrap/components/dropdown_toggle.rb +82 -0
  43. data/lib/bootstrap4_rails_components/bootstrap/components/embed.rb +80 -0
  44. data/lib/bootstrap4_rails_components/bootstrap/components/form.rb +13 -0
  45. data/lib/bootstrap4_rails_components/bootstrap/components/input_group.rb +13 -0
  46. data/lib/bootstrap4_rails_components/bootstrap/components/jumbotron.rb +13 -0
  47. data/lib/bootstrap4_rails_components/bootstrap/components/list_group.rb +39 -0
  48. data/lib/bootstrap4_rails_components/bootstrap/components/list_group_item.rb +69 -0
  49. data/lib/bootstrap4_rails_components/bootstrap/components/media.rb +15 -0
  50. data/lib/bootstrap4_rails_components/bootstrap/components/media_body.rb +15 -0
  51. data/lib/bootstrap4_rails_components/bootstrap/components/media_object.rb +23 -0
  52. data/lib/bootstrap4_rails_components/bootstrap/components/modal.rb +66 -0
  53. data/lib/bootstrap4_rails_components/bootstrap/components/modal_body.rb +16 -0
  54. data/lib/bootstrap4_rails_components/bootstrap/components/modal_footer.rb +16 -0
  55. data/lib/bootstrap4_rails_components/bootstrap/components/modal_header.rb +37 -0
  56. data/lib/bootstrap4_rails_components/bootstrap/components/nav.rb +71 -0
  57. data/lib/bootstrap4_rails_components/bootstrap/components/nav_item.rb +103 -0
  58. data/lib/bootstrap4_rails_components/bootstrap/components/nav_link.rb +62 -0
  59. data/lib/bootstrap4_rails_components/bootstrap/components/navbar.rb +97 -0
  60. data/lib/bootstrap4_rails_components/bootstrap/components/navbar_brand.rb +25 -0
  61. data/lib/bootstrap4_rails_components/bootstrap/components/navbar_nav.rb +48 -0
  62. data/lib/bootstrap4_rails_components/bootstrap/components/navbar_text.rb +21 -0
  63. data/lib/bootstrap4_rails_components/bootstrap/components/navbar_toggler.rb +38 -0
  64. data/lib/bootstrap4_rails_components/bootstrap/components/page_item.rb +66 -0
  65. data/lib/bootstrap4_rails_components/bootstrap/components/pagination.rb +30 -0
  66. data/lib/bootstrap4_rails_components/bootstrap/components/popover.rb +12 -0
  67. data/lib/bootstrap4_rails_components/bootstrap/components/progress.rb +44 -0
  68. data/lib/bootstrap4_rails_components/bootstrap/components/progress_bar.rb +51 -0
  69. data/lib/bootstrap4_rails_components/bootstrap/components/tab_content.rb +15 -0
  70. data/lib/bootstrap4_rails_components/bootstrap/components/tab_pane.rb +49 -0
  71. data/lib/bootstrap4_rails_components/bootstrap/components/table.rb +17 -0
  72. data/lib/bootstrap4_rails_components/bootstrap/readme.md +1 -0
  73. data/lib/bootstrap4_rails_components/bootstrap/utilities/activatable.rb +32 -0
  74. data/lib/bootstrap4_rails_components/bootstrap/utilities/alignable.rb +33 -0
  75. data/lib/bootstrap4_rails_components/bootstrap/utilities/collapse_toggleable.rb +35 -0
  76. data/lib/bootstrap4_rails_components/bootstrap/utilities/collapsible.rb +42 -0
  77. data/lib/bootstrap4_rails_components/bootstrap/utilities/disableable.rb +49 -0
  78. data/lib/bootstrap4_rails_components/bootstrap/utilities/dismissible.rb +24 -0
  79. data/lib/bootstrap4_rails_components/bootstrap/utilities/dropdown_directionable.rb +40 -0
  80. data/lib/bootstrap4_rails_components/bootstrap/utilities/headable.rb +20 -0
  81. data/lib/bootstrap4_rails_components/bootstrap/utilities/modalable.rb +104 -0
  82. data/lib/bootstrap4_rails_components/bootstrap/utilities/progressable.rb +42 -0
  83. data/lib/bootstrap4_rails_components/bootstrap/utilities/remotable.rb +24 -0
  84. data/lib/bootstrap4_rails_components/bootstrap/utilities/sizable.rb +40 -0
  85. data/lib/bootstrap4_rails_components/bootstrap/utilities/themeable.rb +51 -0
  86. data/lib/bootstrap4_rails_components/bootstrap/utilities/titleable.rb +20 -0
  87. data/lib/bootstrap4_rails_components/bootstrap/utilities/tooltipable.rb +95 -0
  88. data/lib/bootstrap4_rails_components/bootstrap/utilities/wrappable.rb +48 -0
  89. data/lib/bootstrap4_rails_components/engine.rb +38 -0
  90. data/lib/bootstrap4_rails_components/ui/base.rb +42 -0
  91. data/lib/bootstrap4_rails_components/ui/bootstrap.rb +44 -0
  92. data/lib/bootstrap4_rails_components/ui/utilities.rb +10 -0
  93. data/lib/bootstrap4_rails_components/ui/utilities/initializer.rb +88 -0
  94. data/lib/bootstrap4_rails_components/version.rb +5 -0
  95. metadata +372 -0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Pagination Component
7
+ # https://getbootstrap.com/docs/4.1/components/pagination/
8
+ class Pagination < Bootstrap4RailsComponents::Bootstrap::Components::Base
9
+ include Bootstrap::Utilities::Alignable
10
+ include Bootstrap::Utilities::Sizable
11
+
12
+ def component_family
13
+ :pagination
14
+ end
15
+
16
+ def render
17
+ content_tag(:nav) do
18
+ super
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def base_element
25
+ :ul
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Popover Component
7
+ # https://getbootstrap.com/docs/4.1/components/popovers/
8
+ class Popover < Bootstrap4RailsComponents::Bootstrap::Components::Base
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Parent Progress Component
7
+ # https://getbootstrap.com/docs/4.1/components/progress/
8
+ class Progress < Bootstrap4RailsComponents::Bootstrap::Components::Base
9
+ include Bootstrap::Utilities::Progressable
10
+
11
+ def component_family
12
+ :progress
13
+ end
14
+
15
+ def height
16
+ options.fetch(:height, nil)
17
+ end
18
+
19
+ def style
20
+ [
21
+ super,
22
+ ("height: #{height}px;" if height)
23
+ ].join(' ').squish
24
+ end
25
+
26
+ def render
27
+ super do
28
+ if body
29
+ (block_given? ? yield : body)
30
+ else
31
+ Bootstrap4RailsComponents::Bootstrap::Components::ProgressBar.new({ theme: theme, label: label, progress: progress, striped: striped, animated: animated }, view_context).render
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def non_html_attribute_options
39
+ super.push(:height)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Progress Bar Component
7
+ # https://getbootstrap.com/docs/4.1/components/progress/
8
+ class ProgressBar < Bootstrap4RailsComponents::Bootstrap::Components::Progress
9
+ include Bootstrap::Utilities::Progressable
10
+ include Bootstrap::Utilities::Themeable
11
+
12
+ def component_family
13
+ :progress
14
+ end
15
+
16
+ def style
17
+ [
18
+ options[:style],
19
+ ("width: #{progress.to_i}%;" if progress)
20
+ ].join(' ').squish
21
+ end
22
+
23
+ def render
24
+ content_tag(:div, label, html_options)
25
+ end
26
+
27
+ private
28
+
29
+ def css_classes
30
+ [
31
+ super,
32
+ ("#{component_css_class}-striped" if striped),
33
+ ("#{component_css_class}-animated" if animated)
34
+ ].join(' ').squish
35
+ end
36
+
37
+ def assistive_html_attributes
38
+ super.merge!(role: 'progressbar', aria: { valuenow: progress, valuemin: 0, valuemax: 100 })
39
+ end
40
+
41
+ def theme_css_class_prefix
42
+ 'bg-'
43
+ end
44
+
45
+ def outlineable?
46
+ false
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Progress Component
7
+ # https://getbootstrap.com/docs/4.1/components/progress/
8
+ class TabContent < Bootstrap4RailsComponents::Bootstrap::Components::Base
9
+ def component_family
10
+ :tab
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Progress Component
7
+ # https://getbootstrap.com/docs/4.1/components/progress/
8
+ class TabPane < Bootstrap4RailsComponents::Bootstrap::Components::Base
9
+ include Bootstrap::Utilities::Activatable
10
+
11
+ def component_family
12
+ :tab
13
+ end
14
+
15
+ def tab
16
+ options.fetch(:tab, nil)
17
+ end
18
+
19
+ def id
20
+ tab ? tab.tr('#', '') : super
21
+ end
22
+
23
+ # Fade is turned on by default
24
+ # This should probably be a global setting
25
+ def fade
26
+ options.fetch(:fade, true)
27
+ end
28
+
29
+ private
30
+
31
+ def css_classes
32
+ [
33
+ super,
34
+ ('fade' if fade),
35
+ ('show' if active)
36
+ ].join(' ').squish
37
+ end
38
+
39
+ def non_html_attribute_options
40
+ super.push(:tab)
41
+ end
42
+
43
+ def assistive_html_attributes
44
+ { role: 'tabpanel' }
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Components
6
+ # Bootstrap Table Component
7
+ # https://getbootstrap.com/docs/4.1/content/tables/
8
+ class Table < Bootstrap4RailsComponents::Bootstrap::Components::Base
9
+ private
10
+
11
+ def base_element
12
+ :table
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ Bootstrap4 code will be isolated into its own gem later.
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Passes in necessary attributes to allow a component to have an active state
7
+ module Activatable
8
+
9
+ def active
10
+ options.fetch(:active, default_active)
11
+ end
12
+
13
+ private
14
+
15
+ def css_classes
16
+ [
17
+ super,
18
+ ('active' if active)
19
+ ].join(' ').squish
20
+ end
21
+
22
+ def non_html_attribute_options
23
+ super.push(:active)
24
+ end
25
+
26
+ def default_active
27
+ false
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allow components to be right and center aligned
7
+ module Alignable
8
+ def center
9
+ options.fetch(:center, false)
10
+ end
11
+
12
+ def right
13
+ options.fetch(:right, false)
14
+ end
15
+
16
+ private
17
+
18
+ def css_classes
19
+ [
20
+ super,
21
+ ('justify-content-center' if center),
22
+ ('justify-content-end' if right)
23
+ ].join(' ').squish
24
+ end
25
+
26
+ def non_html_attribute_options
27
+ super.push(:right,
28
+ :center)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows components to have a collapsed state when appropriate
7
+ module CollapseToggleable
8
+ include Bootstrap::Utilities::Collapsible
9
+
10
+ def data
11
+ collapse ? super.merge!(collapse_data_attributes) : super
12
+ end
13
+
14
+ private
15
+
16
+ # Buttons need to be able to to set a target on :buttons
17
+ # and an href on links -- so this attribute is customizable if needed
18
+ def collapse_data_attributes
19
+ @collapse_data_attributes ||= { toggle: 'collapse', target: collapse }
20
+ end
21
+
22
+ # To do: currently collapsible doesn't control the actual collapse
23
+ # As such, there's no way to set aria-expanded on the button / toggle...
24
+ # based on whether or not the collapse component is expanded or not
25
+ #
26
+ # To solve: how to address aria-expanded to accurately reflect the expanded status
27
+ def assistive_html_attributes
28
+ return super unless collapse
29
+ super.merge!(aria: (options[:aria] || {}).merge!(expanded: 'false', controls: collapse.tr('#','')),
30
+ role: 'button')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows components to carry collapse attributes
7
+ # to more easily pass collapse status to a collapsible target
8
+ #
9
+ # Example:
10
+ # Tile & TileHeader both include Collapsible
11
+ # because they both pass collapse attributes to
12
+ # a collapse button within TileHeader
13
+ #
14
+ # They do not, however need a collapse toggle
15
+ # unlike a NavbarToggle / Button, and thus they do not include
16
+ # The CollapseToggleable module
17
+ #
18
+ # CollapseToggleable components have this module included
19
+ # by default via the CollapseToggleable module.
20
+ module Collapsible
21
+ def collapse
22
+ options.fetch(:collapse, nil)
23
+ end
24
+
25
+ def collapsed
26
+ options.fetch(:collapsed, nil)
27
+ end
28
+
29
+ # Collapsible checks if collapse is manually set true or false and thus, collapsible
30
+ def collapsible
31
+ options[:collapsible] || collapse || !collapsed.nil?
32
+ end
33
+
34
+ private
35
+
36
+ def non_html_attribute_options
37
+ super.push(:collapse, :collapsed, :collapsible)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows components to have a disabled state when appropriate
7
+ module Disableable
8
+ attr_reader :as
9
+
10
+ def disabled
11
+ options.fetch(:disabled, false)
12
+ end
13
+
14
+ private
15
+
16
+ def css_classes
17
+ # when the tag does not take a disabled attribute we
18
+ # assigne the disabled class
19
+ [
20
+ super,
21
+ ('disabled' if disabled && !tag_allows_for_disable_attribute?)
22
+ ].join(' ').squish
23
+ end
24
+
25
+ def non_html_attribute_options
26
+ # if tag accepts the disabled attribute
27
+ # push it through, otherwise remove it from the
28
+ # html options. We do this regardless of whether or not
29
+ # disabled was actually set to ensure that those
30
+ # tags that can't take a disabled option never receive it
31
+ tag_allows_for_disable_attribute? ? super : super.push(:disabled)
32
+ end
33
+
34
+ def assistive_html_attributes
35
+ if disabled
36
+ super.merge!(tabindex: '-1',
37
+ **(tag_allows_for_disable_attribute?) ? { disabled: true } : {})
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ def tag_allows_for_disable_attribute?
44
+ [:button, :input, :fieldset, :optgroup, :option, :select, :textarea].include?(as)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Delivers the dismissibility of the component to the HAML partial
7
+ module Dismissible
8
+ def dismissible
9
+ options.fetch(:dismissible, default_dismissible)
10
+ end
11
+
12
+ private
13
+
14
+ def non_html_attribute_options
15
+ super.push(:dismissible)
16
+ end
17
+
18
+ def default_dismissible
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end