bs5 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c59051b95e71e72c78e941b4fb15915dedfdf4e46564f83bfab206605c84fdc1
4
- data.tar.gz: 7d0de3b478c43f569583b2df7937fdc83aa4264bbcf8bc222c3b3fd5f50a99e1
3
+ metadata.gz: 1d4e64b1fb40e3224c42147923de60bb7233c2c2fbf411674e0bca31c093c837
4
+ data.tar.gz: 80ef0fe973d5cab69eb75e4834dbaed31c1886d13c4f6586aeed655d0a69ba2a
5
5
  SHA512:
6
- metadata.gz: 33d60944d67212152aab1a2e4880fe30fd44e8e9028e8ad227d437bab2b7c18780592b1cc5c4ce636cf9defeea7994c87a0edf311f3307d6dc0ebab7ae2bf301
7
- data.tar.gz: 517cdbda7eff4f44f4db1b3e62679326c07465c0eb857105905e605ae8535b312fb096d97453b0e92a094431a56d9974cfb56a4a39937eab95a86ef6cba53b67
6
+ metadata.gz: a4b8e31ace3f99001251e99f0e8c7d2ad8e2320008223c7b346eeca08fcd9e39d2b59c208e181720a2c6e611550a6913e11cc941b0c92a89dffd73b4bf9d615d
7
+ data.tar.gz: 10bcf562669a15ea680eea134048ab9ee32986e905e28173184ddf044842ac6dafdb507817a3154487e2fa5e567aaa2209313e25752b77e7699df18720adc630
data/README.md CHANGED
@@ -33,7 +33,7 @@ $ gem install bs5
33
33
  Run the following command to setup your project to use Bootstrap 5.
34
34
 
35
35
  $ rails generate bs5:install
36
-
36
+
37
37
  ## Components
38
38
 
39
39
  ### [Accordion](https://v5.getbootstrap.com/docs/5.0/components/accordion/) ✅
@@ -51,6 +51,7 @@ Run the following command to setup your project to use Bootstrap 5.
51
51
  <% end %>
52
52
  <%- end %>
53
53
  ```
54
+
54
55
  ```
55
56
  <%= bs5_accordion(flush: true) do |accordion| %>
56
57
  <% accordion.slot(:item, title: 'Accordion Item #1') do %>
@@ -74,21 +75,33 @@ Run the following command to setup your project to use Bootstrap 5.
74
75
  ```
75
76
 
76
77
  ```
77
- <%= bs5_alert(type: :warning, is_dismissable: true) do %>
78
+ <%= bs5_alert(style: :warning, is_dismissable: true) do %>
78
79
  <strong>Holy guacamole!</strong> You should check in on some of those fields below.
79
80
  <%- end %>
