flowbite-components 0.1.2 → 0.1.4
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 +4 -4
- data/CHANGELOG.md +35 -7
- data/README.md +39 -9
- data/app/components/flowbite/button/outline.rb +25 -10
- data/app/components/flowbite/button/pill.rb +26 -26
- data/app/components/flowbite/button.rb +33 -30
- data/app/components/flowbite/card/card.html.erb +7 -0
- data/app/components/flowbite/card/title.rb +39 -0
- data/app/components/flowbite/card.rb +58 -15
- data/app/components/flowbite/input/checkbox.rb +45 -7
- data/app/components/flowbite/input/field.rb +21 -12
- data/app/components/flowbite/input/file.rb +11 -9
- data/app/components/flowbite/input/hint.rb +10 -7
- data/app/components/flowbite/input/label.rb +14 -9
- data/app/components/flowbite/input/radio_button.rb +11 -9
- data/app/components/flowbite/input/select.rb +15 -6
- data/app/components/flowbite/input/textarea.rb +11 -9
- data/app/components/flowbite/input/validation_error.rb +31 -1
- data/app/components/flowbite/input_field/checkbox.html.erb +2 -4
- data/app/components/flowbite/input_field/checkbox.rb +17 -8
- data/app/components/flowbite/input_field/input_field.html.erb +1 -1
- data/app/components/flowbite/input_field/radio_button.html.erb +2 -4
- data/app/components/flowbite/input_field/radio_button.rb +14 -12
- data/app/components/flowbite/input_field/select.rb +5 -1
- data/app/components/flowbite/input_field.rb +38 -9
- data/app/components/flowbite/link.rb +41 -0
- data/app/components/flowbite/styles.rb +34 -0
- data/lib/flowbite/components/version.rb +1 -1
- metadata +5 -1
|
@@ -13,9 +13,9 @@ module Flowbite
|
|
|
13
13
|
# `Flowbite::InputField` instead.
|
|
14
14
|
class Field < ViewComponent::Base
|
|
15
15
|
SIZES = {
|
|
16
|
-
sm: ["
|
|
17
|
-
default: ["
|
|
18
|
-
lg: ["
|
|
16
|
+
sm: ["px-2.5", "py-2", "text-sm"],
|
|
17
|
+
default: ["px-3", "py-2.5", "text-sm"],
|
|
18
|
+
lg: ["px-3.5", "py-3", "text-base"]
|
|
19
19
|
}.freeze
|
|
20
20
|
|
|
21
21
|
STATES = [
|
|
@@ -46,19 +46,22 @@ module Flowbite
|
|
|
46
46
|
|
|
47
47
|
# rubocop:disable Layout/LineLength
|
|
48
48
|
def styles
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
default:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
Flowbite::Styles.from_hash(
|
|
50
|
+
{
|
|
51
|
+
default: {
|
|
52
|
+
default: ["bg-neutral-secondary-medium", "border", "border-default-medium", "text-heading", "rounded-base", "focus:ring-brand", "focus:border-brand", "block", "w-full", "shadow-xs", "placeholder:text-body"],
|
|
53
|
+
disabled: ["bg-neutral-secondary-medium", "border", "border-default-medium", "text-fg-disabled", "rounded-base", "focus:ring-brand", "focus:border-brand", "block", "w-full", "shadow-xs", "cursor-not-allowed", "placeholder:text-fg-disabled"],
|
|
54
|
+
error: ["bg-danger-soft", "border", "border-danger-subtle", "text-fg-danger-strong", "rounded-base", "focus:ring-danger", "focus:border-danger", "block", "w-full", "shadow-xs", "placeholder:text-fg-danger-strong"]
|
|
55
|
+
}
|
|
56
|
+
}.freeze
|
|
57
|
+
)
|
|
56
58
|
end
|
|
57
59
|
# rubocop:enable Layout/LineLength
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
def initialize(attribute:, form:, disabled: false, options: {}, size: :default)
|
|
62
|
+
def initialize(attribute:, form:, class: nil, disabled: false, options: {}, size: :default)
|
|
61
63
|
@attribute = attribute
|
|
64
|
+
@class = Array.wrap(binding.local_variable_get(:class))
|
|
62
65
|
@disabled = disabled
|
|
63
66
|
@form = form
|
|
64
67
|
@options = options || {}
|
|
@@ -77,7 +80,7 @@ module Flowbite
|
|
|
77
80
|
|
|
78
81
|
# Returns the CSS classes to apply to the input field
|
|
79
82
|
def classes
|
|
80
|
-
self.class.classes(size: size, state: state)
|
|
83
|
+
self.class.classes(size: size, state: state) + @class
|
|
81
84
|
end
|
|
82
85
|
|
|
83
86
|
# Returns the name of the method used to generate HTML for the input field
|
|
@@ -92,7 +95,13 @@ module Flowbite
|
|
|
92
95
|
!!@disabled
|
|
93
96
|
end
|
|
94
97
|
|
|
98
|
+
# Returns true if the object has errors. Returns false if there is no
|
|
99
|
+
# object.
|
|
100
|
+
#
|
|
101
|
+
# @return [Boolean] true if there are errors, false otherwise.
|
|
95
102
|
def errors?
|
|
103
|
+
return false unless @object
|
|
104
|
+
|
|
96
105
|
@object.errors.include?(@attribute.intern)
|
|
97
106
|
end
|
|
98
107
|
|
|
@@ -4,9 +4,9 @@ module Flowbite
|
|
|
4
4
|
module Input
|
|
5
5
|
class File < Field
|
|
6
6
|
SIZES = {
|
|
7
|
-
sm: ["text-
|
|
7
|
+
sm: ["text-sm"],
|
|
8
8
|
default: ["text-sm"],
|
|
9
|
-
lg: ["text-
|
|
9
|
+
lg: ["text-base"]
|
|
10
10
|
}.freeze
|
|
11
11
|
|
|
12
12
|
# Returns the name of the method used to generate HTML for the input field
|
|
@@ -16,13 +16,15 @@ module Flowbite
|
|
|
16
16
|
|
|
17
17
|
# rubocop:disable Layout/LineLength
|
|
18
18
|
def self.styles
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
default:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
Flowbite::Styles.from_hash(
|
|
20
|
+
{
|
|
21
|
+
default: {
|
|
22
|
+
default: ["block", "w-full", "text-heading", "border", "border-default-medium", "rounded-base", "cursor-pointer", "bg-neutral-secondary-medium", "focus:outline-none"],
|
|
23
|
+
disabled: ["block", "w-full", "text-fg-disabled", "border", "border-default-medium", "rounded-base", "cursor-not-allowed", "bg-neutral-secondary-medium"],
|
|
24
|
+
error: ["block", "w-full", "text-fg-danger-strong", "border", "border-danger-subtle", "rounded-base", "cursor-pointer", "bg-danger-soft", "focus:outline-none"]
|
|
25
|
+
}
|
|
26
|
+
}.freeze
|
|
27
|
+
)
|
|
26
28
|
end
|
|
27
29
|
# rubocop:enable Layout/LineLength
|
|
28
30
|
end
|
|
@@ -14,11 +14,13 @@ module Flowbite
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def styles
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
default:
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
Flowbite::Styles.from_hash(
|
|
18
|
+
{
|
|
19
|
+
default: {
|
|
20
|
+
default: ["mt-2.5", "text-sm", "text-body"]
|
|
21
|
+
}
|
|
22
|
+
}.freeze
|
|
23
|
+
)
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
@@ -30,8 +32,9 @@ module Flowbite
|
|
|
30
32
|
)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
def initialize(attribute:, form:, options: {})
|
|
35
|
+
def initialize(attribute:, form:, class: nil, options: {})
|
|
34
36
|
@attribute = attribute
|
|
37
|
+
@class = Array.wrap(binding.local_variable_get(:class))
|
|
35
38
|
@form = form
|
|
36
39
|
@options = options
|
|
37
40
|
@object = form.object
|
|
@@ -39,7 +42,7 @@ module Flowbite
|
|
|
39
42
|
|
|
40
43
|
# Returns an array with the CSS classes to apply to the label element
|
|
41
44
|
def classes
|
|
42
|
-
self.class.classes(state: state)
|
|
45
|
+
self.class.classes(state: state) + @class
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
protected
|
|
@@ -17,13 +17,15 @@ module Flowbite
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def styles
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
default:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
Flowbite::Styles.from_hash(
|
|
21
|
+
{
|
|
22
|
+
default: {
|
|
23
|
+
default: ["block", "mb-2.5", "text-sm", "font-medium", "text-heading"],
|
|
24
|
+
disabled: ["block", "mb-2.5", "text-sm", "font-medium", "text-fg-disabled"],
|
|
25
|
+
error: ["block", "mb-2.5", "text-sm", "font-medium", "text-fg-danger-strong"]
|
|
26
|
+
}
|
|
27
|
+
}.freeze
|
|
28
|
+
)
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -36,11 +38,14 @@ module Flowbite
|
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def errors?
|
|
41
|
+
return false unless @object
|
|
42
|
+
|
|
39
43
|
@object.errors.include?(@attribute.intern)
|
|
40
44
|
end
|
|
41
45
|
|
|
42
|
-
def initialize(attribute:, form:, disabled: false, options: {})
|
|
46
|
+
def initialize(attribute:, form:, class: nil, disabled: false, options: {})
|
|
43
47
|
@attribute = attribute
|
|
48
|
+
@class = Array.wrap(binding.local_variable_get(:class))
|
|
44
49
|
@disabled = disabled
|
|
45
50
|
@form = form
|
|
46
51
|
@object = form.object
|
|
@@ -49,7 +54,7 @@ module Flowbite
|
|
|
49
54
|
|
|
50
55
|
# Returns an array with the CSS classes to apply to the label element
|
|
51
56
|
def classes
|
|
52
|
-
self.class.classes(state: state)
|
|
57
|
+
self.class.classes(state: state) + @class
|
|
53
58
|
end
|
|
54
59
|
|
|
55
60
|
protected
|
|
@@ -17,13 +17,15 @@ module Flowbite
|
|
|
17
17
|
|
|
18
18
|
# rubocop:disable Layout/LineLength
|
|
19
19
|
def styles
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
default:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
Flowbite::Styles.from_hash(
|
|
21
|
+
{
|
|
22
|
+
default: {
|
|
23
|
+
default: ["text-brand", "bg-neutral-secondary-medium", "border-default-medium", "focus:ring-brand", "focus:ring-2"],
|
|
24
|
+
disabled: ["text-brand", "bg-neutral-secondary-medium", "border-default-medium", "focus:ring-brand", "focus:ring-2", "cursor-not-allowed"],
|
|
25
|
+
error: ["text-danger", "bg-danger-soft", "border-danger-subtle", "focus:ring-danger", "focus:ring-2"]
|
|
26
|
+
}
|
|
27
|
+
}.freeze
|
|
28
|
+
)
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -37,8 +39,8 @@ module Flowbite
|
|
|
37
39
|
)
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
def initialize(attribute:, form:, value:, disabled: false, options: {})
|
|
41
|
-
super(attribute: attribute, disabled: disabled, form: form, options: options)
|
|
42
|
+
def initialize(attribute:, form:, value:, class: nil, disabled: false, options: {})
|
|
43
|
+
super(attribute: attribute, class: binding.local_variable_get(:class), disabled: disabled, form: form, options: options)
|
|
42
44
|
@value = value
|
|
43
45
|
end
|
|
44
46
|
|
|
@@ -9,14 +9,16 @@ module Flowbite
|
|
|
9
9
|
# Wraps `ActionView::Helpers::FormOptionsHelper#select`: https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
|
|
10
10
|
class Select < Field
|
|
11
11
|
SIZES = {
|
|
12
|
-
sm: ["
|
|
13
|
-
default: ["
|
|
14
|
-
lg: ["px-
|
|
12
|
+
sm: ["px-2.5", "py-2", "text-sm"],
|
|
13
|
+
default: ["px-3", "py-2.5", "text-sm"],
|
|
14
|
+
lg: ["px-3.5", "py-3", "text-base"]
|
|
15
15
|
}.freeze
|
|
16
16
|
|
|
17
|
-
def initialize(form:, attribute:, collection: [], disabled: false, options: {}, size: :default)
|
|
18
|
-
super(form: form, attribute: attribute, disabled: disabled, options: options, size: size)
|
|
17
|
+
def initialize(form:, attribute:, class: nil, collection: [], disabled: false, include_blank: false, multiple: false, options: {}, size: :default)
|
|
18
|
+
super(form: form, attribute: attribute, class: binding.local_variable_get(:class), 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
|
{
|
|
@@ -6,16 +6,18 @@ module Flowbite
|
|
|
6
6
|
class << self
|
|
7
7
|
# rubocop:disable Layout/LineLength
|
|
8
8
|
def styles
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
default:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
Flowbite::Styles.from_hash(
|
|
10
|
+
{
|
|
11
|
+
default: {
|
|
12
|
+
default: ["block", "w-full", "text-heading", "bg-neutral-secondary-medium", "rounded-base", "border", "border-default-medium", "focus:ring-brand", "focus:border-brand", "shadow-xs", "placeholder:text-body"],
|
|
13
|
+
disabled: ["block", "w-full", "bg-neutral-secondary-medium", "rounded-base", "border", "border-default-medium", "text-fg-disabled", "cursor-not-allowed", "shadow-xs", "placeholder:text-fg-disabled"],
|
|
14
|
+
error: ["block", "w-full", "bg-danger-soft", "border", "border-danger-subtle", "text-fg-danger-strong", "placeholder:text-fg-danger-strong", "rounded-base", "focus:ring-danger", "focus:border-danger", "shadow-xs"]
|
|
15
|
+
}
|
|
16
|
+
}.freeze
|
|
17
|
+
)
|
|
16
18
|
end
|
|
17
|
-
# rubocop:enable Layout/LineLength
|
|
18
19
|
end
|
|
20
|
+
# rubocop:enable Layout/LineLength
|
|
19
21
|
|
|
20
22
|
# Returns the HTML to use for the actual input field element.
|
|
21
23
|
def call
|
|
@@ -30,7 +32,7 @@ module Flowbite
|
|
|
30
32
|
|
|
31
33
|
# Returns the CSS classes to apply to the input field
|
|
32
34
|
def classes
|
|
33
|
-
self.class.classes(size: size, state: state)
|
|
35
|
+
self.class.classes(size: size, state: state) + @class
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
# Returns the name of the method used to generate HTML for the input field
|
|
@@ -3,8 +3,38 @@
|
|
|
3
3
|
module Flowbite
|
|
4
4
|
module Input
|
|
5
5
|
class ValidationError < ViewComponent::Base
|
|
6
|
+
class << self
|
|
7
|
+
def classes(state: :default, style: :default)
|
|
8
|
+
style = styles.fetch(style)
|
|
9
|
+
style.fetch(state)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# rubocop:disable Layout/LineLength
|
|
13
|
+
def styles
|
|
14
|
+
Flowbite::Styles.from_hash(
|
|
15
|
+
{
|
|
16
|
+
default: {
|
|
17
|
+
default: ["mt-2", "text-sm", "text-red-600", "dark:text-red-500"]
|
|
18
|
+
}
|
|
19
|
+
}.freeze
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
# rubocop:enable Layout/LineLength
|
|
23
|
+
end
|
|
24
|
+
|
|
6
25
|
def call
|
|
7
|
-
tag.p(content, class:
|
|
26
|
+
tag.p(content, class: classes)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def initialize(class: nil)
|
|
30
|
+
@class = Array.wrap(binding.local_variable_get(:class))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
# Returns the CSS classes to apply to the validation error
|
|
36
|
+
def classes
|
|
37
|
+
self.class.classes + @class
|
|
8
38
|
end
|
|
9
39
|
end
|
|
10
40
|
end
|
|
@@ -5,12 +5,10 @@ module Flowbite
|
|
|
5
5
|
class Checkbox < InputField
|
|
6
6
|
protected
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
|
|
8
|
+
def default_container_classes
|
|
9
|
+
["flex"]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
protected
|
|
13
|
-
|
|
14
12
|
def default_hint_options
|
|
15
13
|
return {} unless @hint
|
|
16
14
|
|
|
@@ -27,21 +25,32 @@ module Flowbite
|
|
|
27
25
|
options
|
|
28
26
|
end
|
|
29
27
|
|
|
28
|
+
def input_component
|
|
29
|
+
::Flowbite::Input::Checkbox
|
|
30
|
+
end
|
|
31
|
+
|
|
30
32
|
private
|
|
31
33
|
|
|
32
34
|
def hint_classes
|
|
33
35
|
if disabled?
|
|
34
|
-
"text-xs font-normal text-
|
|
36
|
+
"text-xs font-normal text-fg-disabled"
|
|
35
37
|
else
|
|
36
|
-
"text-xs font-normal text-
|
|
38
|
+
"text-xs font-normal text-body"
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
42
|
+
def input_arguments
|
|
43
|
+
args = super
|
|
44
|
+
args[:unchecked_value] = @input[:unchecked_value] if @input.key?(:unchecked_value)
|
|
45
|
+
args[:value] = @input[:value] if @input.key?(:value)
|
|
46
|
+
args
|
|
47
|
+
end
|
|
48
|
+
|
|
40
49
|
def label_classes
|
|
41
50
|
if disabled?
|
|
42
|
-
"font-medium text-
|
|
51
|
+
"font-medium text-fg-disabled"
|
|
43
52
|
else
|
|
44
|
-
"font-medium text-
|
|
53
|
+
"font-medium text-heading"
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
56
|
end
|
|
@@ -3,19 +3,17 @@
|
|
|
3
3
|
module Flowbite
|
|
4
4
|
class InputField
|
|
5
5
|
class RadioButton < InputField
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def initialize(attribute:, form:, value:, disabled: false, hint: nil, input: {}, label: {})
|
|
9
|
-
super(attribute: attribute, form: form, disabled: disabled, hint: hint, input: input, label: label)
|
|
6
|
+
def initialize(attribute:, form:, value:, class: nil, disabled: false, hint: nil, input: {}, label: {}, options: {})
|
|
7
|
+
super(attribute: attribute, class: binding.local_variable_get(:class), form: form, disabled: disabled, hint: hint, input: input, label: label, options: options)
|
|
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
|
|
|
13
|
+
def default_container_classes
|
|
14
|
+
["flex"]
|
|
15
|
+
end
|
|
16
|
+
|
|
19
17
|
def default_input
|
|
20
18
|
args = {
|
|
21
19
|
attribute: @attribute,
|
|
@@ -54,13 +52,17 @@ module Flowbite
|
|
|
54
52
|
render(component)
|
|
55
53
|
end
|
|
56
54
|
|
|
55
|
+
def input_component
|
|
56
|
+
::Flowbite::Input::RadioButton
|
|
57
|
+
end
|
|
58
|
+
|
|
57
59
|
private
|
|
58
60
|
|
|
59
61
|
def hint_classes
|
|
60
62
|
if disabled?
|
|
61
|
-
"text-xs font-normal text-
|
|
63
|
+
"text-xs font-normal text-fg-disabled"
|
|
62
64
|
else
|
|
63
|
-
"text-xs font-normal text-
|
|
65
|
+
"text-xs font-normal text-body"
|
|
64
66
|
end
|
|
65
67
|
end
|
|
66
68
|
|
|
@@ -78,9 +80,9 @@ module Flowbite
|
|
|
78
80
|
|
|
79
81
|
def label_classes
|
|
80
82
|
if disabled?
|
|
81
|
-
"font-medium text-
|
|
83
|
+
"font-medium text-fg-disabled"
|
|
82
84
|
else
|
|
83
|
-
"font-medium text-
|
|
85
|
+
"font-medium text-heading"
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
end
|
|
@@ -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
|
)
|
|
@@ -67,18 +67,24 @@ module Flowbite
|
|
|
67
67
|
renders_one :label
|
|
68
68
|
|
|
69
69
|
# Returns the errors for attribute
|
|
70
|
+
#
|
|
71
|
+
# @return [Array<String>] An array of error messages for the attribute.
|
|
70
72
|
def errors
|
|
73
|
+
return [] unless @object
|
|
74
|
+
|
|
71
75
|
@object.errors[@attribute] || []
|
|
72
76
|
end
|
|
73
77
|
|
|
74
|
-
def initialize(attribute:, form:, disabled: false, hint: nil, input: {}, label: {}, size: :default)
|
|
78
|
+
def initialize(attribute:, form:, class: nil, disabled: false, hint: nil, input: {}, label: {}, options: {}, size: :default)
|
|
75
79
|
@attribute = attribute
|
|
80
|
+
@class = Array.wrap(binding.local_variable_get(:class))
|
|
76
81
|
@disabled = disabled
|
|
77
82
|
@form = form
|
|
78
83
|
@hint = hint
|
|
79
84
|
@input = input
|
|
80
85
|
@label = label
|
|
81
86
|
@object = form.object
|
|
87
|
+
@options = options || {}
|
|
82
88
|
@size = size
|
|
83
89
|
end
|
|
84
90
|
|
|
@@ -88,6 +94,18 @@ module Flowbite
|
|
|
88
94
|
|
|
89
95
|
protected
|
|
90
96
|
|
|
97
|
+
def classes
|
|
98
|
+
if @options[:class]
|
|
99
|
+
Array.wrap(@options[:class])
|
|
100
|
+
else
|
|
101
|
+
[default_container_classes, @class].flatten.compact
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def default_container_classes
|
|
106
|
+
[]
|
|
107
|
+
end
|
|
108
|
+
|
|
91
109
|
# Returns the HTML to use for the hint element if any
|
|
92
110
|
def default_hint
|
|
93
111
|
return unless hint?
|
|
@@ -134,13 +152,7 @@ module Flowbite
|
|
|
134
152
|
|
|
135
153
|
# Returns the HTML to use for the default input element.
|
|
136
154
|
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
|
-
))
|
|
155
|
+
render(input_component.new(**input_arguments))
|
|
144
156
|
end
|
|
145
157
|
|
|
146
158
|
def default_label
|
|
@@ -177,7 +189,24 @@ module Flowbite
|
|
|
177
189
|
end
|
|
178
190
|
|
|
179
191
|
def id_for_hint_element
|
|
180
|
-
|
|
192
|
+
[
|
|
193
|
+
@form.object_name,
|
|
194
|
+
@attribute,
|
|
195
|
+
"hint"
|
|
196
|
+
]
|
|
197
|
+
.compact_blank
|
|
198
|
+
.join("_")
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# @return [Hash] The keyword arguments for the input component.
|
|
202
|
+
def input_arguments
|
|
203
|
+
{
|
|
204
|
+
attribute: @attribute,
|
|
205
|
+
disabled: @disabled,
|
|
206
|
+
form: @form,
|
|
207
|
+
options: input_options,
|
|
208
|
+
size: @size
|
|
209
|
+
}
|
|
181
210
|
end
|
|
182
211
|
|
|
183
212
|
def input_options
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Flowbite
|
|
4
|
+
# The link component can be used to set hyperlinks from one page to another or
|
|
5
|
+
# to an external website when clicking on an inline text item, button, or card
|
|
6
|
+
#
|
|
7
|
+
# Use this component to add default styles to an inline link element.
|
|
8
|
+
class Link < ViewComponent::Base
|
|
9
|
+
attr_reader :href, :options
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def classes
|
|
13
|
+
["font-medium", "text-fg-brand", "hover:underline"]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Initialize the Link component.
|
|
18
|
+
#
|
|
19
|
+
# @param href What to link to. This can be a String or anything else that
|
|
20
|
+
# `link_to` supports. See `ActionView::Helpers::UrlHelper#link_to` for more
|
|
21
|
+
# details.
|
|
22
|
+
#
|
|
23
|
+
# @param options [Hash] Additional HTML options for the link element
|
|
24
|
+
def initialize(href:, class: nil, **options)
|
|
25
|
+
super()
|
|
26
|
+
@class = Array.wrap(binding.local_variable_get(:class))
|
|
27
|
+
@href = href
|
|
28
|
+
@options = options
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def call
|
|
32
|
+
link_to(content, href, {class: classes}.merge(options))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def classes
|
|
38
|
+
self.class.classes + @class
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|