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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f32fb05b632e935c29d9f6a9a62fafa1d29ee13f80b9edf28040067a2a4fa54
4
- data.tar.gz: 59eda6515de3eba70480afc5cea58687eaddaa453f8db7949ab5ae2f67288862
3
+ metadata.gz: 2641783b14422d1a71ae1bc126308ce749e54ab33971baa9f2c590e7368a3d18
4
+ data.tar.gz: 919b625a46a74adafea39e617906d3da0c79f44876aaaba80c202fbae6ad9f0a
5
5
  SHA512:
6
- metadata.gz: 1e00a5308ab23bc68e6946fb6c068f01e91773c6dc3b37454fb5057d9b35268303001ba6135a4c77d746006dea9ebafa8962e34dab14e8ff9b511533272bbd3a
7
- data.tar.gz: 2626ad66e9db0b6f910b0ea879464216da51a21cc6c31b5218746fdd84fd5fccbd3c350f60a0224cbdc833ee47cd4f64b5624b9e63aee18a73e3dda389ab0400
6
+ metadata.gz: 436530353e5ae17c78af2a1d84a3125677d4fbc23a66191ff3b355f205a65307ddbc908d5c53dccef5806bd4151d6f6842f5e53f2079290179b37b96585940d5
7
+ data.tar.gz: 9031664132054b141c7937dfa0794cde6924c86907d0b3c544364f101b1937de5700f86cf89f6350bb159769be35095e3f3cf59572521052941b0f1f4f922155
data/CHANGELOG.md CHANGED
@@ -7,15 +7,30 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  ### Added
9
9
 
10
- * Button component (first component, wee!)
11
- * Input components
12
- * InputField components
13
- * Basic Card component
10
+ *
14
11
 
15
- ### Changes
12
+ ### Changed
16
13
 
17
14
  *
18
15
 
19
16
  ### Removed
20
17
 
21
18
  *
19
+
20
+
21
+ ## [0.1.3]
22
+
23
+ ### Added
24
+
25
+ * Options to Flowbite::InputField::Checkbox and Flowbite::Input::Checkbox that allow you to change the submitted value.
26
+ * Options added for Flowbite::Input::Select - :multiple and :include_blank. These can now be passed to either the input itself or Flowbite::InputField::Select
27
+
28
+
29
+ ## [0.1.2]
30
+
31
+ ### Added
32
+
33
+ * Button component (first component, wee!)
34
+ * Input components
35
+ * InputField components
36
+ * Basic Card component
data/README.md CHANGED
@@ -242,11 +242,12 @@ bundle exec rake install
242
242
 
243
243
  ### Component Previews
244
244
 
245
- This library includes Lookbook previews for all components. To view them:
245
+ This library includes a demo application with previews for all components. To view them:
246
246
 
247
- 1. Add Lookbook to your development dependencies
248
- 2. Run `rails server`
249
- 3. Visit `/rails/lookbook`
247
+ 1. cd demo
248
+ 2. Run `bundle && npm install`
249
+ 3. Run `rails server`
250
+ 4. Visit `http://localhost:3000/rails/lookbook`
250
251
 
251
252
  ## Contributing
252
253
 