80
81
  ```
81
82
 
82
- ### [Badge](https://v5.getbootstrap.com/docs/5.0/components/badge/)
83
+ ### [Badge](https://v5.getbootstrap.com/docs/5.0/components/badge/)
83
84
 
84
- ### [Breadcrumb](https://v5.getbootstrap.com/docs/5.0/components/breadcrumb/)
85
+ ```
86
+ <%= bs5_badge(text: 'New') %>
87
+ ```
85
88
 
86
- ###[Button](https://v5.getbootstrap.com/docs/5.0/components/buttons/)
89
+ ```
90
+ <%= bs5_badge(text: 'Warning', style: :warning) %>
91
+ ```
92
+
93
+ ```
94
+ <%= bs5_badge(text: 'Danger', style: :danger, pill: true) %>
95
+ ```
96
+
97
+
98
+ ### [Breadcrumb](https://v5.getbootstrap.com/docs/5.0/components/breadcrumb/)
87
99
 
100
+ ### [Button](https://v5.getbootstrap.com/docs/5.0/components/buttons/)
88
101
 
89
102
  ## Previewing components
90
103
 
91
- * http://localhost:3000/rails/view_components
104
+ - http://localhost:3000/rails/view_components
92
105
 
93
106
  ## Contributing
94
107
 
@@ -2,18 +2,13 @@
2
2
 
3
3
  module Bs5
4
4
  class AlertComponent < ViewComponent::Base
5
- TYPES = %i[primary secondary success danger warning info light dark].freeze
5
+ attr_reader :style, :is_dismissable
6
6
 
7
7
  include ActiveModel::Validations
8
+ validates :style, style: true
8
9
 
9
- attr_reader :type, :is_dismissable
10
-
11
- validates :type, inclusion: { in: TYPES, message: lambda do |_, data|
12
- "#{data[:value].inspect} is not valid. Try #{TYPES.to_sentence(last_word_connector: ' or ')}."
13
- end }
14
-
15
- def initialize(type: :primary, is_dismissable: false)
16
- @type = type.to_sym
10
+ def initialize(style: :primary, is_dismissable: false)
11
+ @style = style.to_sym
17
12
  @is_dismissable = is_dismissable
18
13
  end
19
14
 
@@ -34,7 +29,7 @@ module Bs5
34
29
  end
35
30
 
36
31
  def contextual_class
37
- "alert-#{@type}"
32
+ "alert-#{@style}"
38
33
  end
39
34
  end
40
35
  end
@@ -0,0 +1 @@
1
+ <span class="<%= component_class %>"><%= text %></span>
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class BadgeComponent < ViewComponent::Base
5
+ attr_reader :text, :style
6
+
7
+ include ActiveModel::Validations
8
+ validates :style, style: true
9
+
10
+ def initialize(text:, style: :secondary, pill: false)
11
+ @text = text
12
+ @style = style.to_sym
13
+ @pill = pill
14
+ end
15
+
16
+ def before_render
17
+ raise errors.full_messages.to_sentence if invalid?
18
+ end
19
+
20
+ private
21
+
22
+ def component_class
23
+ class_names = ['badge', contextual_class]
24
+ class_names << %w[rounded-pill] if pill?
25
+ class_names.join(' ')
26
+ end
27
+
28
+ def pill?
29
+ @pill
30
+ end
31
+
32
+ def contextual_class
33
+ class_names = ["bg-#{@style}"]
34
+ class_names << %w[text-dark] if style.in?(%i[warning info light])
35
+ class_names.join(' ')
36
+ end
37
+ end
38
+ end
@@ -2,16 +2,20 @@
2
2
 
3
3
  module Bs5
4
4
  module ComponentsHelper
5
+ def bs5_accordion(*args)
6
+ render AccordionComponent.new(*args) do |accordion|
7
+ yield accordion if block_given?
8
+ end
9
+ end
10
+
5
11
  def bs5_alert(*args)
6
12
  render AlertComponent.new(*args) do
7
13
  yield if block_given?
8
14
  end
9
15
  end
10
16
 
11
- def bs5_accordion(*args)
12
- render AccordionComponent.new(*args) do |accordion|
13
- yield accordion if block_given?
14
- end
17
+ def bs5_badge(*args)
18
+ render BadgeComponent.new(*args)
15
19
  end
16
20
  end
17
21
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StyleValidator < ActiveModel::EachValidator
4
+ STYLES = %i[primary secondary success danger warning info light dark].freeze
5
+
6
+ def validate_each(record, attribute, value)
7
+ return if value.in?(STYLES)
8
+
9
+ record.errors.add(attribute, :inclusion, valid_styles: STYLES.to_sentence)
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ en:
2
+ activemodel:
3
+ errors:
4
+ models:
5
+ bs5/alert_component:
6
+ attributes:
7
+ style:
8
+ inclusion: "is not included in the list: %{valid_styles}."
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs5
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Baselier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-17 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -102,13 +102,17 @@ files:
102
102
  - app/components/bs5/accordion_component.rb
103
103
  - app/components/bs5/alert_component.html.erb
104
104
  - app/components/bs5/alert_component.rb
105
+ - app/components/bs5/badge_component.html.erb
106
+ - app/components/bs5/badge_component.rb
105
107
  - app/controllers/bs5/application_controller.rb
106
108
  - app/helpers/bs5/application_helper.rb
107
109
  - app/helpers/bs5/components_helper.rb
108
110
  - app/jobs/bs5/application_job.rb
109
111
  - app/mailers/bs5/application_mailer.rb
110
112
  - app/models/bs5/application_record.rb
113
+ - app/validators/style_validator.rb
111
114
  - app/views/layouts/bs5/application.html.erb
115
+ - config/locales/en.yml
112
116
  - config/routes.rb
113
117
  - lib/bs5.rb
114
118
  - lib/bs5/engine.rb