flowbite-components 0.1.0 → 0.1.2

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/README.md +34 -7
  4. data/app/assets/tailwind/flowbite_components/engine.css +2 -0
  5. data/app/components/flowbite/button/outline.rb +22 -0
  6. data/app/components/flowbite/button/pill.rb +40 -0
  7. data/app/components/flowbite/button.rb +92 -0
  8. data/app/components/flowbite/card.rb +43 -0
  9. data/app/components/flowbite/input/checkbox.rb +37 -0
  10. data/app/components/flowbite/input/date.rb +11 -0
  11. data/app/components/flowbite/input/email.rb +12 -0
  12. data/app/components/flowbite/input/field.rb +117 -0
  13. data/app/components/flowbite/input/file.rb +30 -0
  14. data/app/components/flowbite/input/hint.rb +57 -0
  15. data/app/components/flowbite/input/label.rb +82 -0
  16. data/app/components/flowbite/input/number.rb +11 -0
  17. data/app/components/flowbite/input/password.rb +11 -0
  18. data/app/components/flowbite/input/phone.rb +11 -0
  19. data/app/components/flowbite/input/radio_button.rb +50 -0
  20. data/app/components/flowbite/input/select.rb +49 -0
  21. data/app/components/flowbite/input/textarea.rb +42 -0
  22. data/app/components/flowbite/input/url.rb +12 -0
  23. data/app/components/flowbite/input/validation_error.rb +11 -0
  24. data/app/components/flowbite/input_field/checkbox.html.erb +14 -0
  25. data/app/components/flowbite/input_field/checkbox.rb +49 -0
  26. data/app/components/flowbite/input_field/date.rb +13 -0
  27. data/app/components/flowbite/input_field/email.rb +13 -0
  28. data/app/components/flowbite/input_field/file.rb +13 -0
  29. data/app/components/flowbite/input_field/input_field.html.erb +8 -0
  30. data/app/components/flowbite/input_field/number.rb +13 -0
  31. data/app/components/flowbite/input_field/password.rb +13 -0
  32. data/app/components/flowbite/input_field/phone.rb +13 -0
  33. data/app/components/flowbite/input_field/radio_button.html.erb +14 -0
  34. data/app/components/flowbite/input_field/radio_button.rb +88 -0
  35. data/app/components/flowbite/input_field/select.rb +31 -0
  36. data/app/components/flowbite/input_field/text.rb +8 -0
  37. data/app/components/flowbite/input_field/textarea.rb +13 -0
  38. data/app/components/flowbite/input_field/url.rb +13 -0
  39. data/app/components/flowbite/input_field.rb +187 -0
  40. data/app/components/flowbite/style.rb +13 -0
  41. data/lib/flowbite/{view_components → components}/engine.rb +2 -2
  42. data/lib/flowbite/{view_components → components}/version.rb +2 -2
  43. data/lib/flowbite/{view_components.rb → components.rb} +3 -3
  44. metadata +49 -10
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ # A form element for a single field, containing label, input field, error
5
+ # messages, helper text and whatever else is needed for a user friendly input
6
+ # experience.
7
+ #
8
+ # @see https://flowbite.com/docs/forms/input-field/
9
+ #
10
+ # The input field is an important part of the form element that can be used to
11
+ # create interactive controls to accept data from the user based on multiple
12
+ # input types, such as text, email, number, password, URL, phone number, and
13
+ # more.
14
+ #
15
+ # Usually you'd use one of the subclasses of this class which implement the
16
+ # different input types, like `Flowbite::InputField::Text`,
17
+ # `Flowbite::InputField::Email`, etc.
18
+ #
19
+ # Expects 2 arguments:
20
+ #
21
+ # @param attribute [Symbol] The name of the attribute to render in this input
22
+ # field.
23
+ #
24
+ # @param form [ActionView::Helpers::FormBuilder] The form builder object that
25
+ # will be used to generate the input field.
26
+ #
27
+ # Supports additional arguments:
28
+ #
29
+ # @param hint [String] A hint to display below the input field, providing
30
+ # additional context or instructions for the user. This is optional. See
31
+ # https://flowbite.com/docs/forms/input-field/#helper-text
32
+ #
33
+ # @param label [Hash] A hash with options for the label. These are passed to
34
+ # Flowbite::Input::Label, see that for details. Can contain:
35
+ # - `content`: The content of the label. If not provided, the label will
36
+ # default to the attribute name.
37
+ # - `options`: A hash of additional options to pass to the label component.
38
+ # This can be used to set the class, for example.
39
+ #
40
+ # @param disabled [Boolean] Whether the input field should be disabled.
41
+ # Defaults to `false`.
42
+ #
43
+ # @param input [Hash] A hash with options for the default input component.
44
+ # These are passed to the input components constructor, so see whatever
45
+ # component is being used for details. Can contain:
46
+ # - `options`: Additional HTML attributes to pass to the input element.
47
+ #
48
+ # @param size [Symbol] The size of the input field. Can be one of `:sm`,
49
+ # `:md`, or `:lg`. Defaults to `:md`.
50
+ #
51
+ # Sample usage
52
+ #
53
+ # <% form_for @person do |form| %>
54
+ # <%= render(
55
+ # Flowbite::InputField::Number.new(
56
+ # :attribute => :name,
57
+ # :form => form
58
+ # )
59
+ # ) %>
60
+ # <% end %>
61
+ #
62
+ # To render an input without labels or error messages etc, use
63
+ # `Flowbite::Input::Field` instead.
64
+ class InputField < ViewComponent::Base
65
+ renders_one :hint
66
+ renders_one :input
67
+ renders_one :label
68
+
69
+ # Returns the errors for attribute
70
+ def errors
71
+ @object.errors[@attribute] || []
72
+ end
73
+
74
+ def initialize(attribute:, form:, disabled: false, hint: nil, input: {}, label: {}, size: :default)
75
+ @attribute = attribute
76
+ @disabled = disabled
77
+ @form = form
78
+ @hint = hint
79
+ @input = input
80
+ @label = label
81
+ @object = form.object
82
+ @size = size
83
+ end
84
+
85
+ def input_component
86
+ ::Flowbite::Input::Field
87
+ end
88
+
89
+ protected
90
+
91
+ # Returns the HTML to use for the hint element if any
92
+ def default_hint
93
+ return unless hint?
94
+
95
+ component = Flowbite::Input::Hint.new(
96
+ attribute: @attribute,
97
+ form: @form,
98
+ options: default_hint_options
99
+ ).with_content(default_hint_content)
100
+ render(component)
101
+ end
102
+
103
+ def default_hint_content
104
+ return nil unless @hint
105
+
106
+ @hint[:content]
107
+ end
108
+
109
+ # Returns a Hash with the default attributes to apply to the hint element.
110
+ #
111
+ # The default attributes can be overriden by passing the `hint[options]`
112
+ # argument to the constructor.
113
+ def default_hint_options
114
+ return {} unless @hint
115
+
116
+ {
117
+ id: id_for_hint_element
118
+ }.merge(@hint[:options] || {})
119
+ end
120
+
121
+ # Returns a Hash with the default attributes to apply to the input element.
122
+ #
123
+ # The default attributes can be overriden by passing the `input[options]`
124
+ # argument to the constructor.
125
+ def default_input_options
126
+ if hint?
127
+ {
128
+ "aria-describedby": id_for_hint_element
129
+ }
130
+ else
131
+ {}
132
+ end
133
+ end
134
+
135
+ # Returns the HTML to use for the default input element.
136
+ def default_input
137
+ render(input_component.new(
138
+ form: @form,
139
+ attribute: @attribute,
140
+ disabled: @disabled,
141
+ options: input_options,
142
+ size: @size
143
+ ))
144
+ end
145
+
146
+ def default_label
147
+ component = Flowbite::Input::Label.new(**default_label_options)
148
+ if default_label_content
149
+ component.with_content(default_label_content)
150
+ else
151
+ component
152
+ end
153
+ end
154
+
155
+ def default_label_content
156
+ @label[:content]
157
+ end
158
+
159
+ def default_label_options
160
+ label_options = @label.dup
161
+ label_options.delete(:content)
162
+
163
+ {
164
+ attribute: @attribute,
165
+ form: @form
166
+ }.merge(label_options)
167
+ end
168
+
169
+ # Returns true if the input field is disabled, false otherwise.
170
+ def disabled?
171
+ !!@disabled
172
+ end
173
+
174
+ # Returns true if the input field has a hint, false otherwise.
175
+ def hint?
176
+ @hint.present?
177
+ end
178
+
179
+ def id_for_hint_element
180
+ "#{@form.object_name}_#{@attribute}_hint"
181
+ end
182
+
183
+ def input_options
184
+ default_input_options.merge(@input[:options] || {})
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Style
5
+ attr_reader :classes
6
+
7
+ delegate :fetch, to: :classes
8
+
9
+ def initialize(classes)
10
+ @classes = classes
11
+ end
12
+ end
13
+ end
@@ -1,9 +1,9 @@
1
1
  require "rails/engine"
