bootstrap4_rails_components 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows components to supply the dropDIRECTION for menus
7
+ # This is applicable to more than just the Dropdown component
8
+ module DropdownDirectionable
9
+ def dropleft
10
+ options.fetch(:dropleft, false)
11
+ end
12
+
13
+ def dropright
14
+ options.fetch(:dropright, false)
15
+ end
16
+
17
+ def dropup
18
+ options.fetch(:dropup, false)
19
+ end
20
+
21
+ private
22
+
23
+ def css_classes
24
+ [
25
+ super,
26
+ ('dropleft' if dropleft),
27
+ ('dropright' if dropright),
28
+ ('dropup' if dropup)
29
+ ].join(' ').squish
30
+ end
31
+
32
+ def non_html_attribute_options
33
+ super.push(:dropleft,
34
+ :dropright,
35
+ :dropup)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
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 Headable
8
+ def heading
9
+ options.fetch(:heading, nil)
10
+ end
11
+
12
+ private
13
+
14
+ def non_html_attribute_options
15
+ super.push(:heading)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows a component to utilize the :modal option
7
+ # Which then formats the component's HTML data attributes
8
+ # to connect to the desired modal. Note the :modal option requires the '#'
9
+ # preceding the CSS ID per bootstrap docs
10
+ #
11
+ # Correct: { modal: '#the_modal_id' } <-- note the '#'
12
+ # Incorrect: { modal: 'the_modal_id' }
13
+ #
14
+ # USAGE:
15
+ # When to use the :modal option on a component:
16
+ # The :modal option should only be used when activating a modal
17
+ # that has been embedded on the HTML page and is not being injected
18
+ # from a remote ajax request via remote: true.
19
+ #
20
+ # INVALID USAGE:
21
+ # Do not set a modal option on a remote link in Rails
22
+ # Setting a component to remote: true in addition to suppling a modal
23
+ # will result in an ArgumentError. This is due to poor / buggy behavior resulting from
24
+ # remotely re-rendering a modal that is already on the page
25
+ #
26
+ # (basically: there's a high likelihood that the targeted modal will
27
+ # be shown / animated twice)
28
+ #
29
+ # Like when remote: true, components that contain tooltips
30
+ # Will also raise an ArgumentError due to the competing data-toggles
31
+ # and the subsequent silent failure of the tooltip.
32
+ #
33
+ # EXCEPTIONS:
34
+ # Exception for a modalable component with a tooltip:
35
+ # *Disabled* components may use a modal and a tooltip in its options
36
+ # (thanks to how disabled components are wrapped with an html element & the tooltip
37
+ # is applied to the wrapping element, not the component itself)
38
+ #
39
+ # Valid example:
40
+ # = ui.bootstrap :button, disabled: true, tooltip: 'The tooltip', modal: '#the_modal', ...
41
+ #
42
+ # Extra care is taken with the modal and competing options given its typical wide-ranging
43
+ # use in rails applications.
44
+ module Modalable
45
+ def data
46
+ # Raise an error when a component utilizes 'illegal' options (which are options that
47
+ # result in silent failures and/or directly compete with a
48
+ # modalable component's necessary HTML)
49
+ if component_includes_problematic_options_for_modal?
50
+ raise ArgumentError.new(I18n.t("bootstrap4_rails_components.errors.argument_error.modalable.#{error_message_i18n_path}",
51
+ modal: modal,
52
+ class_name: self.class.name,
53
+ options: options,
54
+ file: __FILE__,
55
+ method: __method__))
56
+ end
57
+
58
+ # Overwrites data-toggle and data-target
59
+ # forcing the modal to take precedence.
60
+ # If a tooltip is present in the options, an ArgumentError is raised
61
+ modal ? super.merge!(toggle: 'modal', target: options[:modal]) : super
62
+ end
63
+
64
+ def modal
65
+ options.fetch(:modal, nil)
66
+ end
67
+
68
+ private
69
+
70
+ # Corresponds to i18n locale: config/locales/en.yml
71
+ # Remote is checked first, given its importance and impact on the application
72
+ # Then, check for tooltip.
73
+ def error_message_i18n_path
74
+ return 'remote' if options[:remote]
75
+ return 'tooltip' if options[:tooltip]
76
+ end
77
+
78
+ # Force an error when:
79
+ # 1. The component includes remote: true (and the modal option is present)
80
+ # 2. The component includes a :tooltip in the options
81
+ #
82
+ # When a tooltip is present, the data-toggle would be overwritten with
83
+ # the modal data attributes (given the `data.merge!`) causing a silent failure
84
+ # of the tooltip (it doesn't get added to the component)
85
+ #
86
+ # Exception: when tooltip is not "illegal" (the component has a tooltip *and* is disabled)
87
+ def component_includes_problematic_options_for_modal?
88
+ modal.present? && (options.fetch(:remote, nil) || illegal_tooltip?)
89
+ end
90
+
91
+ # When a modalable component is disabled
92
+ # the tooltip is applied to a wrapping element
93
+ # and will not compete with the modal's data attributes.
94
+ def illegal_tooltip?
95
+ options[:tooltip].present? && !options[:disabled]
96
+ end
97
+
98
+ def non_html_attribute_options
99
+ super.push(:modal)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Shared methods between Progress & ProgressBar.
7
+ module Progressable
8
+ def animated
9
+ options.fetch(:animated, false)
10
+ end
11
+
12
+ def label
13
+ # options.fetch(:label, nil)
14
+ options[:label] == true ? "#{progress}%" : options[:label] || body
15
+ end
16
+
17
+ def progress
18
+ options[:progress] || 0
19
+ end
20
+
21
+ def striped
22
+ options.fetch(:striped, false)
23
+ end
24
+
25
+ def theme
26
+ options.fetch(:theme, nil)
27
+ end
28
+
29
+ private
30
+
31
+ def non_html_attribute_options
32
+ super.push(:animated,
33
+ :height,
34
+ :label,
35
+ :progress,
36
+ :striped,
37
+ :theme)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Turns remote: true functionality on for components that need it.
7
+ module Remotable
8
+ def data
9
+ remote ? super.merge!(remote: remote.to_s) : super
10
+ end
11
+
12
+ def remote
13
+ options.fetch(:remote, nil)
14
+ end
15
+
16
+ private
17
+
18
+ def non_html_attribute_options
19
+ super.push(:remote)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Applies ability to modify the component's size
7
+ # Pass in :lg or :sm
8
+ module Sizable
9
+ def size
10
+ options.fetch(:size, nil)
11
+ end
12
+
13
+ private
14
+
15
+ def css_classes
16
+ [
17
+ super,
18
+ (size_css_class if resized?)
19
+ ].join(' ').squish
20
+ end
21
+
22
+ def non_html_attribute_options
23
+ super.push(:size)
24
+ end
25
+
26
+ def resized?
27
+ size == :sm || size == :lg
28
+ end
29
+
30
+ def size_css_class
31
+ "#{size_css_class_prefix}-#{size}"
32
+ end
33
+
34
+ def size_css_class_prefix
35
+ @size_css_class_prefix ||= component_css_class
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows component to utilize the bootstrap4 theme color palette
7
+ module Themeable
8
+ def outlined
9
+ options.fetch(:outlined, false)
10
+ end
11
+
12
+ # To disable theme on a case by case basis, pass in { theme: nil } to options.
13
+ # or
14
+ # To disable a default theme for a component set default_theme to nil
15
+ def theme
16
+ options.fetch(:theme, default_theme)
17
+ end
18
+
19
+ private
20
+
21
+ def css_classes
22
+ [
23
+ super,
24
+ ("#{theme_css_class_prefix}#{outlined_css_class_prefix if outlined && outlineable?}#{theme}" if theme)
25
+ ].join(' ').squish
26
+ end
27
+
28
+ def default_theme
29
+ @default_theme ||= Bootstrap4RailsComponents::DEFAULT_BOOTSTRAP_THEME
30
+ end
31
+
32
+ def non_html_attribute_options
33
+ super.push(:theme, :outlined)
34
+ end
35
+
36
+ def outlined_css_class_prefix
37
+ @outlined_css_class_prefix ||= 'outline-'
38
+ end
39
+
40
+ def theme_css_class_prefix
41
+ @theme_css_class_prefix ||= "#{component_css_class}-"
42
+ end
43
+
44
+ # Explicitly turn off outlineable on components that should not allow outline
45
+ def outlineable?
46
+ true
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Allows NFG design system components to utilize the :title option
7
+ module Titleable
8
+ def title
9
+ options.fetch(:title, nil)
10
+ end
11
+
12
+ private
13
+
14
+ def non_html_attribute_options
15
+ super.push(:title)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootstrap4RailsComponents
4
+ module Bootstrap
5
+ module Utilities
6
+ # Tooltip doc coming soon
7
+ #
8
+ # Bootstrap documentation
9
+ # https://getbootstrap.com/docs/4.1/components/tooltips/
10
+ #
11
+ # Allows tooltips to be placed on any component's main wrapping element
12
+ #
13
+ # When tooltip is applied to a disabled component (via the tooltip argument)
14
+ # the component will return the necessary information to build a wrapper div
15
+ # due to the non-interactable nature of the disabled elements.
16
+ #
17
+ # Example implementation of a button in HAML:
18
+ #
19
+ # - if button.disabled_tooltipable?
20
+ # %span{ button.disabled_component_tooltip_wrapper_html_options }
21
+ # = content_tag button.html_wrapper_element, button.html_options do
22
+ # = button.body
23
+
24
+ # - else
25
+ # = content_tag button.html_wrapper_element, button.html_options do
26
+ # = button.body
27
+ #
28
+ # Tooltip placement:
29
+ # You can override the placement if needed by setting the tooltip_placement method
30
+ # in your target class -- :top, :bottom, :left, :right
31
+ #
32
+ # Example:
33
+ #
34
+ # def tooltip_placement
35
+ # :right
36
+ # end
37
+ module Tooltipable
38
+ # TODO: This include should be removed and then anything with Tooltipable
39
+ # needs to be evaluated that this doesn't break it.
40
+ # It is undesirable that every Tooltipable component also received
41
+ # the disableable functionality as well.
42
+ include Bootstrap::Utilities::Disableable
43
+
44
+ def tooltip
45
+ options.fetch(:tooltip, nil)
46
+ end
47
+
48
+ # There are a number of complex changes that need to be made to the html
49
+ # for disabled tooltipped buttons
50
+ # Read more:
51
+ #
52
+ # https://getbootstrap.com/docs/4.1/components/tooltips/#disabled-elements
53
+ def html_options
54
+ return super if options[:tooltip].nil?
55
+
56
+ component_title = disabled ? options.fetch(:title, nil) : tooltip
57
+ component_styles = (options[:style] || '') + (disabled ? ' pointer-events: none;' : '') if disabled
58
+ super.merge!(title: component_title,
59
+ style: component_styles.try(:squish))
60
+ end
61
+
62
+ def data
63
+ if tooltip
64
+ disabled ? super : super.merge!(tooltip_data_attributes)
65
+ else
66
+ super
67
+ end
68
+ end
69
+
70
+ def disabled_component_tooltip_wrapper_html_options
71
+ { data: tooltip_data_attributes,
72
+ title: tooltip,
73
+ class: 'd-inline-block',
74
+ tabindex: '0' }
75
+ end
76
+
77
+ private
78
+
79
+ def tooltip_data_attributes
80
+ { toggle: 'tooltip',
81
+ placement: tooltip_placement,
82
+ html: 'true' }
83
+ end
84
+
85
+ def non_html_attribute_options
86
+ super.push(:tooltip)
87
+ end
88
+
89
+ def tooltip_placement
90
+ @tooltip_placement ||= :top
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end