flowbite-components 0.1.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afc7f639fa9f28b2310d7f68cd3d8939e3eaa526ba80ee028c471664597e4581
4
- data.tar.gz: 1b4e73f0bd471b9b3d36db8aba2e614e28f5573cbf7fd214de360a985767eade
3
+ metadata.gz: 2641783b14422d1a71ae1bc126308ce749e54ab33971baa9f2c590e7368a3d18
4
+ data.tar.gz: 919b625a46a74adafea39e617906d3da0c79f44876aaaba80c202fbae6ad9f0a
5
5
  SHA512:
6
- metadata.gz: 6d56824ba5b7d0c13bca6b31e4dac90a1859ec35c3c50478b90a4f67aae2cd7e7efcfb53dc29ddfcae9f4839695610ea5602e0f29b2ddd53c64a00b34562806d
7
- data.tar.gz: efe21d27318e44196ecd0024663a143ba577ab8b2ca0a2b9e085263d4be3d7f472c22c68c5442d802c58717306a575d320325c4d9d8bb3d5f8b5e48fb444c992
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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Flowbite
2
4
  # Renders a card element.
3
5
  #
@@ -9,6 +9,9 @@ module Flowbite
9
9
  #
10
10
  # https://flowbite.com/docs/forms/checkbox/
11
11
  class Checkbox < Field
12
+ DEFAULT_CHECKED_VALUE = "1"
13
+ DEFAULT_UNCHECKED_VALUE = "0"
14
+
12
15
  class << self
13
16
  # Checkboxes only have their default size.
14
17
  def sizes
@@ -29,9 +32,42 @@ module Flowbite
29
32
  end
30
33
  end
31
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
+
32
52
  def input_field_type
33
53
  :check_box
34
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
35
71
  end
36
72
  end
37
73
  end
@@ -14,9 +14,11 @@ module Flowbite
14
14
  lg: ["px-4", "py-3", "text-base"]
15
15
  }.freeze
16
16
 
17
- def initialize(form:, attribute:, collection: [], disabled: false, options: {}, size: :default)
17
+ def initialize(form:, attribute:, collection: [], disabled: false, include_blank: false, multiple: false, options: {}, size: :default)
18
18
  super(form: form, attribute: attribute, disabled: disabled, options: options, size: size)
19
19
  @collection = collection
20
+ @include_blank = include_blank
21
+ @multiple = multiple
20
22
  end
21
23
 
22
24
  # Returns the HTML to use for the actual input field element.
@@ -25,7 +27,7 @@ module Flowbite
25
27
  input_field_type,
26
28
  @attribute,
27
29
  @collection,
28
- {},
30
+ select_options,
29
31
  html_options
30
32
  )
31
33
  end
@@ -37,6 +39,13 @@ module Flowbite
37
39
 
38
40
  private
39
41
 
42
+ def select_options
43
+ {
44
+ include_blank: @include_blank,
45
+ multiple: @multiple
46
+ }
47
+ end
48
+
40
49
  # Returns the html_options argument for the select method
41
50
  def html_options
42
51
  {
@@ -5,12 +5,6 @@ module Flowbite
5
5
  class Checkbox < InputField
6
6
  protected
7
7
 
8
- def input_component
9
- ::Flowbite::Input::Checkbox
10
- end
11
-
12
- protected
13
-
14
8
  def default_hint_options
15
9
  return {} unless @hint
16
10
 
@@ -27,6 +21,10 @@ module Flowbite
27
21
  options
28
22
  end
29
23
 
24
+ def input_component
25
+ ::Flowbite::Input::Checkbox
26
+ end
27
+
30
28
  private
31
29
 
32
30
  def hint_classes
@@ -37,6 +35,13 @@ module Flowbite
37
35
  end
38
36
  end
39
37
 
38
+ def input_arguments
39
+ args = super
40
+ args[:unchecked_value] = @input[:unchecked_value] if @input.key?(:unchecked_value)
41
+ args[:value] = @input[:value] if @input.key?(:value)
42
+ args
43
+ end
44
+
40
45
  def label_classes
41
46
  if disabled?
42
47
  "font-medium text-gray-400 dark:text-gray-500"
@@ -3,17 +3,11 @@
3
3
  module Flowbite
4
4
  class InputField
5
5
  class RadioButton < InputField
6
- protected
7
-
8
6
  def initialize(attribute:, form:, value:, disabled: false, hint: nil, input: {}, label: {})
9
7
  super(attribute: attribute, form: form, disabled: disabled, hint: hint, input: input, label: label)
10
8
  @value = value
11
9
  end
12
10
 
13
- def input_component
14
- ::Flowbite::Input::RadioButton
15
- end
16
-
17
11
  protected
18
12
 
19
13
  def default_input
@@ -54,6 +48,10 @@ module Flowbite
54
48
  render(component)
55
49
  end
56
50
 
51
+ def input_component
52
+ ::Flowbite::Input::RadioButton
53
+ end
54
+
57
55
  private
58
56
 
59
57
  def hint_classes
@@ -3,9 +3,11 @@
3
3
  module Flowbite
4
4
  class InputField
5
5
  class Select < InputField
6
- def initialize(attribute:, form:, collection: [], disabled: false, hint: nil, input: {}, label: {}, size: :default)
6
+ def initialize(attribute:, form:, collection: [], disabled: false, hint: nil, include_blank: false, input: {}, label: {}, multiple: false, size: :default)
7
7
  super(attribute: attribute, disabled: disabled, form: form, hint: hint, input: input, label: label, size: size)
8
8
  @collection = collection
9
+ @include_blank = include_blank
10
+ @multiple = multiple
9
11
  end
10
12
 
11
13
  def input
@@ -15,6 +17,8 @@ module Flowbite
15
17
  collection: @collection,
16
18
  disabled: @disabled,
17
19
  form: @form,
20
+ include_blank: @include_blank,
21
+ multiple: @multiple,
18
22
  options: input_options,
19
23
  size: @size
20
24
  )
@@ -134,13 +134,7 @@ module Flowbite
134
134
 
135
135
  # Returns the HTML to use for the default input element.
136
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
- ))
137
+ render(input_component.new(**input_arguments))
144
138
  end
145
139
 
146
140
  def default_label
@@ -180,6 +174,17 @@ module Flowbite
180
174
  "#{@form.object_name}_#{@attribute}_hint"
181
175
  end
182
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
+
183
188
  def input_options
184
189
  default_input_options.merge(@input[:options] || {})
185
190
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Flowbite
4
4
  module Components
5
- VERSION = "0.1.2"
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Skjerning