Class: ViewComponent::InputComponent::FileSelectorComponent
- Inherits:
-
Object
- Object
- ViewComponent::InputComponent::FileSelectorComponent
- Includes:
- ComponentHelper
- Defined in:
- app/helpers/view_component/input_component/file_selector_component.rb
Constant Summary collapse
- FILE_SELECTOR_TYPES =
%w[image document video].freeze
Instance Attribute Summary collapse
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#error ⇒ Object
Returns the value of attribute error.
-
#form ⇒ Object
Returns the value of attribute form.
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#support_text ⇒ Object
Returns the value of attribute support_text.
-
#support_text_two ⇒ Object
Returns the value of attribute support_text_two.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #accepted_types ⇒ Object
- #choose_file_style ⇒ Object
-
#initialize(type:, form: nil, name: nil, label: nil, support_text: nil, support_text_two: nil, error: nil, disabled: false, html_options: {}) ⇒ FileSelectorComponent
constructor
A new instance of FileSelectorComponent.
- #label_style ⇒ Object
- #preview_style ⇒ Object
- #support_text_style ⇒ Object
- #upload_icon_style ⇒ Object
- #wrapper_style ⇒ Object
Methods included from ComponentHelper
Constructor Details
#initialize(type:, form: nil, name: nil, label: nil, support_text: nil, support_text_two: nil, error: nil, disabled: false, html_options: {}) ⇒ FileSelectorComponent
Returns a new instance of FileSelectorComponent.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 13 def initialize(type:, form: nil, name: nil, label: nil, support_text: nil, support_text_two: nil, error: nil, disabled: false, html_options: {}) raise "Invalid or missing file type: #{type}" unless FILE_SELECTOR_TYPES.include?(type) = resolve_error(form, name, error) self.form = form self.name = name self.label = label self.support_text = (.presence || support_text) self.support_text_two = support_text_two self.error = self.disabled = disabled self. = self.type = type end |
Instance Attribute Details
#disabled ⇒ Object
Returns the value of attribute disabled.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def disabled @disabled end |
#error ⇒ Object
Returns the value of attribute error.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def error @error end |
#form ⇒ Object
Returns the value of attribute form.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def form @form end |
#html_options ⇒ Object
Returns the value of attribute html_options.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def end |
#label ⇒ Object
Returns the value of attribute label.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def name @name end |
#support_text ⇒ Object
Returns the value of attribute support_text.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def support_text @support_text end |
#support_text_two ⇒ Object
Returns the value of attribute support_text_two.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def support_text_two @support_text_two end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 10 def type @type end |
Instance Method Details
#accepted_types ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 30 def accepted_types case type when 'image' 'image/*' when 'document' '.csv,.pdf,.doc,.docx' when 'video' 'video/*,.mp4,.mov,.avi,.mkv' else '*/*' end end |
#choose_file_style ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 94 def choose_file_style base = ['general-text-md-normal '] color_style = if disabled 'text-disabled-color' else 'text-primary' end class_list(base, color_style) end |
#label_style ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 58 def label_style base = ['general-text-sm-normal px-1'] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-letter-color-light' end class_list(base, color_style) end |
#preview_style ⇒ Object
73 74 75 76 77 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 73 def preview_style base = ['file-selector-preview'] class_list(base) end |
#support_text_style ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 107 def support_text_style base = ['file-selector-support-text general-text-sm-normal'] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-slate-grey-50' end class_list(base, color_style) end |
#upload_icon_style ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 79 def upload_icon_style base = ['file-selector-upload-icon'] color_style = if disabled 'fill-disabled-color' elsif error.present? 'fill-danger' else 'fill-primary' end class_list(base, color_style) end |
#wrapper_style ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/view_component/input_component/file_selector_component.rb', line 43 def wrapper_style base = ['file-selector-component-base radius-lg md:radius-xl'] color_style = if disabled 'textarea-disabled-state pointer-events-none cursor-not-allowed' elsif error.present? 'border-danger' else 'border-slate-grey-50 hover:border-primary-light focus:border-primary-light' end class_list(base, color_style) end |