sdr_view_components 0.1.7 → 0.1.8
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/app/components/sdr_view_components/forms/basic_checkbox_component.rb +5 -10
- data/app/components/sdr_view_components/forms/basic_component.rb +28 -0
- data/app/components/sdr_view_components/forms/basic_file_component.rb +2 -11
- data/app/components/sdr_view_components/forms/basic_radio_button_component.rb +9 -8
- data/app/components/sdr_view_components/forms/basic_text_area_component.rb +5 -10
- data/app/components/sdr_view_components/forms/basic_text_field_component.rb +5 -10
- data/app/components/sdr_view_components/forms/checkbox_component.rb +2 -3
- data/app/components/sdr_view_components/forms/field_component.html.erb +4 -2
- data/app/components/sdr_view_components/forms/field_component.rb +13 -7
- data/app/components/sdr_view_components/forms/file_component.rb +0 -7
- data/app/components/sdr_view_components/forms/help_text_component.html.erb +1 -1
- data/app/components/sdr_view_components/forms/help_text_component.rb +8 -2
- data/app/components/sdr_view_components/forms/invalid_feedback_component.rb +4 -4
- data/app/components/sdr_view_components/forms/radio_button_component.rb +13 -3
- data/app/components/sdr_view_components/forms/text_area_component.rb +0 -6
- data/app/components/sdr_view_components/forms/text_field_component.rb +0 -6
- data/lib/sdr_view_components/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ed77ab15d611e21337871d3d410b784454ec8e1a356fe91050b2250d7bc7d14
|
|
4
|
+
data.tar.gz: 10f9d789b3ca10d8b1bef44adf1dbb61639267115340f6d113d08d2d70d54002
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05475af8c2288f5f14ccfc0590fdb86374f530df207cf3fd82aa877d2377dbc91af5fde8742db8a74b16f6ef3dd1135a03450ec0a0bc083d0e4d4de404656844
|
|
7
|
+
data.tar.gz: fe4975a4869e202997e972c67999d66f9e729e7edc0e26f68ab83aaa7b6690579b6e0fa06a263f083c42f0fad2e81c1fead6d527235079dedb6fae7ff7c6e0b8
|
|
@@ -3,18 +3,13 @@
|
|
|
3
3
|
module SdrViewComponents
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form checkbox field
|
|
6
|
-
class BasicCheckboxComponent <
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
@field_name = field_name
|
|
10
|
-
@args = args
|
|
11
|
-
super()
|
|
6
|
+
class BasicCheckboxComponent < BasicComponent
|
|
7
|
+
def call
|
|
8
|
+
form.check_box field_name, class: classes, **args
|
|
12
9
|
end
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def call
|
|
17
|
-
form.check_box field_name, **args
|
|
11
|
+
def classes
|
|
12
|
+
merge_classes('form-check-input', @classes)
|
|
18
13
|
end
|
|
19
14
|
end
|
|
20
15
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SdrViewComponents
|
|
4
|
+
module Forms
|
|
5
|
+
# Base component for basic components.
|
|
6
|
+
class BasicComponent < BaseComponent
|
|
7
|
+
# Subclasses may override this if additional args, e.g., value, are needed.
|
|
8
|
+
def initialize(form:, field_name:, classes: [], **args)
|
|
9
|
+
@form = form
|
|
10
|
+
@field_name = field_name
|
|
11
|
+
@args = args
|
|
12
|
+
@classes = classes
|
|
13
|
+
super()
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
attr_reader :args, :form, :field_name
|
|
17
|
+
|
|
18
|
+
def call
|
|
19
|
+
raise NotImplementedError, 'Subclasses must implement the call method'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Subclasses can override this to provide default classes, e.g., form-check-input
|
|
23
|
+
def classes
|
|
24
|
+
merge_classes(@classes)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -3,18 +3,9 @@
|
|
|
3
3
|
module SdrViewComponents
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form file field
|
|
6
|
-
class BasicFileComponent <
|
|
7
|
-
def initialize(form:, field_name:, **args)
|
|
8
|
-
@form = form
|
|
9
|
-
@field_name = field_name
|
|
10
|
-
@args = args
|
|
11
|
-
super()
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
attr_reader :args, :form, :field_name
|
|
15
|
-
|
|
6
|
+
class BasicFileComponent < BasicComponent
|
|
16
7
|
def call
|
|
17
|
-
form.file_field field_name, **args
|
|
8
|
+
form.file_field field_name, class: classes, **args
|
|
18
9
|
end
|
|
19
10
|
end
|
|
20
11
|
end
|
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
module SdrViewComponents
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form radio button field
|
|
6
|
-
class BasicRadioButtonComponent <
|
|
7
|
-
def initialize(form:, field_name:, value:, **args)
|
|
8
|
-
@form = form
|
|
9
|
-
@field_name = field_name
|
|
6
|
+
class BasicRadioButtonComponent < BasicComponent
|
|
7
|
+
def initialize(form:, field_name:, value:, classes: [], **args)
|
|
10
8
|
@value = value
|
|
11
|
-
|
|
12
|
-
super()
|
|
9
|
+
super(form:, field_name:, classes:, **args)
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
attr_reader :
|
|
12
|
+
attr_reader :value
|
|
16
13
|
|
|
17
14
|
def call
|
|
18
|
-
form.radio_button field_name, value, **args
|
|
15
|
+
form.radio_button field_name, value, class: classes, **args
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def classes
|
|
19
|
+
merge_classes('form-check-input', @classes)
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
22
|
end
|
|
@@ -3,18 +3,13 @@
|
|
|
3
3
|
module SdrViewComponents
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form text area field
|
|
6
|
-
class BasicTextAreaComponent <
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
@field_name = field_name
|
|
10
|
-
@args = args
|
|
11
|
-
super()
|
|
6
|
+
class BasicTextAreaComponent < BasicComponent
|
|
7
|
+
def call
|
|
8
|
+
form.text_area field_name, class: classes, **args
|
|
12
9
|
end
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def call
|
|
17
|
-
form.text_area field_name, **args
|
|
11
|
+
def classes
|
|
12
|
+
merge_classes('form-control', @classes)
|
|
18
13
|
end
|
|
19
14
|
end
|
|
20
15
|
end
|
|
@@ -3,18 +3,13 @@
|
|
|
3
3
|
module SdrViewComponents
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form text field
|
|
6
|
-
class BasicTextFieldComponent <
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
@field_name = field_name
|
|
10
|
-
@args = args
|
|
11
|
-
super()
|
|
6
|
+
class BasicTextFieldComponent < BasicComponent
|
|
7
|
+
def call
|
|
8
|
+
form.text_field field_name, class: classes, **args
|
|
12
9
|
end
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def call
|
|
17
|
-
form.text_field field_name, **args
|
|
11
|
+
def classes
|
|
12
|
+
merge_classes('form-control', @classes)
|
|
18
13
|
end
|
|
19
14
|
end
|
|
20
15
|
end
|
|
@@ -5,9 +5,8 @@ module SdrViewComponents
|
|
|
5
5
|
# Component for form checkbox field
|
|
6
6
|
class CheckboxComponent < FieldComponent
|
|
7
7
|
def initialize(**args)
|
|
8
|
-
args[:
|
|
9
|
-
args[:
|
|
10
|
-
args[:label_default_class] = merge_classes('form-check-label', args[:input_class])
|
|
8
|
+
args[:container_classes] = merge_classes('form-check', args[:container_classes])
|
|
9
|
+
args[:label_default_class] = 'form-check-label'
|
|
11
10
|
super
|
|
12
11
|
end
|
|
13
12
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
<%= tag.div **container_args do %>
|
|
2
|
-
<%= render SdrViewComponents::Forms::LabelComponent.new(form:, field_name
|
|
1
|
+
<%= tag.div class: container_classes, **container_args do %>
|
|
2
|
+
<%= render SdrViewComponents::Forms::LabelComponent.new(form:, field_name: label_field_name, **label_args) %>
|
|
3
3
|
<%= render SdrViewComponents::Forms::HelpTextComponent.new(**help_text_args) %>
|
|
4
4
|
<%= render input_component %>
|
|
5
5
|
<%= render SdrViewComponents::Forms::InvalidFeedbackComponent.new(form:, field_name:, **error_args) %>
|
|
6
|
+
|
|
7
|
+
<%= additional_container_content %>
|
|
6
8
|
<% end %>
|
|
@@ -4,12 +4,17 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Base component for all form fields.
|
|
6
6
|
class FieldComponent < BaseComponent
|
|
7
|
-
|
|
7
|
+
renders_one :additional_container_content
|
|
8
|
+
|
|
9
|
+
def initialize(form:, field_name:, container_classes: [], **args)
|
|
10
|
+
@form = form
|
|
11
|
+
@field_name = field_name
|
|
12
|
+
@container_classes = container_classes
|
|
8
13
|
@args = args
|
|
9
14
|
super()
|
|
10
15
|
end
|
|
11
16
|
|
|
12
|
-
attr_reader :args
|
|
17
|
+
attr_reader :form, :args, :field_name
|
|
13
18
|
|
|
14
19
|
# Any component that inherits from FieldComponent must implement this method
|
|
15
20
|
# or provide its own template.
|
|
@@ -57,15 +62,16 @@ module SdrViewComponents
|
|
|
57
62
|
def label_args
|
|
58
63
|
args_for(args:, prefix: 'label_')
|
|
59
64
|
end
|
|
60
|
-
##########################################################################
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
# Subclasses may override, e.g., for radio buttons.
|
|
67
|
+
def label_field_name
|
|
68
|
+
field_name
|
|
64
69
|
end
|
|
65
70
|
|
|
66
|
-
def
|
|
67
|
-
@
|
|
71
|
+
def container_classes
|
|
72
|
+
merge_classes(@container_classes)
|
|
68
73
|
end
|
|
74
|
+
##########################################################################
|
|
69
75
|
|
|
70
76
|
private
|
|
71
77
|
|
|
@@ -4,13 +4,6 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form file field
|
|
6
6
|
class FileComponent < FieldComponent
|
|
7
|
-
def initialize(**args)
|
|
8
|
-
args[:container_class] = merge_classes('form-file', args[:container_class])
|
|
9
|
-
args[:input_class] = merge_classes('form-file-input', args[:input_class])
|
|
10
|
-
args[:label_default_class] = merge_classes('form-file-label', args[:input_class])
|
|
11
|
-
super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
7
|
def input_component
|
|
15
8
|
SdrViewComponents::Forms::BasicFileComponent.new(form:, field_name:, **input_args)
|
|
16
9
|
end
|
|
@@ -7,17 +7,23 @@ module SdrViewComponents
|
|
|
7
7
|
class HelpTextComponent < BaseComponent
|
|
8
8
|
# this component can take plain text via 'help_text' or a block (which can contain html)
|
|
9
9
|
# it will render the help_text if provided, else it will render the block content
|
|
10
|
-
def initialize(id:, text: nil)
|
|
10
|
+
def initialize(id:, text: nil, classes: [], **args)
|
|
11
11
|
@text = text
|
|
12
12
|
@id = id
|
|
13
|
+
@classes = classes
|
|
14
|
+
@args = args
|
|
13
15
|
super()
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
attr_reader :text, :id
|
|
18
|
+
attr_reader :text, :id, :args
|
|
17
19
|
|
|
18
20
|
def render?
|
|
19
21
|
text.present? || content.present?
|
|
20
22
|
end
|
|
23
|
+
|
|
24
|
+
def classes
|
|
25
|
+
merge_classes('form-text', @classes)
|
|
26
|
+
end
|
|
21
27
|
end
|
|
22
28
|
end
|
|
23
29
|
end
|
|
@@ -4,18 +4,18 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for rendering invalid feedback for a form field.
|
|
6
6
|
class InvalidFeedbackComponent < BaseComponent
|
|
7
|
-
def initialize(field_name:, form:, classes: [],
|
|
7
|
+
def initialize(field_name:, form:, classes: [], **args)
|
|
8
8
|
@field_name = field_name
|
|
9
9
|
@form = form
|
|
10
10
|
@classes = classes
|
|
11
|
-
@
|
|
11
|
+
@args = args
|
|
12
12
|
super()
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
attr_reader :field_name, :form, :
|
|
15
|
+
attr_reader :field_name, :form, :args
|
|
16
16
|
|
|
17
17
|
def call
|
|
18
|
-
tag.div(class: classes, id:,
|
|
18
|
+
tag.div(class: classes, id:, **args) do
|
|
19
19
|
errors.join(', ')
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -5,15 +5,25 @@ module SdrViewComponents
|
|
|
5
5
|
# Component for form radio button field
|
|
6
6
|
class RadioButtonComponent < FieldComponent
|
|
7
7
|
def initialize(**args)
|
|
8
|
-
args[:
|
|
9
|
-
args[:
|
|
10
|
-
args[:label_default_class] = merge_classes('form-check-label', args[:input_class])
|
|
8
|
+
args[:container_classes] = merge_classes('form-check', args[:container_classes])
|
|
9
|
+
args[:label_default_class] = 'form-check-label'
|
|
11
10
|
super
|
|
12
11
|
end
|
|
13
12
|
|
|
14
13
|
def input_component
|
|
15
14
|
SdrViewComponents::Forms::BasicRadioButtonComponent.new(form:, field_name:, **input_args)
|
|
16
15
|
end
|
|
16
|
+
|
|
17
|
+
def label_field_name
|
|
18
|
+
"#{sanitize(field_name)}_#{sanitize(input_args[:value])}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# From https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/form_tag_helper.rb
|
|
24
|
+
def sanitize(value)
|
|
25
|
+
value.to_s.delete(']').tr('^-a-zA-Z0-9:.', '_')
|
|
26
|
+
end
|
|
17
27
|
end
|
|
18
28
|
end
|
|
19
29
|
end
|
|
@@ -4,12 +4,6 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form text area field
|
|
6
6
|
class TextAreaComponent < FieldComponent
|
|
7
|
-
def initialize(**args)
|
|
8
|
-
args[:container_class] = merge_classes('form-text', args[:container_class])
|
|
9
|
-
args[:input_class] = merge_classes('form-control', args[:input_class])
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def input_component
|
|
14
8
|
SdrViewComponents::Forms::BasicTextAreaComponent.new(form:, field_name:, **input_args)
|
|
15
9
|
end
|
|
@@ -4,12 +4,6 @@ module SdrViewComponents
|
|
|
4
4
|
module Forms
|
|
5
5
|
# Component for form text field
|
|
6
6
|
class TextFieldComponent < FieldComponent
|
|
7
|
-
def initialize(**args)
|
|
8
|
-
args[:container_class] = merge_classes('field-container', args[:container_class])
|
|
9
|
-
args[:input_class] = merge_classes('form-control', args[:input_class])
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
|
|
13
7
|
def input_component
|
|
14
8
|
SdrViewComponents::Forms::BasicTextFieldComponent.new(form:, field_name:, **input_args)
|
|
15
9
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sdr_view_components
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Collier
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-12-
|
|
10
|
+
date: 2025-12-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rails
|
|
@@ -86,6 +86,7 @@ files:
|
|
|
86
86
|
- app/components/sdr_view_components/elements/tooltip_component.html.erb
|
|
87
87
|
- app/components/sdr_view_components/elements/tooltip_component.rb
|
|
88
88
|
- app/components/sdr_view_components/forms/basic_checkbox_component.rb
|
|
89
|
+
- app/components/sdr_view_components/forms/basic_component.rb
|
|
89
90
|
- app/components/sdr_view_components/forms/basic_file_component.rb
|
|
90
91
|
- app/components/sdr_view_components/forms/basic_radio_button_component.rb
|
|
91
92
|
- app/components/sdr_view_components/forms/basic_text_area_component.rb
|