@@ -0,0 +1,2 @@
1
+ /* Make sure Tailwind doens't prune our classes away */
2
+ @source "../../../components"
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Button
5
+ class Outline < Flowbite::Button
6
+ class << self
7
+ # rubocop:disable Layout/LineLength
8
+ def styles
9
+ {
10
+ default: Flowbite::Style.new(
11
+ default: ["text-blue-700", "hover:text-white", "border", "border-blue-700", "hover:bg-blue-800", "focus:ring-4", "focus:outline-none", "focus:ring-blue-300", "font-medium", "rounded-lg", "text-center", "me-2", "mb-2", "dark:border-blue-500", "dark:text-blue-500", "dark:hover:text-white", "dark:hover:bg-blue-500", "dark:focus:ring-blue-800"]
12
+ ),
13
+ green: Flowbite::Style.new(
14
+ default: ["text-green-700", "hover:text-white", "border", "border-green-700", "hover:bg-green-800", "focus:ring-4", "focus:outline-none", "focus:ring-green-300", "font-medium", "rounded-lg", "text-center", "me-2", "mb-2", "dark:border-green-500", "dark:text-green-500", "dark:hover:text-white", "dark:hover:bg-green-600", "dark:focus:ring-green-800"]
15
+ )
16
+ }
17
+ end
18
+ # rubocop:enable Layout/LineLength
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ class Button
5
+ class Pill < Flowbite::Button
6
+ class << self
7
+ # rubocop:disable Layout/LineLength, Metrics/MethodLength
8
+ def styles
9
+ {
10
+ alternative: Flowbite::Style.new(
11
+ default: ["text-sm", "font-medium", "text-gray-900", "focus:outline-none", "bg-white", "rounded-full", "border", "border-gray-200", "hover:bg-gray-100", "hover:text-blue-700", "focus:z-10", "focus:ring-4", "focus:ring-gray-100", "dark:focus:ring-gray-700", "dark:bg-gray-800", "dark:text-gray-400", "dark:border-gray-600", "dark:hover:text-white", "dark:hover:bg-gray-700"]
12
+ ),
13
+ dark: Flowbite::Style.new(
14
+ default: ["text-white", "bg-gray-800", "hover:bg-gray-900", "focus:outline-none", "focus:ring-4", "focus:ring-gray-300", "font-medium", "rounded-full", "dark:bg-gray-800", "dark:hover:bg-gray-700", "dark:focus:ring-gray-700", "dark:border-gray-700"]
15
+ ),
16
+ default: Flowbite::Style.new(
17
+ default: ["text-white", "bg-blue-700", "hover:bg-blue-800", "focus:outline-none", "focus:ring-4", "focus:ring-blue-300", "font-medium", "rounded-full", "text-center", "dark:bg-blue-600", "dark:hover:bg-blue-700", "dark:focus:ring-blue-800"]
18
+ ),
19
+ green: Flowbite::Style.new(
20
+ default: ["text-white", "bg-green-700", "hover:bg-green-800", "focus:outline-none", "focus:ring-4", "focus:ring-green-300", "font-medium", "rounded-full", "text-center", "dark:bg-green-600", "dark:hover:bg-green-700", "dark:focus:ring-green-800"]
21
+ ),
22
+ light: Flowbite::Style.new(
23
+ default: ["text-gray-900", "bg-white", "border", "border-gray-300", "focus:outline-none", "hover:bg-gray-100", "focus:ring-4", "focus:ring-gray-100", "font-medium", "rounded-full", "dark:bg-gray-800", "dark:text-white", "dark:border-gray-600", "dark:hover:bg-gray-700", "dark:hover:border-gray-600", "dark:focus:ring-gray-700"]
24
+ ),
25
+ purple: Flowbite::Style.new(
26
+ default: ["text-white", "bg-purple-700", "hover:bg-purple-800", "focus:outline-none", "focus:ring-4", "focus:ring-purple-300", "font-medium", "rounded-full", "text-center", "dark:bg-purple-600", "dark:hover:bg-purple-700", "dark:focus:ring-purple-900"]
27
+ ),
28
+ red: Flowbite::Style.new(
29
+ default: ["text-white", "bg-red-700", "hover:bg-red-800", "focus:outline-none", "focus:ring-4", "focus:ring-red-300", "font-medium", "rounded-full", "text-center", "dark:bg-red-600", "dark:hover:bg-red-700", "dark:focus:ring-red-900"]
30
+ ),
31
+ yellow: Flowbite::Style.new(
32
+ default: ["text-white", "bg-yellow-400", "hover:bg-yellow-500", "focus:outline-none", "focus:ring-4", "focus:ring-yellow-300", "font-medium", "rounded-full", "text-center", "dark:focus:ring-yellow-900"]
33
+ )
34
+ }
35
+ end
36
+ # rubocop:enable Layout/LineLength, Metrics/MethodLength
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ # Renders a HTML button element.
5
+ #
6
+ # See https://flowbite.com/docs/components/buttons/
7
+ #
8
+ # @param label [String] The text to display on the button.
9
+ #
10
+ # All other parameters are optional and are passed directly to the button tag
11
+ # as HTML attributes.
12
+ class Button < ViewComponent::Base
13
+ SIZES = {
14
+ xs: ["text-xs", "px-3", "py-2"],
15
+ sm: ["text-sm", "px-3", "py-2"],
16
+ default: ["text-sm", "px-5", "py-2.5"],
17
+ lg: ["text-base", "px-5", "py-3"],
18
+ xl: ["text-base", "px-6", "py-3.5"]
19
+ }.freeze
20
+
21
+ class << self
22
+ def classes(size: :default, state: :default, style: :default)
23
+ style = styles.fetch(style)
24
+ classes = style.fetch(state)
25
+ classes + sizes.fetch(size)
26
+ end
27
+
28
+ def sizes
29
+ SIZES
30
+ end
31
+
32
+ # rubocop:disable Layout/LineLength
33
+ def styles
34
+ {
35
+ alternative: Flowbite::Style.new(
36
+ default: ["font-medium", "text-gray-900", "focus:outline-none", "bg-white", "rounded-lg", "border", "border-gray-200", "hover:bg-gray-100", "hover:text-blue-700", "focus:z-10", "focus:ring-4", "focus:ring-gray-100", "dark:focus:ring-gray-700", "dark:bg-gray-800", "dark:text-gray-400", "dark:border-gray-600", "dark:hover:text-white", "dark:hover:bg-gray-700"]
37
+ ),
38
+ dark: Flowbite::Style.new(
39
+ default: ["text-white", "bg-gray-800", "hover:bg-gray-900", "focus:ring-4", "focus:ring-gray-300", "font-medium", "rounded-lg", "dark:bg-gray-800", "dark:hover:bg-gray-700", "dark:focus:ring-gray-700", "dark:border-gray-700"]
40
+ ),
41
+ default: Flowbite::Style.new(
42
+ default: ["text-white", "bg-blue-700", "hover:bg-blue-800", "focus:ring-4", "focus:ring-blue-300", "font-medium", "rounded-lg", "dark:bg-blue-600", "dark:hover:bg-blue-700", "focus:outline-none", "dark:focus:ring-blue-800"]
43
+ ),
44
+ green: Flowbite::Style.new(
45
+ default: ["focus:outline-none", "text-white", "bg-green-700", "hover:bg-green-800", "focus:ring-4", "focus:ring-green-300", "font-medium", "rounded-lg", "dark:bg-green-600", "dark:hover:bg-green-700", "dark:focus:ring-green-800"]
46
+ ),
47
+ light: Flowbite::Style.new(
48
+ default: ["text-gray-900", "bg-white", "border", "border-gray-300", "hover:bg-gray-100", "focus:ring-4", "focus:ring-gray-100", "font-medium", "rounded-lg", "dark:bg-gray-800", "dark:text-white", "dark:border-gray-600", "dark:hover:bg-gray-700", "dark:hover:border-gray-600", "dark:focus:ring-gray-700"]
49
+ ),
50
+ purple: Flowbite::Style.new(
51
+ default: ["focus:outline-none", "text-white", "bg-purple-700", "hover:bg-purple-800", "focus:ring-4", "focus:ring-purple-300", "font-medium", "rounded-lg", "dark:bg-purple-600", "dark:hover:bg-purple-700", "dark:focus:ring-purple-900"]
52
+ ),
53
+ red: Flowbite::Style.new(
54
+ default: ["focus:outline-none", "text-white", "bg-red-700", "hover:bg-red-800", "focus:ring-4", "focus:ring-red-300", "font-medium", "rounded-lg", "dark:bg-red-600", "dark:hover:bg-red-700", "dark:focus:ring-red-900"]
55
+ ),
56
+ yellow: Flowbite::Style.new(
57
+ default: ["focus:outline-none", "text-white", "bg-yellow-400", "hover:bg-yellow-500", "focus:ring-4", "focus:ring-yellow-300", "font-medium", "rounded-lg", "dark:focus:ring-yellow-900"]
58
+ )
59
+ }.freeze
60
+ end
61
+ # rubocop:enable Layout/LineLength
62
+ end
63
+
64
+ attr_reader :button_attributes, :size, :style
65
+
66
+ def initialize(size: :default, style: :default, **button_attributes)
67
+ @size = size
68
+ @style = style
69
+ @button_attributes = button_attributes
70
+ end
71
+
72
+ def call
73
+ content_tag(
74
+ :button,
75
+ content,
76
+ **options
77
+ )
78
+ end
79
+
80
+ private
81
+
82
+ def classes
83
+ self.class.classes(size: size, state: :default, style: style)
84
+ end
85
+
86
+ def options
87
+ {
88
+ class: classes
89
+ }.merge(button_attributes)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ # Renders a card element.
5
+ #
6
+ # See https://flowbite.com/docs/components/cards/
7
+ class Card < ViewComponent::Base
8
+ class << self
9
+ def classes(state: :default, style: :default)
10
+ style = styles.fetch(style)
11
+ style.fetch(state)
12
+ end
13
+
14
+ # rubocop:disable Layout/LineLength
15
+ def styles
16
+ {
17
+ default: Flowbite::Style.new(
18
+ default: ["p-6", "bg-white", "border", "border-gray-200", "rounded-lg", "shadow-sm", "dark:bg-gray-800", "dark:border-gray-700"]
19
+ )
20
+ }.freeze
21
+ end
22
+ # rubocop:enable Layout/LineLength
23
+ end
24
+
25
+ def call
26
+ card_options = {}
27
+ card_options[:class] = self.class.classes + @class
28
+
29
+ content_tag(:div, card_options.merge(@options)) do
30
+ concat(content_tag(:div, content, class: "font-normal text-gray-700 dark:text-gray-400"))
31
+ end
32
+ end
33
+
34
+ # @param class [Array<String>] Additional CSS classes for the card
35
+ # container.
36
+ #
37
+ # @param options [Hash] Additional HTML options for the card container
38
+ # (e.g., custom classes, data attributes). These options are merged into
39
+ # the card's root element.
40
+ def initialize(class: [], options: {})
41
+ @class = Array(binding.local_variable_get(:class)) || []
42
+ @options = options || {}
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ # The checkbox component can be used to receive one or more selected options
6
+ # from the user in the form of a square box available in multiple styles,
7
+ # sizes, colors, and variants coded with the utility classes from Tailwind
8
+ # CSS and with support for dark mode.
9
+ #
10
+ # https://flowbite.com/docs/forms/checkbox/
11
+ class Checkbox < Field
12
+ DEFAULT_CHECKED_VALUE = "1"
13
+ DEFAULT_UNCHECKED_VALUE = "0"
14
+
15
+ class << self
16
+ # Checkboxes only have their default size.
17
+ def sizes
18
+ {
19
+ default: ["w-4", "h-4"]
20
+ }
21
+ end
22
+
23
+ # rubocop:disable Layout/LineLength
24
+ def styles
25
+ {
26
+ default: Flowbite::Style.new(
27
+ default: ["text-blue-600", "bg-gray-100", "border-gray-300", "rounded-sm", "focus:ring-blue-500", "dark:focus:ring-blue-600", "dark:ring-offset-gray-800", "focus:ring-2", "dark:bg-gray-700", "dark:border-gray-600"],
28
+ disabled: ["text-blue-600", "bg-gray-100", "border-gray-300", "rounded-sm", "focus:ring-blue-500", "dark:focus:ring-blue-600", "dark:ring-offset-gray-800", "focus:ring-2", "dark:bg-gray-700", "dark:border-gray-600"],
29
+ error: ["text-red-600", "bg-red-50", "border-red-500", "rounded-sm", "focus:ring-red-500", "dark:focus:ring-red-600", "dark:ring-offset-gray-800", "focus:ring-2", "dark:bg-gray-700", "dark:border-red-500"]
30
+ )
31
+ }.freeze
32
+ end
33
+ end
34
+
35
+ # Returns the HTML to use for the actual input field element.
36
+ def call
37
+ @form.send(
38
+ input_field_type,
39
+ @attribute,
40
+ input_options,
41
+ checked_value,
42
+ unchecked_value
43
+ )
44
+ end
45
+
46
+ def initialize(attribute:, form:, disabled: false, options: {}, size: :default, unchecked_value: DEFAULT_UNCHECKED_VALUE, value: DEFAULT_CHECKED_VALUE)
47
+ super(attribute: attribute, form: form, disabled: disabled, options: options, size: size)
48
+ @unchecked_value = unchecked_value
49
+ @value = value
50
+ end
51
+
52
+ def input_field_type
53
+ :check_box
54
+ end
55
+
56
+ # Returns the options argument for the input field
57
+ def input_options
58
+ {
59
+ class: classes,
60
+ disabled: disabled?
61
+ }.merge(options)
62
+ end
63
+
64
+ private
65
+
66
+ def checked_value
67
+ @value
68
+ end
69
+
70
+ attr_reader :unchecked_value
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ class Date < Field
6
+ def input_field_type
7
+ :date_field
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ class Email < Field
6
+ # Returns the name of the method used to generate HTML for the input field
7
+ def input_field_type
8
+ :email_field
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ # The indivdual input component for use in forms without labels or error
6
+ # messages.
7
+ #
8
+ # Use this when you want to render an input field on its own without any
9
+ # surrounding elements, ie as a building block in more complex input
10
+ # components.
11
+ #
12
+ # To render a complete input field with labels and error messages, use
13
+ # `Flowbite::InputField` instead.
14
+ class Field < ViewComponent::Base
15
+ SIZES = {
16
+ sm: ["p-2", "text-xs"],
17
+ default: ["p-2.5", "text-sm"],
18
+ lg: ["p-4", "text-base"]
19
+ }.freeze
20
+
21
+ STATES = [
22
+ DEFAULT = :default,
23
+ DISABLED = :disabled,
24
+ ERROR = :error
25
+ ].freeze
26
+
27
+ attr_reader :options, :size, :style
28
+
29
+ class << self
30
+ def classes(size: :default, state: :default, style: :default)
31
+ style = styles.fetch(style)
32
+ state_classes = style.fetch(state)
33
+ state_classes + sizes.fetch(size)
34
+ end
35
+
36
+ # Returns the sizes this Field supports.
37
+ #
38
+ # This is effectively the SIZES constant, but provided as a method to
39
+ # return the constant from the current class, not the superclass.
40
+ #
41
+ # @return [Hash] A hash mapping size names to their corresponding CSS
42
+ # classes.
43
+ def sizes
44
+ const_get(:SIZES)
45
+ end
46
+
47
+ # rubocop:disable Layout/LineLength
48
+ def styles
49
+ {
50
+ default: Flowbite::Style.new(
51
+ default: ["bg-gray-50", "border", "border-gray-300", "text-gray-900", "rounded-lg", "focus:ring-blue-500", "focus:border-blue-500", "block", "w-full", "dark:bg-gray-700", "dark:border-gray-600", "dark:placeholder-gray-400", "dark:text-white", "dark:focus:ring-blue-500", "dark:focus:border-blue-500"],
52
+ disabled: ["bg-gray-100", "border", "border-gray-300", "text-gray-900", "text-sm", "rounded-lg", "focus:ring-blue-500", "focus:border-blue-500", "block", "w-full", "p-2.5", "cursor-not-allowed", "dark:bg-gray-700", "dark:border-gray-600", "dark:placeholder-gray-400", "dark:text-gray-400", "dark:focus:ring-blue-500", "dark:focus:border-blue-500"],
53
+ error: ["bg-red-50", "border", "border-red-500", "text-red-900", "placeholder-red-700", "rounded-lg", "focus:ring-red-500", "dark:bg-gray-700", "focus:border-red-500", "block", "w-full", "dark:text-red-500", "dark:placeholder-red-500", "dark:border-red-500"]
54
+ )
55
+ }.freeze
56
+ end
57
+ # rubocop:enable Layout/LineLength
58
+ end
59
+
60
+ def initialize(attribute:, form:, disabled: false, options: {}, size: :default)
61
+ @attribute = attribute
62
+ @disabled = disabled
63
+ @form = form
64
+ @options = options || {}
65
+ @object = form.object
66
+ @size = size
67
+ end
68
+
69
+ # Returns the HTML to use for the actual input field element.
70
+ def call
71
+ @form.send(
72
+ input_field_type,
73
+ @attribute,
74
+ **input_options
75
+ )
76
+ end
77
+
78
+ # Returns the CSS classes to apply to the input field
79
+ def classes
80
+ self.class.classes(size: size, state: state)
81
+ end
82
+
83
+ # Returns the name of the method used to generate HTML for the input field
84
+ def input_field_type
85
+ :text_field
86
+ end
87
+
88
+ protected
89
+
90
+ # Returns true if the field is disabled
91
+ def disabled?
92
+ !!@disabled
93
+ end
94
+
95
+ def errors?
96
+ @object.errors.include?(@attribute.intern)
97
+ end
98
+
99
+ private
100
+
101
+ # Returns the options argument for the input field
102
+ def input_options
103
+ {
104
+ class: classes,
105
+ disabled: disabled?
106
+ }.merge(options)
107
+ end
108
+
109
+ def state
110
+ return DISABLED if disabled?
111
+ return ERROR if errors?
112
+
113
+ DEFAULT
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ class File < Field
6
+ SIZES = {
7
+ sm: ["text-xs"],
8
+ default: ["text-sm"],
9
+ lg: ["text-lg"]
10
+ }.freeze
11
+
12
+ # Returns the name of the method used to generate HTML for the input field
13
+ def input_field_type
14
+ :file_field
15
+ end
16
+
17
+ # rubocop:disable Layout/LineLength
18
+ def self.styles
19
+ {
20
+ default: Flowbite::Style.new(
21
+ default: ["block", "w-full", "text-gray-900", "border", "border-gray-300", "rounded-lg", "cursor-pointer", "bg-gray-50", "focus:outline-none", "dark:text-gray-400", "dark:bg-gray-700", "dark:border-gray-600"],
22
+ disabled: ["block", "w-full", "text-gray-400", "border", "border-gray-300", "rounded-lg", "cursor-not-allowed", "bg-gray-100", "dark:text-gray-500", "dark:bg-gray-600", "dark:border-gray-500"],
23
+ error: ["block", "w-full", "text-red-900", "border", "border-red-500", "rounded-lg", "cursor-pointer", "bg-red-50", "focus:outline-none", "dark:text-red-400", "dark:bg-gray-700", "dark:border-red-500"]
24
+ )
25
+ }.freeze
26
+ end
27
+ # rubocop:enable Layout/LineLength
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ class Hint < ViewComponent::Base
6
+ STATES = [
7
+ DEFAULT = :default
8
+ ].freeze
9
+
10
+ class << self
11
+ def classes(state: :default, style: :default)
12
+ style = styles.fetch(style)
13
+ style.fetch(state)
14
+ end
15
+
16
+ def styles
17
+ {
18
+ default: Flowbite::Style.new(
19
+ default: ["mt-2", "text-sm", "text-gray-500", "dark:text-gray-400"]
20
+ )
21
+ }.freeze
22
+ end
23
+ end
24
+
25
+ def call
26
+ tag.p(
27
+ content,
28
+ class: classes,
29
+ **@options
30
+ )
31
+ end
32
+
33
+ def initialize(attribute:, form:, options: {})
34
+ @attribute = attribute
35
+ @form = form
36
+ @options = options
37
+ @object = form.object
38
+ end
39
+
40
+ # Returns an array with the CSS classes to apply to the label element
41
+ def classes
42
+ self.class.classes(state: state)
43
+ end
44
+
45
+ protected
46
+
47
+ # Returns the state of the label.
48
+ #
49
+ # See the STATES constant for valid values.
50
+ #
51
+ # @return [Symbol] the state of the label
52
+ def state
53
+ DEFAULT
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ # https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-label
6
+ class Label < ViewComponent::Base
7
+ STATES = [
8
+ DEFAULT = :default,
9
+ DISABLED = :disabled,
10
+ ERROR = :error
11
+ ].freeze
12
+
13
+ class << self
14
+ def classes(state: :default, style: :default)
15
+ style = styles.fetch(style)
16
+ style.fetch(state)
17
+ end
18
+
19
+ def styles
20
+ {
21
+ default: Flowbite::Style.new(
22
+ default: ["block", "mb-2", "text-sm", "font-medium", "text-gray-900", "dark:text-white"],
23
+ disabled: ["block", "mb-2", "text-sm", "font-medium", "text-gray-400", "dark:text-gray-500"],
24
+ error: ["block", "mb-2", "text-sm", "font-medium", "text-red-700", "dark:text-red-500"]
25
+ )
26
+ }.freeze
27
+ end
28
+ end
29
+
30
+ def call
31
+ if content?
32
+ @form.label(@attribute, content, **options)
33
+ else
34
+ @form.label(@attribute, **options)
35
+ end
36
+ end
37
+
38
+ def errors?
39
+ @object.errors.include?(@attribute.intern)
40
+ end
41
+
42
+ def initialize(attribute:, form:, disabled: false, options: {})
43
+ @attribute = attribute
44
+ @disabled = disabled
45
+ @form = form
46
+ @object = form.object
47
+ @options = options
48
+ end
49
+
50
+ # Returns an array with the CSS classes to apply to the label element
51
+ def classes
52
+ self.class.classes(state: state)
53
+ end
54
+
55
+ protected
56
+
57
+ def disabled?
58
+ !!@disabled
59
+ end
60
+
61
+ # Returns the state of the label.
62
+ #
63
+ # See the STATES constant for valid values.
64
+ #
65
+ # @return [Symbol] the state of the label
66
+ def state
67
+ return DISABLED if disabled?
68
+ return ERROR if errors?
69
+
70
+ DEFAULT
71
+ end
72
+
73
+ private
74
+
75
+ def options
76
+ {
77
+ class: classes
78
+ }.merge(@options)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flowbite
4
+ module Input
5
+ class Number < Field
6
+ def input_field_type
7
+ :number_field
8
+ end
9
+ end
10
+ end
11
+ end