bs5 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/bs5/button_tag_component.rb +1 -5
- data/app/components/bs5/button_to_component.rb +106 -0
- data/app/helpers/bs5/components_helper.rb +1 -1
- data/app/views/bs5/examples/_buttons.html.erb +10 -6
- data/app/views/bs5/examples/buttons/button_tag/block_buttons/_example.html.erb +5 -0
- data/app/views/bs5/examples/buttons/{block_buttons → button_tag/block_buttons}/block_buttons.html.erb +0 -0
- data/app/views/bs5/examples/buttons/{block_buttons → button_tag/block_buttons}/responsive_block_buttons_1.html.erb +0 -0
- data/app/views/bs5/examples/buttons/{block_buttons → button_tag/block_buttons}/responsive_block_buttons_2.html.erb +0 -0
- data/app/views/bs5/examples/buttons/{block_buttons → button_tag/block_buttons}/responsive_block_buttons_3.html.erb +0 -0
- data/app/views/bs5/examples/buttons/button_tag/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/{default → button_tag/default}/snippet.html.erb +0 -0
- data/app/views/bs5/examples/buttons/button_tag/outline/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/{outline → button_tag/outline}/snippet.html.erb +0 -0
- data/app/views/bs5/examples/buttons/button_tag/size/_example.html.erb +3 -0
- data/app/views/bs5/examples/buttons/{size → button_tag/size}/large.html.erb +0 -0
- data/app/views/bs5/examples/buttons/{size → button_tag/size}/small.html.erb +0 -0
- data/app/views/bs5/examples/buttons/button_tag/style/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/{style → button_tag/style}/snippet.html.erb +0 -0
- data/app/views/bs5/examples/buttons/button_tag/toggle_states/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/{toggle_states → button_tag/toggle_states}/snippet.html.erb +0 -0
- data/app/views/bs5/examples/buttons/button_to/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/button_to/default/snippet.html.erb +11 -0
- data/config/locales/en.yml +6 -0
- data/lib/bs5/version.rb +1 -1
- metadata +20 -17
- data/app/views/bs5/examples/buttons/block_buttons/_example.html.erb +0 -5
- data/app/views/bs5/examples/buttons/default/_example.html.erb +0 -2
- data/app/views/bs5/examples/buttons/outline/_example.html.erb +0 -2
- data/app/views/bs5/examples/buttons/size/_example.html.erb +0 -3
- data/app/views/bs5/examples/buttons/style/_example.html.erb +0 -2
- data/app/views/bs5/examples/buttons/toggle_states/_example.html.erb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d45e3e9d6c5303c22f72e3637abc45b8302a2834956d9213a3cbe3300320658
|
4
|
+
data.tar.gz: 0c9d8ed8656a427932ba2fae5a49bb6f8110bd0a86d7af8a0f95020ae0cafd6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 149b6ad2c77ad23fcef6c02d0a6e6b147dd32e0d1299807484233b207dc7280c90d3bf2fce397c02b64376478ace48bcc30aea57de654fa9ce0a6c4a715ccc7d
|
7
|
+
data.tar.gz: 59471a7a2b75588e27d203e982ae52f1b1e54498ca0e26c6776bf7b5ef34166cbd7f644a80302f6ec1034b747b34f5b144d03bca836c07f84ba5808f3dbfa999
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bs5
|
4
|
+
class ButtonToComponent < ViewComponent::Base
|
5
|
+
STYLES = %i[primary secondary success danger warning info light dark link].freeze
|
6
|
+
DEFAULT_STYLE = :primary
|
7
|
+
SIZES = { small: :sm, large: :lg }.freeze
|
8
|
+
CLASS_PREFIX = 'btn'
|
9
|
+
|
10
|
+
attr_reader :size
|
11
|
+
|
12
|
+
include ActiveModel::Validations
|
13
|
+
validates :style, style: true
|
14
|
+
validates :size, inclusion: { in: SIZES.keys, valid_sizes: SIZES.keys.to_sentence, allow_nil: true }
|
15
|
+
|
16
|
+
def initialize(name = nil, options = nil, html_options = nil)
|
17
|
+
@name = name
|
18
|
+
@options = options
|
19
|
+
@html_options = html_options
|
20
|
+
|
21
|
+
if @name.is_a? Hash
|
22
|
+
self.button_to_options = @name
|
23
|
+
elsif @options.is_a? Hash
|
24
|
+
self.button_to_options = @options
|
25
|
+
else
|
26
|
+
@html_options ||= {}
|
27
|
+
self.button_to_options = @html_options
|
28
|
+
end
|
29
|
+
|
30
|
+
extract_custom_options
|
31
|
+
merge_default_options
|
32
|
+
end
|
33
|
+
|
34
|
+
def before_render
|
35
|
+
raise errors.full_messages.to_sentence if invalid?
|
36
|
+
end
|
37
|
+
|
38
|
+
def call
|
39
|
+
if content
|
40
|
+
button_to(@name, @options, @html_options) { content }
|
41
|
+
else
|
42
|
+
button_to(@name, @options, @html_options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def button_to_options=(hash)
|
49
|
+
@button_to_options = hash.symbolize_keys!
|
50
|
+
end
|
51
|
+
|
52
|
+
def extract_custom_options
|
53
|
+
extract_style
|
54
|
+
extract_outline
|
55
|
+
extract_size
|
56
|
+
end
|
57
|
+
|
58
|
+
def extract_style
|
59
|
+
@style = @button_to_options.delete(:style)
|
60
|
+
end
|
61
|
+
|
62
|
+
def extract_outline
|
63
|
+
@outline = @button_to_options.delete(:outline)
|
64
|
+
end
|
65
|
+
|
66
|
+
def extract_size
|
67
|
+
@size = @button_to_options.delete(:size)
|
68
|
+
end
|
69
|
+
|
70
|
+
def merge_default_options
|
71
|
+
@button_to_options.deep_merge!(default_options) do |_key, this_val, other_val|
|
72
|
+
[this_val, other_val].join(' ').strip
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def default_options
|
77
|
+
{ class: button_class }
|
78
|
+
end
|
79
|
+
|
80
|
+
def button_class
|
81
|
+
[CLASS_PREFIX, contextual_class, size_class].compact.join(' ')
|
82
|
+
end
|
83
|
+
|
84
|
+
def contextual_class
|
85
|
+
[CLASS_PREFIX, outline? ? 'outline' : nil, style].compact.join('-')
|
86
|
+
end
|
87
|
+
|
88
|
+
def size_class
|
89
|
+
return unless size?
|
90
|
+
|
91
|
+
[CLASS_PREFIX, SIZES[size]].join('-')
|
92
|
+
end
|
93
|
+
|
94
|
+
def style
|
95
|
+
(@style || DEFAULT_STYLE).to_sym
|
96
|
+
end
|
97
|
+
|
98
|
+
def outline?
|
99
|
+
!!@outline
|
100
|
+
end
|
101
|
+
|
102
|
+
def size?
|
103
|
+
!!size
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Bs5
|
4
4
|
module ComponentsHelper
|
5
|
-
COMPONENTS = %w[accordion alert badge close_button breadcrumb button_tag].freeze
|
5
|
+
COMPONENTS = %w[accordion alert badge close_button breadcrumb button_tag button_to].freeze
|
6
6
|
|
7
7
|
COMPONENTS.each do |name|
|
8
8
|
define_method("bs5_#{name}") do |*args, &block|
|
@@ -1,7 +1,11 @@
|
|
1
1
|
<h2>Buttons</h2>
|
2
|
-
|
3
|
-
<%= render 'bs5/examples/buttons/
|
4
|
-
<%= render 'bs5/examples/buttons/
|
5
|
-
<%= render 'bs5/examples/buttons/
|
6
|
-
<%= render 'bs5/examples/buttons/
|
7
|
-
<%= render 'bs5/examples/buttons/
|
2
|
+
<h3>Decorating Rails' <code>button_tag</code></h3>
|
3
|
+
<%= render 'bs5/examples/buttons/button_tag/default/example' %>
|
4
|
+
<%= render 'bs5/examples/buttons/button_tag/style/example' %>
|
5
|
+
<%= render 'bs5/examples/buttons/button_tag/outline/example' %>
|
6
|
+
<%= render 'bs5/examples/buttons/button_tag/size/example' %>
|
7
|
+
<%= render 'bs5/examples/buttons/button_tag/block_buttons/example' %>
|
8
|
+
<%= render 'bs5/examples/buttons/button_tag/toggle_states/example' %>
|
9
|
+
|
10
|
+
<h3>Decorating Rails' <code>button_to</code></h3>
|
11
|
+
<%= render 'bs5/examples/buttons/button_to/default/example' %>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<h3>Block buttons</h3>
|
2
|
+
<%= bs5_example(snippet: 'buttons/button_tag/block_buttons/block_buttons') %>
|
3
|
+
<%= bs5_example(snippet: 'buttons/button_tag/block_buttons/responsive_block_buttons_1') %>
|
4
|
+
<%= bs5_example(snippet: 'buttons/button_tag/block_buttons/responsive_block_buttons_2') %>
|
5
|
+
<%= bs5_example(snippet: 'buttons/button_tag/block_buttons/responsive_block_buttons_3') %>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/app/views/bs5/examples/buttons/{toggle_states → button_tag/toggle_states}/snippet.html.erb
RENAMED
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="d-grid gap-2 d-md-flex">
|
2
|
+
<%= bs5_button_to('New', 'http://www.example.com') %>
|
3
|
+
|
4
|
+
<%= bs5_button_to('http://www.example.com', style: :success) do %>
|
5
|
+
Make happy <strong>John Doe</strong>
|
6
|
+
<%- end %>
|
7
|
+
|
8
|
+
<%= bs5_button_to('New', 'http://www.example.com', style: :dark, outline: true, size: :large, form_class: 'new-thing') %>
|
9
|
+
|
10
|
+
<%= bs5_button_to('Destroy', 'http://www.example.com', style: :danger, method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
|
11
|
+
</div>
|
data/config/locales/en.yml
CHANGED
@@ -12,3 +12,9 @@ en:
|
|
12
12
|
inclusion: "is not included in the list: %{valid_styles}."
|
13
13
|
size:
|
14
14
|
inclusion: "is not included in the list: %{valid_sizes}."
|
15
|
+
bs5/button_to_component:
|
16
|
+
attributes:
|
17
|
+
style:
|
18
|
+
inclusion: "is not included in the list: %{valid_styles}."
|
19
|
+
size:
|
20
|
+
inclusion: "is not included in the list: %{valid_sizes}."
|
data/lib/bs5/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bs5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Baselier
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- app/components/bs5/breadcrumb_component.html.erb
|
136
136
|
- app/components/bs5/breadcrumb_component.rb
|
137
137
|
- app/components/bs5/button_tag_component.rb
|
138
|
+
- app/components/bs5/button_to_component.rb
|
138
139
|
- app/components/bs5/close_button_component.html.erb
|
139
140
|
- app/components/bs5/close_button_component.rb
|
140
141
|
- app/components/bs5/example_component.html.erb
|
@@ -172,22 +173,24 @@ files:
|
|
172
173
|
- app/views/bs5/examples/badge/style/snippet.html.erb
|
173
174
|
- app/views/bs5/examples/breadcrumb/default/_example.html.erb
|
174
175
|
- app/views/bs5/examples/breadcrumb/default/snippet.html.erb
|
175
|
-
- app/views/bs5/examples/buttons/block_buttons/_example.html.erb
|
176
|
-
- app/views/bs5/examples/buttons/block_buttons/block_buttons.html.erb
|
177
|
-
- app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_1.html.erb
|
178
|
-
- app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_2.html.erb
|
179
|
-
- app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_3.html.erb
|
180
|
-
- app/views/bs5/examples/buttons/default/_example.html.erb
|
181
|
-
- app/views/bs5/examples/buttons/default/snippet.html.erb
|
182
|
-
- app/views/bs5/examples/buttons/outline/_example.html.erb
|
183
|
-
- app/views/bs5/examples/buttons/outline/snippet.html.erb
|
184
|
-
- app/views/bs5/examples/buttons/size/_example.html.erb
|
185
|
-
- app/views/bs5/examples/buttons/size/large.html.erb
|
186
|
-
- app/views/bs5/examples/buttons/size/small.html.erb
|
187
|
-
- app/views/bs5/examples/buttons/style/_example.html.erb
|
188
|
-
- app/views/bs5/examples/buttons/style/snippet.html.erb
|
189
|
-
- app/views/bs5/examples/buttons/toggle_states/_example.html.erb
|
190
|
-
- app/views/bs5/examples/buttons/toggle_states/snippet.html.erb
|
176
|
+
- app/views/bs5/examples/buttons/button_tag/block_buttons/_example.html.erb
|
177
|
+
- app/views/bs5/examples/buttons/button_tag/block_buttons/block_buttons.html.erb
|
178
|
+
- app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_1.html.erb
|
179
|
+
- app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_2.html.erb
|
180
|
+
- app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_3.html.erb
|
181
|
+
- app/views/bs5/examples/buttons/button_tag/default/_example.html.erb
|
182
|
+
- app/views/bs5/examples/buttons/button_tag/default/snippet.html.erb
|
183
|
+
- app/views/bs5/examples/buttons/button_tag/outline/_example.html.erb
|
184
|
+
- app/views/bs5/examples/buttons/button_tag/outline/snippet.html.erb
|
185
|
+
- app/views/bs5/examples/buttons/button_tag/size/_example.html.erb
|
186
|
+
- app/views/bs5/examples/buttons/button_tag/size/large.html.erb
|
187
|
+
- app/views/bs5/examples/buttons/button_tag/size/small.html.erb
|
188
|
+
- app/views/bs5/examples/buttons/button_tag/style/_example.html.erb
|
189
|
+
- app/views/bs5/examples/buttons/button_tag/style/snippet.html.erb
|
190
|
+
- app/views/bs5/examples/buttons/button_tag/toggle_states/_example.html.erb
|
191
|
+
- app/views/bs5/examples/buttons/button_tag/toggle_states/snippet.html.erb
|
192
|
+
- app/views/bs5/examples/buttons/button_to/default/_example.html.erb
|
193
|
+
- app/views/bs5/examples/buttons/button_to/default/snippet.html.erb
|
191
194
|
- app/views/bs5/examples/close_button/default/_example.html.erb
|
192
195
|
- app/views/bs5/examples/close_button/default/snippet.html.erb
|
193
196
|
- app/views/bs5/examples/close_button/disabled/_example.html.erb
|
@@ -1,5 +0,0 @@
|
|
1
|
-
<h3>Block buttons</h3>
|
2
|
-
<%= bs5_example(snippet: 'buttons/block_buttons/block_buttons') %>
|
3
|
-
<%= bs5_example(snippet: 'buttons/block_buttons/responsive_block_buttons_1') %>
|
4
|
-
<%= bs5_example(snippet: 'buttons/block_buttons/responsive_block_buttons_2') %>
|
5
|
-
<%= bs5_example(snippet: 'buttons/block_buttons/responsive_block_buttons_3') %>
|