bootstrap5_helper 1.0.1 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddd5360c6d7fb29c1cb1eaa28a882785b64ceaa1d39ed460eadef28a101de043
4
- data.tar.gz: 676196ec53f4480ec0855b51a541b686627fb3b95b162059feb98174e5d82525
3
+ metadata.gz: 7ab8982347a3e4e8f5b3f295df1d32c1436c96f6a0e6ed7ebe49be9cb2030acf
4
+ data.tar.gz: 1f0e37c6a736272b748fab3c8c00107d58d232f177d4fcbb812d212085670d6c
5
5
  SHA512:
6
- metadata.gz: fb1af7aa23cb5d2a989612b5ad8a5fa694fff894af7feeab2bb244f78b6395a546fc1bb6315e9b5b316164bfecee9d92042fab45dc8489590384fe9cba6a983a
7
- data.tar.gz: a84bdbb6867e7a7c37e61a627fad0a0ce9f6bc136b45d73f164df130cc31313ec3416b87ff4c1e09fa35983323b999a5b3e245bfff9a1ab0d7c57ad2b0ff7055
6
+ metadata.gz: 81a56bd544a7aaa270adbde0e361e2c1bf206e9e39980eca8ad8af45295a430c2cb1b21d76af32eb320013715ca5545ba99c784f881786e1df967f9a6df1aad8
7
+ data.tar.gz: 5aedd70cae3d0fce44b2457a1be9918b4e8c5cf95440970f6eb1dee8c4abb3be40af7b345a6312b7504f42f958304cf1be833fdde375a1bd21f9888888b1351f
@@ -33,11 +33,23 @@ module Bootstrap5Helper
33
33
 
34
34
  # Builds a header component for the accordion.
35
35
  #
36
- # @param [Hash] opts
36
+ # @overload header(tag, opts)
37
+ # @param [Symbol|String] tag - The HTML element to use.
38
+ # @param [Hash] options
39
+ # @option opts [String] :id
40
+ # @option opts [String] :class
41
+ # @option opts [Hash] :data
42
+ #
43
+ # @overload header(opts)
44
+ # @param [Hash] options
45
+ # @option opts [String] :id
46
+ # @option opts [String] :class
47
+ # @option opts [Hash] :data
48
+ #
37
49
  # @return [String]
38
50
  #
39
- def header(tag_or_options = nil, opts = {}, &block)
40
- tag, args = parse_tag_or_options(tag_or_options, opts)
51
+ def header(*tag_or_options, &block)
52
+ tag, args = parse_tag_or_options(*tag_or_options, {})
41
53
 
42
54
  @header_id = args.fetch(:id, @header_id)
43
55
  klass = args.fetch(:class, '')
@@ -72,6 +84,9 @@ module Bootstrap5Helper
72
84
  # Builds the body component for the accordion.
73
85
  #
74
86
  # @param [Hash] opts
87
+ # @option opts [String] :id
88
+ # @option opts [String] :class
89
+ # @option opts [Hash] :data
75
90
  # @return [String]
76
91
  #
77
92
  def body(opts = {}, &block)
@@ -28,8 +28,8 @@ module Bootstrap5Helper
28
28
  #
29
29
  # @return [Accodion::Item]
30
30
  #
31
- def item(*args, &block)
32
- Accordion::Item.new(self, (@always_open ? nil : @id), *args, &block)
31
+ def item(opts = {}, &block)
32
+ Accordion::Item.new(self, (@always_open ? nil : @id), opts, &block)
33
33
  end
34
34
 
35
35
  # String representation of the object.
@@ -28,7 +28,7 @@ module Bootstrap5Helper
28
28
  #
29
29
  def to_s