2
2
 
3
3
  module Flowbite
4
- module ViewComponents
4
+ module Components
5
5
  class Engine < ::Rails::Engine
6
- isolate_namespace Flowbite::ViewComponents
6
+ isolate_namespace Flowbite::Components
7
7
 
8
8
  config.autoload_paths = [
9
9
  "#{root}/app/components"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flowbite
4
- module ViewComponents
5
- VERSION = "0.1.0"
4
+ module Components
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "view_components/engine"
4
- require_relative "view_components/version"
3
+ require_relative "components/engine"
4
+ require_relative "components/version"
5
5
 
6
6
  require "view_component"
7
7
 
8
8
  module Flowbite
9
- module ViewComponents
9
+ module Components
10
10
  class Error < StandardError; end
11
11
  # Your code goes here...
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowbite-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Skjerning
@@ -23,7 +23,8 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 4.0.0
26
- description: A library of Flowbite View Components to be used in Rails applications.
26
+ description: A library of View Components based on the Flowbite design system to be
27
+ used in Rails applications.
27
28
  email:
28
29
  - jakob@mentalized.net
29
30
  executables: []
@@ -33,18 +34,56 @@ files:
33
34
  - CHANGELOG.md
34
35
  - LICENSE
35
36
  - README.md
36
- - lib/flowbite/view_components.rb
37
- - lib/flowbite/view_components/engine.rb
38
- - lib/flowbite/view_components/version.rb
39
- homepage: https://github.com/substancelab/flowbite-view_components
37
+ - app/assets/tailwind/flowbite_components/engine.css
38
+ - app/components/flowbite/button.rb
39
+ - app/components/flowbite/button/outline.rb
40
+ - app/components/flowbite/button/pill.rb
41
+ - app/components/flowbite/card.rb
42
+ - app/components/flowbite/input/checkbox.rb
43
+ - app/components/flowbite/input/date.rb
44
+ - app/components/flowbite/input/email.rb
45
+ - app/components/flowbite/input/field.rb
46
+ - app/components/flowbite/input/file.rb
47
+ - app/components/flowbite/input/hint.rb
48
+ - app/components/flowbite/input/label.rb
49
+ - app/components/flowbite/input/number.rb
50
+ - app/components/flowbite/input/password.rb
51
+ - app/components/flowbite/input/phone.rb
52
+ - app/components/flowbite/input/radio_button.rb
53
+ - app/components/flowbite/input/select.rb
54
+ - app/components/flowbite/input/textarea.rb
55
+ - app/components/flowbite/input/url.rb
56
+ - app/components/flowbite/input/validation_error.rb
57
+ - app/components/flowbite/input_field.rb
58
+ - app/components/flowbite/input_field/checkbox.html.erb
59
+ - app/components/flowbite/input_field/checkbox.rb
60
+ - app/components/flowbite/input_field/date.rb
61
+ - app/components/flowbite/input_field/email.rb
62
+ - app/components/flowbite/input_field/file.rb
63
+ - app/components/flowbite/input_field/input_field.html.erb
64
+ - app/components/flowbite/input_field/number.rb
65
+ - app/components/flowbite/input_field/password.rb
66
+ - app/components/flowbite/input_field/phone.rb
67
+ - app/components/flowbite/input_field/radio_button.html.erb
68
+ - app/components/flowbite/input_field/radio_button.rb
69
+ - app/components/flowbite/input_field/select.rb
70
+ - app/components/flowbite/input_field/text.rb
71
+ - app/components/flowbite/input_field/textarea.rb
72
+ - app/components/flowbite/input_field/url.rb
73
+ - app/components/flowbite/style.rb
74
+ - lib/flowbite/components.rb
75
+ - lib/flowbite/components/engine.rb
76
+ - lib/flowbite/components/version.rb
77
+ homepage: https://github.com/substancelab/flowbite-components
40
78
  licenses: []
41
79
  metadata:
42
80
  allowed_push_host: https://rubygems.org/
43
- homepage_uri: https://github.com/substancelab/flowbite-view_components
44
- source_code_uri: https://github.com/substancelab/flowbite-view_components
45
- changelog_uri: https://github.com/substancelab/flowbite-view_components/blob/main/CHANGELOG.md
81
+ homepage_uri: https://github.com/substancelab/flowbite-components
82
+ source_code_uri: https://github.com/substancelab/flowbite-components
83
+ changelog_uri: https://github.com/substancelab/flowbite-components/blob/main/CHANGELOG.md
46
84
  rdoc_options: []
47
85
  require_paths:
86
+ - app
48
87
  - lib
49
88
  required_ruby_version: !ruby/object:Gem::Requirement
50
89
  requirements:
@@ -59,5 +98,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
98
  requirements: []
60
99
  rubygems_version: 3.6.9
61
100
  specification_version: 4
62
- summary: Flowbite components for Rails applications
101
+ summary: ViewComponents using the Flowbite design system
63
102
  test_files: []