-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.rb
More file actions
58 lines (51 loc) · 1.56 KB
/
select.rb
File metadata and controls
58 lines (51 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
module Flowbite
module Input
# The `Select` component renders a select input field for use in forms.
#
# https://flowbite.com/docs/forms/select/
#
# Wraps `ActionView::Helpers::FormOptionsHelper#select`: https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
class Select < Field
SIZES = {
sm: ["p-2", "text-xs"],
default: ["p-2.5", "text-sm"],
lg: ["px-4", "py-3", "text-base"]
}.freeze
def initialize(form:, attribute:, collection: [], disabled: false, include_blank: false, multiple: false, options: {}, size: :default)
super(form: form, attribute: attribute, disabled: disabled, options: options, size: size)
@collection = collection
@include_blank = include_blank
@multiple = multiple
end
# Returns the HTML to use for the actual input field element.
def call
@form.send(
input_field_type,
@attribute,
@collection,
select_options,
html_options
)
end
# Returns the name of the method used to generate HTML for the input field
def input_field_type
:select
end
private
def select_options
{
include_blank: @include_blank,
multiple: @multiple
}
end
# Returns the html_options argument for the select method
def html_options
{
class: classes,
disabled: disabled?
}.merge(options)
end
end
end
end