30
30
  content_tag(
31
- config(:badges, :span),
31
+ config({ badges: :base }, :span),
32
32
  id: @id,
33
33
  class: container_class,
34
34
  data: @data
@@ -44,10 +44,17 @@ module Bootstrap5Helper
44
44
  # @return [String]
45
45
  #
46
46
  def container_class
47
- string = 'badge '
48
- string += @context == 'secondary' ? 'bg-secondary' : "bg-#{@context}"
49
- string += " #{@class}"
50
- string
47
+ "badge #{component_class} #{@class}"
48
+ end
49
+
50
+ def component_class
51
+ contrast = config({ badges: :contrast }, false)
52
+
53
+ if @context == 'secondary'
54
+ contrast ? 'text-bg-secondary' : 'bg-secondary'
55
+ else
56
+ contrast ? "text-bg-#{@context}" : "bg-#{@context}"
57
+ end
51
58
  end
52
59
  end
53
60
  end
@@ -23,15 +23,23 @@ module Bootstrap5Helper
23
23
 
24
24
  # Builds the Header component.
25
25
  #
26
- # @param [Symbol|Hash|NilClass] tag_or_options
27
- # @param [Hash] opts
28
- # @option opts [String] :id
29
- # @option opts [String] :class
30
- # @option opts [Hash] :data
26
+ # @overload header(tag, opts)
27
+ # @param [Symbol|String] tag - The HTML element to use.
28
+ # @param [Hash] options
29
+ # @option opts [String] :id
30
+ # @option opts [String] :class
31
+ # @option opts [Hash] :data
32
+ #
33
+ # @overload header(opts)
34
+ # @param [Hash] options
35
+ # @option opts [String] :id
36
+ # @option opts [String] :class
37
+ # @option opts [Hash] :data
38
+ #
31
39
  # @return [String]
32
40
  #
33
- def header(tag_or_options = nil, opts = {}, &block)
34
- tag, args = parse_tag_or_options(tag_or_options, opts)
41
+ def header(*tag_or_options, &block)
42
+ tag, args = parse_tag_or_options(*tag_or_options, {})
35
43
  build_base_component(
36
44
  tag || config({ cards: :header }, :h5),
37
45
  :header,
@@ -42,15 +50,23 @@ module Bootstrap5Helper
42
50
 
43
51
  # Builds the Body component.
44
52
  #
45
- # @param [Symbol|Hash|NilClass] tag_or_options
46
- # @param [Hash] opts
47
- # @option opts [String] :id
48
- # @option opts [String] :class
49
- # @option opts [Hash] :data
53
+ # @overload body(tag, opts)
54
+ # @param [Symbol|String] tag - The HTML element to use.
55
+ # @param [Hash] options
56
+ # @option opts [String] :id
57
+ # @option opts [String] :class
58
+ # @option opts [Hash] :data
59
+ #
60
+ # @overload body(opts)
61
+ # @param [Hash] options
62
+ # @option opts [String] :id
63
+ # @option opts [String] :class
64
+ # @option opts [Hash] :data
65
+ #
50
66
  # @return [String]
51
67
  #
52
- def body(tag_or_options = nil, opts = {}, &block)
53
- tag, args = parse_tag_or_options(tag_or_options, opts)
68
+ def body(*tag_or_options, &block)
69
+ tag, args = parse_tag_or_options(*tag_or_options, {})
54
70
  build_base_component(
55
71
  tag || config({ cards: :body }, :div),
56
72
  :body,
@@ -61,15 +77,24 @@ module Bootstrap5Helper
61
77
 
62
78
  # Builds the Footer component.
63
79
  #
64
- # @param [Symbol|Hash|NilClass] tag_or_options
65
- # @param [Hash] opts
66
- # @option opts [String] :id
67
- # @option opts [String] :class
68
- # @option opts [Hash] :data
80
+ #
81
+ # @overload footer(tag, opts)
82
+ # @param [Symbol|String] tag - The HTML element to use.
83
+ # @param [Hash] options
84
+ # @option opts [String] :id
85
+ # @option opts [String] :class
86
+ # @option opts [Hash] :data
87
+ #
88
+ # @overload footer(opts)
89
+ # @param [Hash] options
90
+ # @option opts [String] :id
91
+ # @option opts [String] :class
92
+ # @option opts [Hash] :data
93
+ #
69
94
  # @return [String]
70
95
  #
71
- def footer(tag_or_options = nil, opts = {}, &block)
72
- tag, args = parse_tag_or_options(tag_or_options, opts)
96
+ def footer(*tag_or_options, &block)
97
+ tag, args = parse_tag_or_options(*tag_or_options, {})
73
98
  build_base_component(
74
99
  tag || config({ cards: :footer }, :div),
75
100
  :footer,
@@ -80,15 +105,23 @@ module Bootstrap5Helper
80
105
 
81
106
  # Builds a Title component.
82
107
  #
83
- # @param [Symbol|Hash|NilClass] tag_or_options
84
- # @param [Hash] opts
85
- # @option opts [String] :id
86
- # @option opts [String] :class
87
- # @option opts [Hash] :data
108
+ # @overload title(tag, opts)
109
+ # @param [Symbol|String] tag - The HTML element to use.
110
+ # @param [Hash] options
111
+ # @option opts [String] :id
112
+ # @option opts [String] :class
113
+ # @option opts [Hash] :data
114
+ #
115
+ # @overload title(opts)
116
+ # @param [Hash] options
117
+ # @option opts [String] :id
118
+ # @option opts [String] :class
119
+ # @option opts [Hash] :data
120
+ #
88
121
  # @return [String]
89
122
  #
90
- def title(tag_or_options = nil, opts = {}, &block)
91
- tag, args = parse_tag_or_options(tag_or_options, opts)
123
+ def title(*tag_or_options, &block)
124
+ tag, args = parse_tag_or_options(*tag_or_options, {})
92
125
  build_sub_component(
93
126
  tag || config({ cards: :title }, :h5),
94
127
  :title,
@@ -97,17 +130,52 @@ module Bootstrap5Helper
97
130
  )
98
131
  end
99
132
 
133
+ # Builds a Title component.
134
+ #
135
+ # @overload subtitle(tag, opts)
136
+ # @param [Symbol|String] tag - The HTML element to use.
137
+ # @param [Hash] options
138
+ # @option opts [String] :id
139
+ # @option opts [String] :class
140
+ # @option opts [Hash] :data
141
+ #
142
+ # @overload subtitle(opts)
143
+ # @param [Hash] options
144
+ # @option opts [String] :id
145
+ # @option opts [String] :class
146
+ # @option opts [Hash] :data
147
+ #
148
+ # @return [String]
149
+ #
150
+ def subtitle(*tag_or_options, &block)
151
+ tag, args = parse_tag_or_options(*tag_or_options, {})
152
+ build_sub_component(
153
+ tag || config({ cards: :subtitle }, :h6),
154
+ :subtitle,
155
+ args,
156
+ &block
157
+ )
158
+ end
159
+
100
160
  # Builds a Text component.
101
161
  #
102
- # @param [Symbol|Hash|NilClass] tag_or_options
103
- # @param [Hash] opts
104
- # @option opts [String] :id
105
- # @option opts [String] :class
106
- # @option opts [Hash] :data
162
+ # @overload header(tag, opts)
163
+ # @param [Symbol|String] tag - The HTML element to use.
164
+ # @param [Hash] options
165
+ # @option opts [String] :id
166
+ # @option opts [String] :class
167
+ # @option opts [Hash] :data
168
+ #
169
+ # @overload header(opts)
170
+ # @param [Hash] options
171
+ # @option opts [String] :id
172
+ # @option opts [String] :class
173
+ # @option opts [Hash] :data
174
+ #
107
175
  # @return [String]
108
176
  #
109
- def text(tag_or_options = nil, opts = {}, &block)
110
- tag, args = parse_tag_or_options(tag_or_options, opts)
177
+ def text(*tag_or_options, &block)
178
+ tag, args = parse_tag_or_options(*tag_or_options, {})
111
179
  build_sub_component(
112
180
  tag || config(:card_text, :p),
113
181
  :text,
@@ -0,0 +1,80 @@
1
+ module Bootstrap5Helper
2
+ class CardWithNavTab < Component # :nodoc:
3
+ # Class constructor
4
+ #
5
+ # @param [ActionView] template
6
+ # @param [Symbol|String|Hash] type_or_options
7
+ # @param [Hash] opts
8
+ # @option opts [String] :id
9
+ # @option opts [String] :class
10
+ # @option opts [Hash] :data
11
+ #
12
+ def initialize(template, *context_or_options, &block)
13
+ super(template)
14
+ @context, args = parse_context_or_options(*context_or_options, {})
15
+ @id = args.fetch(:id, '')
16
+ @class = args.fetch(:class, '')
17
+ @data = args.fetch(:data, nil)
18
+ @content = block || proc { '' }
19
+ end
20
+
21
+ # Builds a custom Nav component for the tabs.
22
+ #
23
+ # @overload nav(tag, opts)
24
+ # @param [Symbol|String] tag - :nav, :ul
25
+ # @param [Hash] opts
26
+ # @option opts [String] :id
27
+ # @option opts [String] :class
28
+ # @option opts [Hash] :data
29
+ # @option opts [Hash] :child - data attributes for child, NOT wrapper
30
+ #
31
+ # @overload nav(opts)
32
+ # @param [Hash] opts
33
+ # @option opts [String] :id
34
+ # @option opts [String] :class
35
+ # @option opts [Hash] :data
36
+ # @option opts [Hash] :child - data attributes for child, NOT wrapper
37
+ #
38
+ # @yield [Nav]
39
+ # @return [Nav]
40
+ #
41
+ def nav(*tag_or_options, &block)
42
+ tag, args = parse_tag_or_options(*tag_or_options, {})
43
+ args[:class] = (args[:class] || '') << 'nav-tabs card-header-tabs'
44
+ args[:data] = (args[:data] || {}).merge('bs-toggle' => 'tab')
45
+ args[:child] = {
46
+ data: {
47
+ 'bs-toggle' => 'tab',
48
+ 'bs-display' => 'static'
49
+ }
50
+ }
51
+
52
+ content_tag :div, class: 'card-header' do
53
+ Nav.new(@template, tag, args, &block).to_s
54
+ end
55
+ end
56
+
57
+ # Builds the Content object for the Tab.
58
+ #
59
+ # @param [Hash] opts
60
+ # @option opts [String] :id
61
+ # @option opts [String] :class
62
+ # @option opts [Hash] :data
63
+ # @return [Tab::Content]
64
+ #
65
+ def content(opts = {}, &block)
66
+ content_tag :div, class: 'card-body' do
67
+ Tab::Content.new(@template, opts, &block).to_s
68
+ end
69
+ end
70
+
71
+ # @todo
72
+ #
73
+ #
74
+ def to_s
75
+ content_tag :div, class: "card with-nav-tabs-#{@context}" do
76
+ @content.call(self)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -10,19 +10,24 @@ module Bootstrap5Helper
10
10
  header: :h2,
11
11
  body: :div
12
12
  },
13
- badges: :span,
13
+ badges: {
14
+ contrast: false,
15
+ base: :span
16
+ },
14
17
  callouts: {
15
18
  header: :h4
16
19
  },
17
20
  cards: {
18
- header: :h5,
19
- body: :div,
20
- footer: :div,
21
- title: :h5,
22
- text: :p
21
+ header: :h5,
22
+ body: :div,
23
+ footer: :div,
24
+ title: :h5,
25
+ subtitle: :h6,
26
+ text: :p
23
27
  },
24
28
  dropdowns: {},
25
- dropdown_menus: {
29
+ overlay_menus: {
30
+ base: :div,
26
31
  text: :span,
27
32
  header: :h6,
28
33
  divider: :div
@@ -12,8 +12,12 @@ module Bootstrap5Helper
12
12
  card
13
13
  callout
14
14
  configuration
15
+ overlay
16
+ overlay/menu
15
17
  dropdown
16
- dropdown/menu
18
+ dropup
19
+ dropstart
20
+ dropend
17
21
  input_group
18
22
  modal
19
23
  nav
@@ -23,6 +27,7 @@ module Bootstrap5Helper
23
27
  spinner
24
28
  tab
25
29
  tab/content
30
+ card_with_nav_tab
26
31
  ].freeze
27
32
  end
28
33
  end
@@ -2,120 +2,33 @@ module Bootstrap5Helper
2
2
  # Builds a Dropdown component that can be used in other components.
3
3
  #
4
4
  #
5
- class Dropdown < Component
5
+ class Dropdown < Overlay
6
6
  # Class constructor
7
7
  #
8
- # @param [ActionView] template
9
- # @param [Symbol|String] type
10
- # @param [Hash] opts
11
- # @option opts [String] :id
12
- # @option opts [String] :class
13
- # @option opts [Hash] :data
14
- # @option opts [Boolea] :split
15
- # @option opts [Boolean] :centered
16
- #
17
- def initialize(template, type = :dropdown, opts = {}, &block)
18
- super(template)
19
-
20
- @type = type
21
- @split = opts.fetch(:split, false)
22
- @centered = opts.fetch(:centered, false)
23
- @id = opts.fetch(:id, uuid)
24
- @class = opts.fetch(:class, '')
25
- @data = opts.fetch(:data, {})
26
- @content = block || proc { '' }
27
- end
28
-
29
- # Used to generate a button for the dropdown. The buttons default as just
30
- # a button that opens the coresponding dropdown menu. The `split: true` option
31
- # make the button just the arrow indicator that open the menu.
32
- #
33
- # @param [Symbol] context
34
- # @param [Hash] opts
35
- # @option opts [String] :id
36
- # @option opts [String] :class
37
- # @option opts [Hash] :data
38
- # @option opts [Boolean] :split
39
- # @return [String]
40
- #
41
- def button(context = :primary, opts = {})
42
- id = opts.fetch(:id, nil)
43
- klass = opts.fetch(:class, '')
44
- split = opts.fetch(:split, false)
45
- data = opts.fetch(:data, {}).merge('bs-toggle' => 'dropdown')
46
- extra = @split ? 'dropdown-toggle-split' : ''
47
-
48
- content_tag(
49
- :button,
50
- id: id,
51
- type: 'button',
52
- class: "dropdown-toggle btn btn-#{context} #{klass} #{extra}",
53
- data: data,
54
- aria: { haspopup: true, expanded: false }
55
- ) do
56
- split ? content_tag(:span, 'Toggle Dropdown', class: 'visually-hidden') : yield
57
- end
58
- end
59
-
60
- # Used to create a new `Dropdown::Menu`
61
- #
62
- # @param [Hash] opts
63
- # @option opts [String] :id
64
- # @option opts [String] :class
65
- # @option opts [Hash] :data
66
- # @return [Dropdown::Menu]
67
- #
68
- def menu(opts = {}, &block)
69
- Menu.new(@template, opts, &block)
70
- end
71
-
72
- # String reprentation of the object.
73
- #
74
- # @return [String]
75
- #
76
- def to_s
77
- content_tag(
78
- :div,
79
- id: @id,
80
- class: "#{element_type_class} #{alignment_type_class} #{@class}",
81
- data: @data
82
- ) do
83
- @content.call(self)
84
- end
85
- end
86
-
87
- private
88
-
89
- # Returns the container class for the dropdown component.
90
- #
91
- # @return [String]
92
- #
93
- def element_type_class
94
- case @type
95
- when :dropdown
96
- 'dropdown'
97
- when :dropup
98
- 'dropup'
99
- when :dropstart
100
- 'dropstart'
101
- when :dropend
102
- 'dropend'
103
- else
104
- ''
105
- end
106
- end
107
-
108
- # Returns the alignment class for the dropdown component.
109
- #
110
- # @return [String]
111
- #
112
- def alignment_type_class
113
- case @type
114
- when :dropdown, :dropup
115
- @centered ? "#{element_type_class}-center" : ''
116
- else
117
- ''
118
- end
8
+ # @overload initialize(template, tag, opts)
9
+ # @param [ActionView] template
10
+ # @param [Symbol|String] tag - The HTML element to use to wrap the component.
11
+ # @param [Hash] opts
12
+ # @option opts [String] :id
13
+ # @option opts [String] :class
14
+ # @option opts [Hash] :data
15
+ # @option opts [Boolea] :split
16
+ # @option opts [Boolean] :centered
17
+ #
18
+ # @overload initialize(template, opts)
19
+ # @param [ActionView] template
20
+ # @param [Hash] opts
21
+ # @option opts [String] :id
22
+ # @option opts [String] :class
23
+ # @option opts [Hash] :data
24
+ # @option opts [Boolea] :split
25
+ # @option opts [Boolean] :centered
26
+ #
27
+ # @return [Dropdown]
28
+ #
29
+ def initialize(template, *tag_or_options, &block)
30
+ super(template, *tag_or_options, &block)
31
+ @type = :dropdown
119
32
  end
120
33
  end
121
34
  end
@@ -0,0 +1,34 @@
1
+ module Bootstrap5Helper
2
+ # Builds a Dropdown component that can be used in other components.
3
+ #
4
+ #
5
+ class Dropend < Overlay
6
+ # Class constructor
7
+ #
8
+ # @overload initialize(template, tag, opts)
9
+ # @param [ActionView] template
10
+ # @param [Symbol|String] tag - The HTML element to use to wrap the component.
11
+ # @param [Hash] opts
12
+ # @option opts [String] :id
13
+ # @option opts [String] :class
14
+ # @option opts [Hash] :data
15
+ # @option opts [Boolea] :split
16
+ # @option opts [Boolean] :centered
17
+ #
18
+ # @overload initialize(template, opts)
19
+ # @param [ActionView] template
20
+ # @param [Hash] opts
21
+ # @option opts [String] :id
22
+ # @option opts [String] :class
23
+ # @option opts [Hash] :data
24
+ # @option opts [Boolea] :split
25
+ # @option opts [Boolean] :centered
26
+ #
27
+ # @return [Dropend]
28
+ #
29
+ def initialize(template, *tag_or_options, &block)
30
+ super(template, *tag_or_options, &block)
31
+ @type = :dropend
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Bootstrap5Helper
2
+ # Builds a Dropdown component that can be used in other components.
3
+ #
4
+ #
5
+ class Dropstart < Overlay
6
+ # Class constructor
7
+ #
8
+ # @overload initialize(template, tag, opts)
9
+ # @param [ActionView] template
10
+ # @param [Symbol|String] tag - The HTML element to use to wrap the component.
11
+ # @param [Hash] opts
12
+ # @option opts [String] :id
13
+ # @option opts [String] :class
14
+ # @option opts [Hash] :data
15
+ # @option opts [Boolea] :split
16
+ # @option opts [Boolean] :centered
17
+ #
18
+ # @overload initialize(template, opts)
19
+ # @param [ActionView] template
20
+ # @param [Hash] opts
21
+ # @option opts [String] :id
22
+ # @option opts [String] :class
23
+ # @option opts [Hash] :data
24
+ # @option opts [Boolea] :split
25
+ # @option opts [Boolean] :centered
26
+ #
27
+ # @return [Dropstart]
28
+ #
29
+ def initialize(template, *tag_or_options, &block)
30
+ super(template, *tag_or_options, &block)
31
+ @type = :dropstart
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Bootstrap5Helper
2
+ # Builds a Dropdown component that can be used in other components.
3
+ #
4
+ #
5
+ class Dropup < Overlay
6
+ # Class constructor
7
+ #
8
+ # @overload initialize(template, tag, opts)
9
+ # @param [ActionView] template
10
+ # @param [Symbol|String] tag - The HTML element to use to wrap the component.
11
+ # @param [Hash] opts
12
+ # @option opts [String] :id
13
+ # @option opts [String] :class
14
+ # @option opts [Hash] :data
15
+ # @option opts [Boolea] :split
16
+ # @option opts [Boolean] :centered
17
+ #
18
+ # @overload initialize(template, opts)
19
+ # @param [ActionView] template
20
+ # @param [Hash] opts
21
+ # @option opts [String] :id
22
+ # @option opts [String] :class
23
+ # @option opts [Hash] :data
24
+ # @option opts [Boolea] :split
25
+ # @option opts [Boolean] :centered
26
+ #
27
+ # @return [Dropup]
28
+ #
29
+ def initialize(template, *tag_or_options, &block)
30
+ super(template, *tag_or_options, &block)
31
+ @type = :dropup
32
+ end
33
+ end
34
+ end