flowbite-components 0.1.1 → 0.1.3

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -5
  3. data/README.md +5 -4
  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 +45 -0
  9. data/app/components/flowbite/input/checkbox.rb +73 -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 +58 -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 +54 -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 +86 -0
  35. data/app/components/flowbite/input_field/select.rb +35 -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 +192 -0
  40. data/app/components/flowbite/style.rb +13 -0
  41. data/lib/flowbite/components/version.rb +1 -1
  42. metadata +39 -1
@@ -0,0 +1,192 @@
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(**input_arguments))
138
+ end
139
+
140
+ def default_label
141
+ component = Flowbite::Input::Label.new(**default_label_options)
142
+ if default_label_content
143
+ component.with_content(default_label_content)
144
+ else
145
+ component
146
+ end
147
+ end
148
+
149
+ def default_label_content
150
+ @label[:content]
151
+ end
152
+
153
+ def default_label_options
154
+ label_options = @label.dup
155
+ label_options.delete(:content)
156
+
157
+ {
158
+ attribute: @attribute,
159
+ form: @form
160
+ }.merge(label_options)
161
+ end
162
+
163
+ # Returns true if the input field is disabled, false otherwise.
164
+ def disabled?
165
+ !!@disabled
166
+ end
167
+
168
+ # Returns true if the input field has a hint, false otherwise.
169
+ def hint?
170
+ @hint.present?
171
+ end
172
+
173
+ def id_for_hint_element
174
+ "#{@form.object_name}_#{@attribute}_hint"
175
+ end
176
+
177
+ # @return [Hash] The keyword arguments for the input component.
178
+ def input_arguments
179
+ {
180
+ attribute: @attribute,
181
+ disabled: @disabled,
182
+ form: @form,
183
+ options: input_options,
184
+ size: @size
185
+ }
186
+ end
187
+
188
+ def input_options
189
+ default_input_options.merge(@input[:options] || {})
190
+ end
191
+ end
192
+ 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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Flowbite
4
4
  module Components
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Skjerning
@@ -34,6 +34,43 @@ files:
34
34
  - CHANGELOG.md
35
35
  - LICENSE
36
36
  - README.md
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
37
74
  - lib/flowbite/components.rb
38
75
  - lib/flowbite/components/engine.rb
39
76
  - lib/flowbite/components/version.rb
@@ -46,6 +83,7 @@ metadata:
46
83
  changelog_uri: https://github.com/substancelab/flowbite-components/blob/main/CHANGELOG.md
47
84
  rdoc_options: []
48
85
  require_paths:
86
+ - app
49
87
  - lib
50
88
  required_ruby_version: !ruby/object:Gem::Requirement
51
89
  requirements: